Skip to content

Commit 43fe51e

Browse files
committed
device-dax: fix 'passing zero to ERR_PTR()' warning
Dan Carpenter reports: The patch 7b6be84: "dax: refactor dax-fs into a generic provider of 'struct dax_device' instances" from Apr 11, 2017, leads to the following static checker warning: drivers/dax/device.c:643 devm_create_dev_dax() warn: passing zero to 'ERR_PTR' Fix the case where we inadvertently leak 0 to ERR_PTR() by setting at every error case, and make it clear that 'count' is never 0. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 4e3f070 commit 43fe51e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/dax/device.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,10 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
567567
struct inode *inode;
568568
struct device *dev;
569569
struct cdev *cdev;
570-
int rc = 0, i;
570+
int rc, i;
571+
572+
if (!count)
573+
return ERR_PTR(-EINVAL);
571574

572575
dev_dax = kzalloc(sizeof(*dev_dax) + sizeof(*res) * count, GFP_KERNEL);
573576
if (!dev_dax)
@@ -598,8 +601,10 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
598601
* device outside of mmap of the resulting character device.
599602
*/
600603
dax_dev = alloc_dax(dev_dax, NULL, NULL);
601-
if (!dax_dev)
604+
if (!dax_dev) {
605+
rc = -ENOMEM;
602606
goto err_dax;
607+
}
603608

604609
/* from here on we're committed to teardown via dax_dev_release() */
605610
dev = &dev_dax->dev;

0 commit comments

Comments
 (0)