mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] stm: Fix potential policy leak after device unregistration
Date: Fri, 13 Nov 2026 22:06:49 +0800	[thread overview]
Message-ID: <20261113-4e14e563a1-stm@mail.sdu.edu.cn> (raw)

A policy can outlive its STM device. When that happens, device teardown
has already cleared policy->stm and stp_policy_release() returns without
freeing the policy.

Only skip unbinding an already unbound policy; always free its memory.

This issue was found by our static analysis tool under development.

Fixes: 4c127fd16e6b ("stm class: Fix locking in unbinding policy path")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/hwtracing/stm/policy.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/hwtracing/stm/policy.c b/drivers/hwtracing/stm/policy.c
index fabaf4b14889..ec0c9f4d693e 100644
--- a/drivers/hwtracing/stm/policy.c
+++ b/drivers/hwtracing/stm/policy.c
@@ -354,12 +354,11 @@ static void stp_policy_release(struct config_item *item)
 	struct stm_device *stm = policy->stm;
 
 	/* a policy *can* be unbound and still exist in configfs tree */
-	if (!stm)
-		return;
-
-	mutex_lock(&stm->policy_mutex);
-	stp_policy_unbind(policy);
-	mutex_unlock(&stm->policy_mutex);
+	if (stm) {
+		mutex_lock(&stm->policy_mutex);
+		stp_policy_unbind(policy);
+		mutex_unlock(&stm->policy_mutex);
+	}
 
 	kfree(policy);
 }

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

                 reply	other threads:[~2026-11-13 14:06 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=20261113-4e14e563a1-stm@mail.sdu.edu.cn \
    --to=liguangshuo@mail.sdu.edu.cn \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --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

all inboxes | Powered by JetHome®