If device_register() fails, put_device() is called with cscfg_mutex held. This calls cscfg_dev_release() which takes cscfg_mutex again and deadlocks. Drop the mutex before calling put_device().
Fixes: 199380decc5f ("coresight: configfs: Fix unload of configurations on module exit") Reported-by: Sashiko sashiko-bot@kernel.org Closes: https://sashiko.dev/#/bug/linux-e07a8e2f-c34e-4609-a667-9f294c6fcf29 Signed-off-by: James Clark james.clark@linaro.org --- drivers/hwtracing/coresight/coresight-syscfg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index f93150a1bee4..92aef8b9c734 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -1217,8 +1217,12 @@ static int cscfg_create_device(void) dev->init_name = "cs_system_cfg";
err = device_register(dev); - if (err) + if (err) { + /* cscfg_dev_release() takes cscfg_mutex */ + mutex_unlock(&cscfg_mutex); put_device(dev); + return err; + }
create_dev_exit_unlock: mutex_unlock(&cscfg_mutex);