From: Chanwoo Choi <cwchoi00@gmail.com>
To: Malaya Kumar Rout <malayarout91@gmail.com>,
zhanjie9@hisilicon.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: Mon, 16 Nov 2026 06:29:07 +0900 [thread overview]
Message-ID: <d8ba1575-f5b3-4794-8b63-f139897074e0@gmail.com> (raw)
In-Reply-To: <20260729133523.357383-1-malayarout91@gmail.com>
On 7/29/2026 10: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>
> ---
> 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;
> }
>
Applied it.
--
Best Regards,
Chanwoo Choi
Principal Engineer, Samsung Electronics
prev parent reply other threads:[~2026-11-15 21:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 16:32 [PATCH] " 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
2026-11-15 21:29 ` Chanwoo Choi [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=d8ba1575-f5b3-4794-8b63-f139897074e0@gmail.com \
--to=cwchoi00@gmail.com \
--cc=chanwoo@kernel.org \
--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 \
--cc=zhanjie9@hisilicon.com \
/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
all inboxes | Powered by JetHome®