mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] coresight: syscfg: fix deadlock on device registration failure
@ 2026-08-25  1:47 yingchao
  2026-09-07  3:06 ` yingchao deng
  2026-09-08 16:16 ` Leo Yan
  0 siblings, 2 replies; 5+ messages in thread
From: yingchao @ 2026-08-25  1:47 UTC (permalink / raw)
  To: Suzuki K Poulose, Alexander Shishkin
  Cc: Mike Leach, James Clark, Leo Yan, Mathieu Poirier, Miaoqian Lin,
	coresight, linux-arm-kernel, linux-kernel, qinyungao,
	Yingchao Deng

From: Yingchao Deng <dengyingchao@kylinsec.com.cn>

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@kylinsec.com.cn>
---
 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-09  9:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-25  1:47 [PATCH] coresight: syscfg: fix deadlock on device registration failure yingchao
2026-09-07  3:06 ` yingchao deng
2026-09-08 16:16 ` Leo Yan
2026-09-09  1:34   ` yingchao deng
2026-09-09  9:29     ` Leo Yan

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®