Linux Power Management development
 help / color / mirror / Atom feed
From: Jie Zhan <zhanjie9@hisilicon.com>
To: Malaya Kumar Rout <malayarout91@gmail.com>,
	<linux-pm@vger.kernel.org>, <myungjoo.ham@samsung.com>,
	<kyungmin.park@samsung.com>, <cw00.choi@samsung.com>,
	<kant@allwinnertech.com>
Cc: <skhan@linuxfoundation.org>, <me@brighamcampbell.com>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] PM / devfreq: userspace: Fix memory leak in userspace_init()
Date: Thu, 30 Jul 2026 20:51:10 +0800	[thread overview]
Message-ID: <dc2f03bc-037c-49ab-a34f-caf4dc4c4afa@hisilicon.com> (raw)
In-Reply-To: <20260729133523.357383-1-malayarout91@gmail.com>



On 7/29/2026 9:35 PM, 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.
> 
> v2:
> - Removed redundant 'out:' goto label and returned -ENOMEM directly
>   on allocation failure.
> 
> Fixes: 5fdded844892 ("PM/devfreq: governor: Add a private governor_data for governor")
> Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
Thanks. LGTM.
Reviewed-by: Jie Zhan <zhanjie9@hisilicon.com>
> ---
>  drivers/devfreq/governor_userspace.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/devfreq/governor_userspace.c b/drivers/devfreq/governor_userspace.c
> index 3906ebedbae8..8211aadb81f0 100644
> --- a/drivers/devfreq/governor_userspace.c
> +++ b/drivers/devfreq/governor_userspace.c
> @@ -89,15 +89,18 @@ static int userspace_init(struct devfreq *devfreq)
>  	int err = 0;
>  	struct userspace_data *data = kzalloc_obj(struct userspace_data);
>  
> -	if (!data) {
> -		err = -ENOMEM;
> -		goto out;
> -	}
> +	if (!data)
> +		return -ENOMEM;
> +
>  	data->valid = false;
>  	devfreq->governor_data = data;
>  
>  	err = sysfs_create_group(&devfreq->dev.kobj, &dev_attr_group);
> -out:
> +	if (err) {
> +		kfree(data);
> +		devfreq->governor_data = NULL;
> +	}
> +
>  	return err;
>  }
>  

      reply	other threads:[~2026-07-30 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dc2f03bc-037c-49ab-a34f-caf4dc4c4afa@hisilicon.com \
    --to=zhanjie9@hisilicon.com \
    --cc=cw00.choi@samsung.com \
    --cc=kant@allwinnertech.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=malayarout91@gmail.com \
    --cc=me@brighamcampbell.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox