[PATCH] coresight: syscfg: fix deadlock on device registration failure
From: yingchao
Date: Mon Aug 24 2026 - 21:50:47 EST
From: Yingchao Deng <dengyingchao@xxxxxxxxxxxxxxx>
cscfg_create_device() calls put_device() while holding cscfg_mutex. If
device_register() failed, put_device() drops the last reference and invokes
cscfg_dev_release(), which takes cscfg_mutex again, deadlocking.
Unlock cscfg_mutex before calling put_device().
Fixes: cfa5dbcdd7ae ("coresight: syscfg: Fix memleak on registration failure in cscfg_create_device")
Signed-off-by: Yingchao Deng <dengyingchao@xxxxxxxxxxxxxxx>
---
drivers/hwtracing/coresight/coresight-syscfg.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
index 2bfdd7b45e49..d0e7e4720e46 100644
--- a/drivers/hwtracing/coresight/coresight-syscfg.c
+++ b/drivers/hwtracing/coresight/coresight-syscfg.c
@@ -1210,8 +1210,14 @@ static int cscfg_create_device(void)
dev->init_name = "cs_system_cfg";
err = device_register(dev);
- if (err)
+ if (err) {
+ /* put_device() triggers cscfg_dev_release() which takes
+ * cscfg_mutex, so drop the lock first to avoid deadlocking.
+ */
+ mutex_unlock(&cscfg_mutex);
put_device(dev);
+ return err;
+ }
create_dev_exit_unlock:
mutex_unlock(&cscfg_mutex);
--
2.33.0