linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure
@ 2016-10-23 20:56 Colin King
  2016-10-24 13:09 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2016-10-23 20:56 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: linux-kernel

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure
  2016-10-23 20:56 [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure Colin King
@ 2016-10-24 13:09 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2016-10-24 13:09 UTC (permalink / raw)
  To: Colin King, Jean Delvare, linux-hwmon; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-24 13:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-23 20:56 [PATCH] hwmon: (core) fix resource leak on devm_kcalloc failure Colin King
2016-10-24 13:09 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).