1
0
Fork 0

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>
hifive-unleashed-5.1
Colin Ian King 2016-10-23 21:56:08 +01:00 committed by Guenter Roeck
parent 07d9a38068
commit 38d8ed6509
1 changed files with 4 additions and 2 deletions

View File

@ -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)) {