Linux Power Management development
 help / color / mirror / Atom feed
From: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com,
	cw00.choi@samsung.com
Cc: linux-pm@vger.kernel.org,
	Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Subject: [PATCH v2] PM / devfreq: Fix memory leak in devfreq_event_add_edev()
Date: Sun,  7 Sep 2025 17:03:02 +0530	[thread overview]
Message-ID: <20250907113302.3353584-1-kaushlendra.kumar@intel.com> (raw)

Add missing kfree() call to prevent memory leak when device_register()
fails in devfreq_event_add_edev(). The allocated edev structure was not
being freed in the error path, causing a memory leak.

When device_register() fails, the edev structure allocated earlier in
the function needs to be freed before calling put_device() to avoid
leaking memory.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
Changes in v2:
- moved kfree after put_device based on review feedback
---
 drivers/devfreq/devfreq-event.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c
index 70219099c604..34406c52b845 100644
--- a/drivers/devfreq/devfreq-event.c
+++ b/drivers/devfreq/devfreq-event.c
@@ -328,6 +328,7 @@ struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
 	ret = device_register(&edev->dev);
 	if (ret < 0) {
 		put_device(&edev->dev);
+		kfree(edev);
 		return ERR_PTR(ret);
 	}
 	dev_set_drvdata(&edev->dev, edev);
-- 
2.34.1


             reply	other threads:[~2025-09-07 11:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-07 11:33 Kaushlendra Kumar [this message]
2025-09-07 12:18 ` [PATCH v2] PM / devfreq: Fix memory leak in devfreq_event_add_edev() Chanwoo Choi

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=20250907113302.3353584-1-kaushlendra.kumar@intel.com \
    --to=kaushlendra.kumar@intel.com \
    --cc=cw00.choi@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=myungjoo.ham@samsung.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