[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5e1b6e81-c9a9-66dc-94c1-31c39def5129@roeck-us.net>
Date: Mon, 24 Oct 2016 06:09:27 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Colin King <colin.king@...onical.com>,
Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure
On 10/23/2016 01:56 PM, Colin King wrote:
> From: Colin Ian King <colin.king@...onical.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@...onical.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)) {
>
Powered by blists - more mailing lists