linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sumeet Pawnikar <sumeet4linux@gmail.com>
To: rafael@kernel.org, linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, sumeet4linux@gmail.com
Subject: [PATCH] powercap: fix memory leak in intel_rapl_common
Date: Mon,  8 Dec 2025 00:32:08 +0530	[thread overview]
Message-ID: <20251207190210.471764-1-sumeet4linux@gmail.com> (raw)

The err_cleanup path in rapl_package_register_powercap() function
doesn't free rp->domains before returning when child domain
registration fails. Also, there is a missing the cleanup for the
parent package power zone which was successfully registered earlier.

When registration of child domains fails, now the previously
registered package domain (parent zone) is being unregistered.
This makes both parent and child powercap zones are properly
unregistered before returning the error.
Also, fix the rp->power_zone dangling pointer issue by setting it
to NULL.

Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com>
---
 drivers/powercap/intel_rapl_common.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index b9d87e56cbbc..5ea31433abf2 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -1406,6 +1406,13 @@ static int rapl_package_register_powercap(struct rapl_package *rp)
 					 &rd->power_zone);
 	}
 
+	/* Also unregister the package domain if it was registered */
+	if (rp->power_zone) {
+		powercap_unregister_zone(rp->priv->control_type,
+					 rp->power_zone);
+		rp->power_zone = NULL;
+	}
+
 	return ret;
 }
 
-- 
2.43.0


             reply	other threads:[~2025-12-07 19:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-07 19:02 Sumeet Pawnikar [this message]
2025-12-15 11:41 ` [PATCH] powercap: fix memory leak in intel_rapl_common Rafael J. Wysocki

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=20251207190210.471764-1-sumeet4linux@gmail.com \
    --to=sumeet4linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@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;
as well as URLs for NNTP newsgroup(s).