Skip to content

Commit

Permalink
hwmon: (core) fix resource leak on devm_kcalloc failure
Browse files Browse the repository at this point in the history
If dev_kcalloc fails to allocate hw_dev->groups then the current
exit path is a direct return, causing a leak of resources such
as hwdev and ida is not removed.  Fix this by exiting via the
free_hwmon exit path that performs the necessary resource cleanup.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Colin Ian King authored and Guenter Roeck committed Oct 24, 2016
1 parent 07d9a38 commit 38d8ed6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/hwmon/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,10 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,

hwdev->groups = devm_kcalloc(dev, ngroups, sizeof(*groups),
GFP_KERNEL);
if (!hwdev->groups)
return ERR_PTR(-ENOMEM);
if (!hwdev->groups) {
err = -ENOMEM;
goto free_hwmon;
}

attrs = __hwmon_create_attrs(dev, drvdata, chip);
if (IS_ERR(attrs)) {
Expand Down

0 comments on commit 38d8ed6

Please sign in to comment.