Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1506762 > unrolled thread

[PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure

Started byColin King <colin.king@canonical.com>
First post2016-10-23 23:00 +0200
Last post2016-10-24 15:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure Colin King <colin.king@canonical.com> - 2016-10-23 23:00 +0200
    Re: [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure Guenter Roeck <linux@roeck-us.net> - 2016-10-24 15:10 +0200

#1506762 — [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure

FromColin King <colin.king@canonical.com>
Date2016-10-23 23:00 +0200
Subject[PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure
Message-ID<svy26-5N3-3@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

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>
---
 drivers/hwmon/hwmon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index adae684..a74c075 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,
 
 		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)) {
-- 
2.9.3

[toc] | [next] | [standalone]


#1507178

FromGuenter Roeck <linux@roeck-us.net>
Date2016-10-24 15:10 +0200
Message-ID<svNaO-80A-31@gated-at.bofh.it>
In reply to#1506762
On 10/23/2016 01:56 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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>

Good catch! Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/hwmon.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index adae684..a74c075 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,
>
>  		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)) {
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web