diff options
author | Colin Ian King <colin.king@canonical.com> | 2016-10-23 16:56:08 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2016-10-24 09:05:13 -0400 |
commit | 38d8ed65092ed22f52a95f397855cace0260e110 (patch) | |
tree | 59b5e01b4d1f349b736a8c0e4ce3cf8f3338cafd | |
parent | 07d9a380680d1c0eb51ef87ff2eab5c994949e69 (diff) |
hwmon: (core) fix resource leak on devm_kcalloc failure
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>
-rw-r--r-- | drivers/hwmon/hwmon.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index adae6848ffb2..a74c075a30ec 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c | |||
@@ -536,8 +536,10 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, | |||
536 | 536 | ||
537 | hwdev->groups = devm_kcalloc(dev, ngroups, sizeof(*groups), | 537 | hwdev->groups = devm_kcalloc(dev, ngroups, sizeof(*groups), |
538 | GFP_KERNEL); | 538 | GFP_KERNEL); |
539 | if (!hwdev->groups) | 539 | if (!hwdev->groups) { |
540 | return ERR_PTR(-ENOMEM); | 540 | err = -ENOMEM; |
541 | goto free_hwmon; | ||
542 | } | ||
541 | 543 | ||
542 | attrs = __hwmon_create_attrs(dev, drvdata, chip); | 544 | attrs = __hwmon_create_attrs(dev, drvdata, chip); |
543 | if (IS_ERR(attrs)) { | 545 | if (IS_ERR(attrs)) { |