linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Resend][PATCH] drivers/thermal: fix potential memleak in error branch
@ 2020-11-10  8:10 Bernard
  2020-11-12 11:22 ` Daniel Lezcano
  0 siblings, 1 reply; 2+ messages in thread
From: Bernard @ 2020-11-10  8:10 UTC (permalink / raw)
  To: Zhang Rui, Daniel Lezcano, Amit Kucheria, linux-pm, linux-kernel
  Cc: opensource.kernel, Bernard Zhao

Function __thermal_cooling_device_register, when device_register
failed, cdev is not free after error value return, this may
bring in potential memleak.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/thermal/thermal_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 3d1e0033bf3e..e4bee15dfa1f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1125,6 +1125,7 @@ __thermal_cooling_device_register(struct device_node *np,
 	if (result) {
 		ida_simple_remove(&thermal_cdev_ida, cdev->id);
 		put_device(&cdev->device);
+		kfree(cdev);
 		return ERR_PTR(result);
 	}
 
-- 
2.29.0




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

* Re: [Resend][PATCH] drivers/thermal: fix potential memleak in error branch
  2020-11-10  8:10 [Resend][PATCH] drivers/thermal: fix potential memleak in error branch Bernard
@ 2020-11-12 11:22 ` Daniel Lezcano
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2020-11-12 11:22 UTC (permalink / raw)
  To: Bernard, Zhang Rui, Amit Kucheria, linux-pm, linux-kernel
  Cc: opensource.kernel

On 10/11/2020 09:10, Bernard wrote:
> Function __thermal_cooling_device_register, when device_register
> failed, cdev is not free after error value return, this may
> bring in potential memleak.
> 
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  drivers/thermal/thermal_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 3d1e0033bf3e..e4bee15dfa1f 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1125,6 +1125,7 @@ __thermal_cooling_device_register(struct device_node *np,
>  	if (result) {
>  		ida_simple_remove(&thermal_cdev_ida, cdev->id);
>  		put_device(&cdev->device);
> +		kfree(cdev);
>  		return ERR_PTR(result);
>  	}

Please fix the function with the proper error path and the labels.

Thanks

  -- Daniel


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

end of thread, other threads:[~2020-11-12 11:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10  8:10 [Resend][PATCH] drivers/thermal: fix potential memleak in error branch Bernard
2020-11-12 11:22 ` Daniel Lezcano

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