mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Zhang <yuz08559@gmail.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] stm class: drop the source link after the source device is gone
Date: Sun,  1 Nov 2026 16:23:17 +1000	[thread overview]
Message-ID: <20261101062317.16608-1-yuz08559@gmail.com> (raw)

stm_source_unregister_device() drops the link of the source and only
then unregisters its device. The stm_source_link sysfs attribute is
still reachable in between, so a concurrent write to it re-links the
source: it ends up on the stm device's link list with src->link set and
the source's link() callback armed, after which device_unregister()
frees it and the source module is unloaded. The next unlink walk in
stm_unregister_device() then touches the freed source, the stm device
keeps a reference that is never dropped, and a source like
stm_heartbeat has its hrtimer fire in freed module memory.

Delete the device first, which drains the sysfs attribute, then drop
the link and release the device.

Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")
Cc: stable@vger.kernel.org
Signed-off-by: Yu Zhang <yuz08559@gmail.com>
---
 drivers/hwtracing/stm/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 5fbea4e..64a9eb1 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -1287,9 +1287,9 @@ void stm_source_unregister_device(struct stm_source_data *data)
 {
 	struct stm_source_device *src = data->src;
 
+	device_del(&src->dev);
 	stm_source_link_drop(src);
-
-	device_unregister(&src->dev);
+	put_device(&src->dev);
 }
 EXPORT_SYMBOL_GPL(stm_source_unregister_device);
 
-- 
2.43.0


                 reply	other threads:[~2026-11-01  6:23 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=20261101062317.16608-1-yuz08559@gmail.com \
    --to=yuz08559@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®