mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ma Ke <make24@iscas.ac.cn>
To: jie.gan@oss.qualcomm.com, leo.yan@arm.com, james.clark@linaro.org
Cc: akpm@linux-foundation.org, alexander.shishkin@linux.intel.com,
	coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, make24@iscas.ac.cn,
	mathieu.poirier@linaro.org, mike.leach@linaro.org,
	stable@vger.kernel.org, suzuki.poulose@arm.com
Subject: Re: [PATCH v2 RESEND] coresight: etm-perf: Fix reference count leak in etm_setup_aux
Date: Fri, 19 Dec 2025 10:39:49 +0800	[thread overview]
Message-ID: <20251219023949.12699-1-make24@iscas.ac.cn> (raw)
In-Reply-To: <f85c7d37-4980-46f0-9136-353a35a8f0ed@oss.qualcomm.com>

On 12/15/2025 10:09 AM, Jie Gan wrote:
> On 12/15/2025 5:51 PM, Leo Yan wrote:
>> On Mon, Dec 15, 2025 at 11:02:08AM +0200, James Clark wrote:
>>>
>>>
>>> On 15/12/2025 04:27, Ma Ke wrote:
>>>> In etm_setup_aux(), when a user sink is obtained via
>>>> coresight_get_sink_by_id(), it increments the reference count of the
>>>> sink device. However, if the sink is used in path building, the path
>>>> holds a reference, but the initial reference from
>>>> coresight_get_sink_by_id() is not released, causing a reference count
>>>> leak. We should release the initial reference after the path is built.
>>>>
>>>> Found by code review.
>>>>
>>>> Cc: stable@vger.kernel.org
>>>> Fixes: 0e6c20517596 ("coresight: etm-perf: Allow an event to use different sinks")
>>>> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
>>>> ---
>>>> Changes in v2:
>>>> - modified the patch as suggestions.
>>>
>>> I think Leo's comment on the previous v2 is still unaddressed. But releasing
>>> it in coresight_get_sink_by_id() would make it consistent with
>>> coresight_find_csdev_by_fwnode() and prevent further mistakes.
>> 
>> The point is the coresight core layer uses coresight_grab_device() to
>> increase the device's refcnt.  This is why we don't need to grab a
>> device when setup AUX.
>
> That make sense. We dont need to hold the refcnt for a while and it 
> should be released immediately after locating the required device.
>
> Thanks,
> Jie

>> 
>>> It also leads me to see that users of coresight_find_device_by_fwnode()
>>> should also release it, but only one out of two appears to.
>> 
>> Good finding!
>> 
>> Thanks,
>> Leo
>> 
Hi all,

Thank you for the insightful discussion. I've carefully read the 
feedback from Leo, James, and Jie, and now have a clear understanding 
of the reference count management.

The core issue: coresight_get_sink_by_id() internally calls 
bus_find_device(), which increases reference count via get_device().

From the discussion, I note two possible fix directions:

1. Release the initial reference in etm_setup_aux() (current v2 patch)
2. Modify the behavior of coresight_get_sink_by_id() itself so it 
doesn't increase the reference count. 

Leo mentioned referencing how acpi_dev_present() does it, and James 
also pointed out that APIs should be consistent. I think it makes 
sense that following the principle like "lookup doesn't hold a 
reference" could prevent similar leaks in the future.

To ensure the correctness of the v3 patch, I'd like to confirm which 
patch is preferred. If option 2 is the consensus, I'm happy to modify 
the implementation of coresight_get_sink_by_id() as suggested.

Looking forward to your further guidance.

Thanks!


  reply	other threads:[~2025-12-19  2:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15  2:27 Ma Ke
2025-12-15  9:02 ` James Clark
2025-12-15  9:51   ` Leo Yan
2025-12-15 10:09     ` Jie Gan
2025-12-19  2:39       ` Ma Ke [this message]
2025-12-19  9:41         ` Leo Yan
2025-12-19  9:59           ` Suzuki K Poulose
2025-12-19 11:38             ` Leo Yan
2025-12-19 11:48               ` Suzuki K Poulose
2025-12-19 12:17                 ` Leo Yan
2025-12-15  2:38 Ma Ke

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=20251219023949.12699-1-make24@iscas.ac.cn \
    --to=make24@iscas.ac.cn \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@linaro.org \
    --cc=jie.gan@oss.qualcomm.com \
    --cc=leo.yan@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=stable@vger.kernel.org \
    --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®