[PATCH] stm: core: Initialize source state before device_add

Runyu Xiao runyu.xiao at seu.edu.cn
Tue Sep 1 04:53:20 PDT 2026


device_add() publishes the source device and creates its sysfs
attributes. A concurrent sysfs operation can therefore reach the source
before its output, link lock, list entry, or data pointers are initialized.
Initialize the source state before publication, including the back-pointer
used by source callbacks. Drop any link established during publication
before clearing the back-pointer and releasing the source on failure.

Signed-off-by: Runyu Xiao <runyu.xiao at seu.edu.cn>
Assisted-by: Codex:GPT-5
Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")
Cc: stable at vger.kernel.org
---
 drivers/hwtracing/stm/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index f48c6a8a0..487fb747f 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -1256,19 +1256,21 @@ int stm_source_register_device(struct device *parent,
 	pm_runtime_no_callbacks(&src->dev);
 	pm_runtime_forbid(&src->dev);
 
-	err = device_add(&src->dev);
-	if (err)
-		goto err;
-
 	stm_output_init(&src->output);
 	spin_lock_init(&src->link_lock);
 	INIT_LIST_HEAD(&src->link_entry);
 	src->data = data;
 	data->src = src;
 
+	err = device_add(&src->dev);
+	if (err)
+		goto err;
+
 	return 0;
 
 err:
+	stm_source_link_drop(src);
+	data->src = NULL;
 	put_device(&src->dev);
 
 	return err;
-- 
2.34.1




More information about the linux-arm-kernel mailing list