From: Mike Leach <mike.leach@arm.com>
To: Yingchao Deng <dengyingchao@kylinsec.com.cn>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
James Clark <james.clark@linaro.org>, Leo Yan <leo.yan@arm.com>
Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, qinyungao@kylinsec.com.cn,
nd@arm.com
Subject: Re: [PATCH v2 1/1] coresight: syscfg: fix deadlock on device registration failure
Date: Wed, 23 Sep 2026 11:04:48 +0100 [thread overview]
Message-ID: <5c29acfd-a057-4edf-b885-3ad26c303179@arm.com> (raw)
In-Reply-To: <6CC680FFAC60931F+20260914074900.1711-1-dengyingchao@kylinsec.com.cn>
Reviewed-by: Mike Leach <mike.leach@arm.com>
On 9/14/26 08:49, Yingchao Deng wrote:
> cscfg_create_device() calls put_device() on the error path while holding
> cscfg_mutex. If device_register() fails, put_device() drops the last
> reference and invokes cscfg_dev_release(), which takes cscfg_mutex again,
> deadlocking.
>
> Module init and exit are serialized by the kernel, so cscfg_mutex is not
> needed to protect the allocation and freeing of cscfg_mgr. Remove the
> mutex from cscfg_dev_release() and take it only while cscfg_mgr fields
> are being accessed.
>
> Fixes: 199380decc5f ("coresight: configfs: Fix unload of configurations on module exit")
> Suggested-by: Leo Yan <leo.yan@arm.com>
> Signed-off-by: Yingchao Deng <dengyingchao@kylinsec.com.cn>
> ---
> drivers/hwtracing/coresight/coresight-syscfg.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
> index 2bfdd7b45e49..2dd0b29f44e4 100644
> --- a/drivers/hwtracing/coresight/coresight-syscfg.c
> +++ b/drivers/hwtracing/coresight/coresight-syscfg.c
> @@ -1173,27 +1173,21 @@ struct device *cscfg_device(void)
> /* Must have a release function or the kernel will complain on module unload */
> static void cscfg_dev_release(struct device *dev)
> {
> - mutex_lock(&cscfg_mutex);
> kfree(cscfg_mgr);
> cscfg_mgr = NULL;
> - mutex_unlock(&cscfg_mutex);
> }
>
> /* a device is needed to "own" some kernel elements such as sysfs entries. */
> static int cscfg_create_device(void)
> {
> struct device *dev;
> - int err = -ENOMEM;
> -
> - mutex_lock(&cscfg_mutex);
> - if (cscfg_mgr) {
> - err = -EINVAL;
> - goto create_dev_exit_unlock;
> - }
> + int err;
>
> cscfg_mgr = kzalloc_obj(struct cscfg_manager);
> if (!cscfg_mgr)
> - goto create_dev_exit_unlock;
> + return -ENOMEM;
> +
> + mutex_lock(&cscfg_mutex);
>
> /* initialise the cscfg_mgr structure */
> INIT_LIST_HEAD(&cscfg_mgr->csdev_desc_list);
> @@ -1204,6 +1198,8 @@ static int cscfg_create_device(void)
> cscfg_mgr->load_state = CSCFG_NONE;
> raw_spin_lock_init(&cscfg_mgr->sysfs_store_lock);
>
> + mutex_unlock(&cscfg_mutex);
> +
> /* setup the device */
> dev = cscfg_device();
> dev->release = cscfg_dev_release;
> @@ -1213,8 +1209,6 @@ static int cscfg_create_device(void)
> if (err)
> put_device(dev);
>
> -create_dev_exit_unlock:
> - mutex_unlock(&cscfg_mutex);
> return err;
> }
>
next prev parent reply other threads:[~2026-09-23 10:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 7:45 [PATCH v2 0/1] " Yingchao Deng
2026-09-14 7:49 ` [PATCH v2 1/1] " Yingchao Deng
2026-09-23 10:04 ` Mike Leach [this message]
2026-09-24 16:24 ` Leo Yan
2026-09-25 2:40 ` yingchao deng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5c29acfd-a057-4edf-b885-3ad26c303179@arm.com \
--to=mike.leach@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=dengyingchao@kylinsec.com.cn \
--cc=james.clark@linaro.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nd@arm.com \
--cc=qinyungao@kylinsec.com.cn \
--cc=suzuki.poulose@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®