Linux Power Management development
 help / color / mirror / Atom feed
From: Malaya Kumar Rout <malayarout91@gmail.com>
To: 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,
	Malaya Kumar Rout <malayarout91@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] PM / devfreq: userspace: Fix memory leak in userspace_init()
Date: Wed, 29 Jul 2026 19:05:22 +0530	[thread overview]
Message-ID: <20260729133523.357383-1-malayarout91@gmail.com> (raw)
In-Reply-To: <511c7f13-3344-44bf-a960-044fc2401789@hisilicon.com>

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;
 }
 
-- 
2.54.0


      reply	other threads:[~2026-07-29 13:35 UTC|newest]

Thread overview: 4+ 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   ` Malaya Kumar Rout [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=20260729133523.357383-1-malayarout91@gmail.com \
    --to=malayarout91@gmail.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=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