[PATCH] PM / devfreq: userspace: Fix memory leak in userspace_init()

From: Malaya Kumar Rout

Date: Sat Jul 04 2026 - 12:33:41 EST


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@xxxxxxxxx>
---
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