Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] hwmon/coretemp: Fix a memory leak bug
@ 2019-08-19 21:00 Wenwen Wang
  2019-08-20 15:05 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Wenwen Wang @ 2019-08-19 21:00 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Fenghua Yu, Jean Delvare, Guenter Roeck, linux-hwmon, linux-kernel

In coretemp_init(), 'zone_devices' is allocated through kcalloc(). However,
it is not deallocated in the following execution if
platform_driver_register() fails, leading to a memory leak. To fix this
issue, introduce the 'outzone' label to free 'zone_devices' before
returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/hwmon/coretemp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index fe6618e..d855c78 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -736,7 +736,7 @@ static int __init coretemp_init(void)
 
 	err = platform_driver_register(&coretemp_driver);
 	if (err)
-		return err;
+		goto outzone;
 
 	err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online",
 				coretemp_cpu_online, coretemp_cpu_offline);
@@ -747,6 +747,7 @@ static int __init coretemp_init(void)
 
 outdrv:
 	platform_driver_unregister(&coretemp_driver);
+outzone:
 	kfree(zone_devices);
 	return err;
 }
-- 
2.7.4


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

* Re: [PATCH] hwmon/coretemp: Fix a memory leak bug
  2019-08-19 21:00 [PATCH] hwmon/coretemp: Fix a memory leak bug Wenwen Wang
@ 2019-08-20 15:05 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2019-08-20 15:05 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Fenghua Yu, Jean Delvare,
	open list:CORETEMP HARDWARE MONITORING DRIVER, open list

On Mon, Aug 19, 2019 at 04:00:02PM -0500, Wenwen Wang wrote:
> In coretemp_init(), 'zone_devices' is allocated through kcalloc(). However,
> it is not deallocated in the following execution if
> platform_driver_register() fails, leading to a memory leak. To fix this
> issue, introduce the 'outzone' label to free 'zone_devices' before
> returning the error.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/coretemp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
> index fe6618e..d855c78 100644
> --- a/drivers/hwmon/coretemp.c
> +++ b/drivers/hwmon/coretemp.c
> @@ -736,7 +736,7 @@ static int __init coretemp_init(void)
>  
>  	err = platform_driver_register(&coretemp_driver);
>  	if (err)
> -		return err;
> +		goto outzone;
>  
>  	err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online",
>  				coretemp_cpu_online, coretemp_cpu_offline);
> @@ -747,6 +747,7 @@ static int __init coretemp_init(void)
>  
>  outdrv:
>  	platform_driver_unregister(&coretemp_driver);
> +outzone:
>  	kfree(zone_devices);
>  	return err;
>  }

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19 21:00 [PATCH] hwmon/coretemp: Fix a memory leak bug Wenwen Wang
2019-08-20 15:05 ` Guenter Roeck

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org linux-hwmon@archiver.kernel.org
	public-inbox-index linux-hwmon


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/ public-inbox