All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PM / devfreq: userspace: Fix memory leak in userspace_init()
@ 2026-07-04 16:32 Malaya Kumar Rout
  2026-07-24  6:17 ` malaya kumar rout
  2026-07-28  6:31 ` Jie Zhan
  0 siblings, 2 replies; 5+ messages in thread
From: Malaya Kumar Rout @ 2026-07-04 16:32 UTC (permalink / raw)
  To: linux-kernel, stable, linux-pm
  Cc: mrout, skhan, me, Malaya Kumar Rout, MyungJoo Ham, Kyungmin Park,
	Chanwoo Choi, Kant Fan

Fix a memory leak in the userspace_init() function where allocated
memory is not freed when sysfs_create_group() fails.

When sysfs_create_group() fails, the function returns without freeing
the memory allocated for 'data', leading to a memory leak. This patch
adds proper error handling to free the allocated memory and reset
governor_data to NULL on failure.

Fixes: 5fdded844892 ("PM/devfreq: governor: Add a private governor_data for governor")
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
---
 drivers/devfreq/governor_userspace.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/devfreq/governor_userspace.c b/drivers/devfreq/governor_userspace.c
index 3906ebedbae8..b9fbcacdfba1 100644
--- a/drivers/devfreq/governor_userspace.c
+++ b/drivers/devfreq/governor_userspace.c
@@ -97,6 +97,12 @@ static int userspace_init(struct devfreq *devfreq)
 	devfreq->governor_data = data;
 
 	err = sysfs_create_group(&devfreq->dev.kobj, &dev_attr_group);
+
+	if (err) {
+		kfree(data);
+		devfreq->governor_data = NULL;
+	}
+
 out:
 	return err;
 }
-- 
2.54.0


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

end of thread, other threads:[~2026-07-30 12:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 16:32 [PATCH] PM / devfreq: userspace: Fix memory leak in userspace_init() Malaya Kumar Rout
2026-07-24  6:17 ` malaya kumar rout
2026-07-28  6:31 ` Jie Zhan
2026-07-29 13:35   ` [PATCH v2] " Malaya Kumar Rout
2026-07-30 12:51     ` Jie Zhan

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.