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

From: Jie Zhan

Date: Tue Jul 28 2026 - 02:31:59 EST




On 7/5/2026 12:32 AM, Malaya Kumar Rout wrote:
> 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);
> +
Redundant blank line. Otherwise,
Reviewed-by: Jie Zhan <zhanjie9@xxxxxxxxxxxxx>

BTW, this function can be slightly cleaned up, e.g. the 'goto' statement
can be removed.
> + if (err) {
> + kfree(data);
> + devfreq->governor_data = NULL;
> + }
> +
> out:
> return err;
> }