* [PATCH v2] PM / devfreq: Fix memory leak in devfreq_event_add_edev()
@ 2025-09-07 11:33 Kaushlendra Kumar
2025-09-07 12:18 ` Chanwoo Choi
0 siblings, 1 reply; 2+ messages in thread
From: Kaushlendra Kumar @ 2025-09-07 11:33 UTC (permalink / raw)
To: myungjoo.ham, kyungmin.park, cw00.choi; +Cc: linux-pm, Kaushlendra Kumar
Add missing kfree() call to prevent memory leak when device_register()
fails in devfreq_event_add_edev(). The allocated edev structure was not
being freed in the error path, causing a memory leak.
When device_register() fails, the edev structure allocated earlier in
the function needs to be freed before calling put_device() to avoid
leaking memory.
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
Changes in v2:
- moved kfree after put_device based on review feedback
---
drivers/devfreq/devfreq-event.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c
index 70219099c604..34406c52b845 100644
--- a/drivers/devfreq/devfreq-event.c
+++ b/drivers/devfreq/devfreq-event.c
@@ -328,6 +328,7 @@ struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
ret = device_register(&edev->dev);
if (ret < 0) {
put_device(&edev->dev);
+ kfree(edev);
return ERR_PTR(ret);
}
dev_set_drvdata(&edev->dev, edev);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] PM / devfreq: Fix memory leak in devfreq_event_add_edev()
2025-09-07 11:33 [PATCH v2] PM / devfreq: Fix memory leak in devfreq_event_add_edev() Kaushlendra Kumar
@ 2025-09-07 12:18 ` Chanwoo Choi
0 siblings, 0 replies; 2+ messages in thread
From: Chanwoo Choi @ 2025-09-07 12:18 UTC (permalink / raw)
To: Kaushlendra Kumar; +Cc: myungjoo.ham, kyungmin.park, cw00.choi, linux-pm
Hi,
Applied it. Thanks.
On Sun, Sep 7, 2025 at 8:34 PM Kaushlendra Kumar
<kaushlendra.kumar@intel.com> wrote:
>
> Add missing kfree() call to prevent memory leak when device_register()
> fails in devfreq_event_add_edev(). The allocated edev structure was not
> being freed in the error path, causing a memory leak.
>
> When device_register() fails, the edev structure allocated earlier in
> the function needs to be freed before calling put_device() to avoid
> leaking memory.
>
> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
> ---
> Changes in v2:
> - moved kfree after put_device based on review feedback
> ---
> drivers/devfreq/devfreq-event.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c
> index 70219099c604..34406c52b845 100644
> --- a/drivers/devfreq/devfreq-event.c
> +++ b/drivers/devfreq/devfreq-event.c
> @@ -328,6 +328,7 @@ struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
> ret = device_register(&edev->dev);
> if (ret < 0) {
> put_device(&edev->dev);
> + kfree(edev);
> return ERR_PTR(ret);
> }
> dev_set_drvdata(&edev->dev, edev);
> --
> 2.34.1
>
>
--
Best Regards,
Chanwoo Choi
Samsung Electronics
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-07 12:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-07 11:33 [PATCH v2] PM / devfreq: Fix memory leak in devfreq_event_add_edev() Kaushlendra Kumar
2025-09-07 12:18 ` Chanwoo Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox