Skip to content

Commit

Permalink
device-dax: fix 'passing zero to ERR_PTR()' warning
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
  • Loading branch information
djbw committed Jul 17, 2017
1 parent 4e3f070 commit 43fe51e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/dax/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
struct inode *inode;
struct device *dev;
struct cdev *cdev;
int rc = 0, i;
int rc, i;

if (!count)
return ERR_PTR(-EINVAL);

dev_dax = kzalloc(sizeof(*dev_dax) + sizeof(*res) * count, GFP_KERNEL);
if (!dev_dax)
Expand Down Expand Up @@ -598,8 +601,10 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
* device outside of mmap of the resulting character device.
*/
dax_dev = alloc_dax(dev_dax, NULL, NULL);
if (!dax_dev)
if (!dax_dev) {
rc = -ENOMEM;
goto err_dax;
}

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

0 comments on commit 43fe51e

Please sign in to comment.