mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] stm class: drop the source link after the source device is gone
@ 2026-11-01  6:23 Yu Zhang
  0 siblings, 0 replies; only message in thread
From: Yu Zhang @ 2026-11-01  6:23 UTC (permalink / raw)
  To: Alexander Shishkin; +Cc: Greg Kroah-Hartman, linux-kernel, stable

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-01  6:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-01  6:23 [PATCH] stm class: drop the source link after the source device is gone Yu Zhang

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®