All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal/of: Fix memory leak in thermal_of_zone_register()
@ 2022-11-23 14:33 Xiu Jianfeng
  2022-11-23 14:48 ` xiujianfeng
  0 siblings, 1 reply; 2+ messages in thread
From: Xiu Jianfeng @ 2022-11-23 14:33 UTC (permalink / raw)
  To: rafael, daniel.lezcano, amitk, rui.zhang; +Cc: linux-pm, linux-kernel

In the entry of this function, it has allocated memory by kmemdup() and
save it in @of_ops, it should be freed on the error paths, otherwise
memory leak issue happens, fix it.

Fixes: 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 drivers/thermal/thermal_of.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index d4b6335ace15..95d3da9051c4 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -604,13 +604,15 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor,
 	if (IS_ERR(np)) {
 		if (PTR_ERR(np) != -ENODEV)
 			pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id);
-		return ERR_CAST(np);
+		ret = PTR_ERR(np);
+		goto out_kfree_ops;
 	}
 
 	trips = thermal_of_trips_init(np, &ntrips);
 	if (IS_ERR(trips)) {
 		pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id);
-		return ERR_CAST(trips);
+		ret = PTR_ERR(trips);
+		goto out_kfree_ops;
 	}
 
 	ret = thermal_of_monitor_init(np, &delay, &pdelay);
@@ -659,6 +661,8 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor,
 	kfree(tzp);
 out_kfree_trips:
 	kfree(trips);
+out_kfree_ops:
+	kfree(of_ops);
 
 	return ERR_PTR(ret);
 }
-- 
2.17.1


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

* Re: [PATCH] thermal/of: Fix memory leak in thermal_of_zone_register()
  2022-11-23 14:33 [PATCH] thermal/of: Fix memory leak in thermal_of_zone_register() Xiu Jianfeng
@ 2022-11-23 14:48 ` xiujianfeng
  0 siblings, 0 replies; 2+ messages in thread
From: xiujianfeng @ 2022-11-23 14:48 UTC (permalink / raw)
  To: rafael, daniel.lezcano, amitk, rui.zhang; +Cc: linux-pm, linux-kernel

sorry, it seems someone already sent fix patch, ignore this.

在 2022/11/23 22:33, Xiu Jianfeng 写道:
> In the entry of this function, it has allocated memory by kmemdup() and
> save it in @of_ops, it should be freed on the error paths, otherwise
> memory leak issue happens, fix it.
> 
> Fixes: 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization")
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
>   drivers/thermal/thermal_of.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index d4b6335ace15..95d3da9051c4 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -604,13 +604,15 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor,
>   	if (IS_ERR(np)) {
>   		if (PTR_ERR(np) != -ENODEV)
>   			pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id);
> -		return ERR_CAST(np);
> +		ret = PTR_ERR(np);
> +		goto out_kfree_ops;
>   	}
>   
>   	trips = thermal_of_trips_init(np, &ntrips);
>   	if (IS_ERR(trips)) {
>   		pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id);
> -		return ERR_CAST(trips);
> +		ret = PTR_ERR(trips);
> +		goto out_kfree_ops;
>   	}
>   
>   	ret = thermal_of_monitor_init(np, &delay, &pdelay);
> @@ -659,6 +661,8 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor,
>   	kfree(tzp);
>   out_kfree_trips:
>   	kfree(trips);
> +out_kfree_ops:
> +	kfree(of_ops);
>   
>   	return ERR_PTR(ret);
>   }
> 

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

end of thread, other threads:[~2022-11-23 14:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 14:33 [PATCH] thermal/of: Fix memory leak in thermal_of_zone_register() Xiu Jianfeng
2022-11-23 14:48 ` xiujianfeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.