diff options
author | Dan Williams <dan.j.williams@intel.com> | 2017-07-12 16:42:37 -0400 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2017-07-17 14:43:58 -0400 |
commit | 43fe51e11c194a6576634585f81ba33e104194a5 (patch) | |
tree | cf27724a7c3a0c200e167068d1e2346dedbc5c52 /drivers/dax/device.c | |
parent | 4e3f0701f25ab194c5362576b1146a1e6cc6c2e7 (diff) |
device-dax: fix 'passing zero to ERR_PTR()' warning
Dan Carpenter reports:
The patch 7b6be8444e0f: "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>
Diffstat (limited to 'drivers/dax/device.c')
-rw-r--r-- | drivers/dax/device.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 12943d19bfc4..44d72e5e64cc 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c | |||
@@ -567,7 +567,10 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, | |||
567 | struct inode *inode; | 567 | struct inode *inode; |
568 | struct device *dev; | 568 | struct device *dev; |
569 | struct cdev *cdev; | 569 | struct cdev *cdev; |
570 | int rc = 0, i; | 570 | int rc, i; |
571 | |||
572 | if (!count) | ||
573 | return ERR_PTR(-EINVAL); | ||
571 | 574 | ||
572 | dev_dax = kzalloc(sizeof(*dev_dax) + sizeof(*res) * count, GFP_KERNEL); | 575 | dev_dax = kzalloc(sizeof(*dev_dax) + sizeof(*res) * count, GFP_KERNEL); |
573 | if (!dev_dax) | 576 | if (!dev_dax) |
@@ -598,8 +601,10 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, | |||
598 | * device outside of mmap of the resulting character device. | 601 | * device outside of mmap of the resulting character device. |
599 | */ | 602 | */ |
600 | dax_dev = alloc_dax(dev_dax, NULL, NULL); | 603 | dax_dev = alloc_dax(dev_dax, NULL, NULL); |
601 | if (!dax_dev) | 604 | if (!dax_dev) { |
605 | rc = -ENOMEM; | ||
602 | goto err_dax; | 606 | goto err_dax; |
607 | } | ||
603 | 608 | ||
604 | /* from here on we're committed to teardown via dax_dev_release() */ | 609 | /* from here on we're committed to teardown via dax_dev_release() */ |
605 | dev = &dev_dax->dev; | 610 | dev = &dev_dax->dev; |