The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Sean Anderson <sean.anderson@linux.dev>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>,
	coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
	James Clark <james.clark@linaro.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Yeoreum Yun <yeoreum.yun@arm.com>,
	Linu Cherian <lcherian@marvell.com>,
	Mike Leach <mike.leach@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/2] coresight: Fix fwnode leak in coresight_register error path
Date: Mon, 22 Sep 2025 11:06:53 +0100	[thread overview]
Message-ID: <20250922100653.GE516577@e132581.arm.com> (raw)
In-Reply-To: <20250919160653.507109-2-sean.anderson@linux.dev>

On Fri, Sep 19, 2025 at 12:06:52PM -0400, Sean Anderson wrote:
> If registering the CPU map fails, we need to put the fwnode. free_percpu
> works when called with a NULL pointer, so just use
> coresight_device_release.
> 
> Fixes: 5ad628a76176 ("coresight: Use per-sink trace ID maps for Perf sessions")
> Signed-off-by: Sean Anderson <sean.anderson@linux.dev>

I have a patch that fixes the same issue:

https://lore.kernel.org/linux-arm-kernel/20250512154108.23920-2-leo.yan@arm.com/

The difference in my patch is about the sequence: first it allocates the
resource, then increases the fw node's reference count. During release,
it first decreases the reference count, and then safely releases the
resource.

After comparing your patch, I still think the above reason is valid.

That said, I agree we should put this fixing before the panic notifier
fix. This would be friendly for backporting.

Thanks,
Leo

> ---
> 
> Changes in v4:
> - New
> 
>  drivers/hwtracing/coresight/coresight-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index fa758cc21827..022c8384b98d 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1352,7 +1352,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>  		raw_spin_lock_init(&csdev->perf_sink_id_map.lock);
>  		csdev->perf_sink_id_map.cpu_map = alloc_percpu(atomic_t);
>  		if (!csdev->perf_sink_id_map.cpu_map) {
> -			kfree(csdev);
> +			coresight_device_release(&csdev->dev);
>  			ret = -ENOMEM;
>  			goto err_out;
>  		}
> -- 
> 2.35.1.1320.gc452695387.dirty
> 

  reply	other threads:[~2025-09-22 10:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-19 16:06 [PATCH v4 0/2] coresight: Fix possible deadlock in coresight_panic_cb Sean Anderson
2025-09-19 16:06 ` [PATCH v4 1/2] coresight: Fix fwnode leak in coresight_register error path Sean Anderson
2025-09-22 10:06   ` Leo Yan [this message]
2025-09-19 16:06 ` [PATCH v4 2/2] coresight: Fix possible deadlock in coresight_panic_cb Sean Anderson
2025-09-22 10:34   ` Leo Yan

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=20250922100653.GE516577@e132581.arm.com \
    --to=leo.yan@arm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@linaro.org \
    --cc=lcherian@marvell.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.leach@linaro.org \
    --cc=sean.anderson@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=yeoreum.yun@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