Linux Power Management development
 help / color / mirror / Atom feed
From: Malaya Kumar Rout <malayarout91@gmail.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	linux-pm@vger.kernel.org
Cc: mrout@redhat.com, skhan@linuxfoundation.org,
	me@brighamcampbell.com,
	Malaya Kumar Rout <malayarout91@gmail.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Kant Fan <kant@allwinnertech.com>
Subject: [PATCH] PM / devfreq: userspace: Fix memory leak in userspace_init()
Date: Sat,  4 Jul 2026 22:02:38 +0530	[thread overview]
Message-ID: <20260704163238.115819-1-malayarout91@gmail.com> (raw)

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@gmail.com>
---
 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


                 reply	other threads:[~2026-07-04 16:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260704163238.115819-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=mrout@redhat.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=skhan@linuxfoundation.org \
    --cc=stable@vger.kernel.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