Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure
@ 2026-05-11  9:04 Jie Gan
  2026-05-11  9:20 ` Jie Gan
  2026-05-11  9:24 ` Leo Yan
  0 siblings, 2 replies; 6+ messages in thread
From: Jie Gan @ 2026-05-11  9:04 UTC (permalink / raw)
  To: Suzuki K Poulose, Mike Leach, James Clark, Leo Yan,
	Alexander Shishkin, Tingwei Zhang
  Cc: coresight, linux-arm-kernel, linux-kernel, Jie Gan, Jie Gan

In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM,
OTHERS), the source device is enabled via coresight_enable_source_sysfs()
before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the
original code jumped directly to err_source, which only calls
coresight_disable_path() and coresight_release_path(). The source device
was left enabled with an incremented refcnt but no path tracked for it,
leaving the device in an inconsistent state.

Disable the source before jumping to err_source so the enable and path
operations are fully unwound.

Fixes: 1f5149c7751c ("coresight: Move all sysfs code to sysfs file")
Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>
---
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
 drivers/hwtracing/coresight/coresight-sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c
index d2a6ed8bcc74..a5c08fab97a1 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -244,8 +244,10 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
 		 */
 		hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev)));
 		ret = idr_alloc_u32(&path_idr, path, &hash, hash, GFP_KERNEL);
-		if (ret)
+		if (ret) {
+			coresight_disable_source_sysfs(csdev, NULL);
 			goto err_source;
+		}
 		break;
 	default:
 		/* We can't be here */

---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260511-fix-coresight-sysfs-enable-issue-91533f26f9bb

Best regards,
-- 
Jie Gan <jie.gan@oss.qualcomm.com>



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

* Re: [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure
  2026-05-11  9:04 [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure Jie Gan
@ 2026-05-11  9:20 ` Jie Gan
  2026-05-11  9:24 ` Leo Yan
  1 sibling, 0 replies; 6+ messages in thread
From: Jie Gan @ 2026-05-11  9:20 UTC (permalink / raw)
  To: Suzuki K Poulose, Mike Leach, James Clark, Leo Yan,
	Alexander Shishkin, Tingwei Zhang
  Cc: coresight, linux-arm-kernel, linux-kernel, Jie Gan



On 5/11/2026 5:04 PM, Jie Gan wrote:
> In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM,
> OTHERS), the source device is enabled via coresight_enable_source_sysfs()
> before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the
> original code jumped directly to err_source, which only calls
> coresight_disable_path() and coresight_release_path(). The source device
> was left enabled with an incremented refcnt but no path tracked for it,
> leaving the device in an inconsistent state.
> 
> Disable the source before jumping to err_source so the enable and path
> operations are fully unwound.
> 
> Fixes: 1f5149c7751c ("coresight: Move all sysfs code to sysfs file")
> Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>

My git made a mistake here..
should be:
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>

Thanks,
Jie

> ---
> Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
> ---
>   drivers/hwtracing/coresight/coresight-sysfs.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c
> index d2a6ed8bcc74..a5c08fab97a1 100644
> --- a/drivers/hwtracing/coresight/coresight-sysfs.c
> +++ b/drivers/hwtracing/coresight/coresight-sysfs.c
> @@ -244,8 +244,10 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
>   		 */
>   		hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev)));
>   		ret = idr_alloc_u32(&path_idr, path, &hash, hash, GFP_KERNEL);
> -		if (ret)
> +		if (ret) {
> +			coresight_disable_source_sysfs(csdev, NULL);
>   			goto err_source;
> +		}
>   		break;
>   	default:
>   		/* We can't be here */
> 
> ---
> base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
> change-id: 20260511-fix-coresight-sysfs-enable-issue-91533f26f9bb
> 
> Best regards,



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

* Re: [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure
  2026-05-11  9:04 [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure Jie Gan
  2026-05-11  9:20 ` Jie Gan
@ 2026-05-11  9:24 ` Leo Yan
  2026-05-11  9:28   ` Jie Gan
  1 sibling, 1 reply; 6+ messages in thread
From: Leo Yan @ 2026-05-11  9:24 UTC (permalink / raw)
  To: Jie Gan
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
	Tingwei Zhang, coresight, linux-arm-kernel, linux-kernel, Jie Gan

On Mon, May 11, 2026 at 05:04:44PM +0800, Jie Gan wrote:
> In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM,
> OTHERS), the source device is enabled via coresight_enable_source_sysfs()
> before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the
> original code jumped directly to err_source, which only calls
> coresight_disable_path() and coresight_release_path(). The source device
> was left enabled with an incremented refcnt but no path tracked for it,
> leaving the device in an inconsistent state.
> 
> Disable the source before jumping to err_source so the enable and path
> operations are fully unwound.
> 
> Fixes: 1f5149c7751c ("coresight: Move all sysfs code to sysfs file")
> Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>

Actually I have noticed this. Since my PM series will remove IDR things,
and I don't think anyone really hit idr alloc error, this is why I
didn't send fix for this.

Anyway, this is a reasonable fix. I will send out my PM series later
in today, I will pick this patch into my series and rebase on it, hope
this is easier for all of us.

Thanks,
Leo


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

* Re: [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure
  2026-05-11  9:24 ` Leo Yan
@ 2026-05-11  9:28   ` Jie Gan
  2026-05-11  9:40     ` Leo Yan
  0 siblings, 1 reply; 6+ messages in thread
From: Jie Gan @ 2026-05-11  9:28 UTC (permalink / raw)
  To: Leo Yan
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
	Tingwei Zhang, coresight, linux-arm-kernel, linux-kernel, Jie Gan

Hi Leo,

On 5/11/2026 5:24 PM, Leo Yan wrote:
> On Mon, May 11, 2026 at 05:04:44PM +0800, Jie Gan wrote:
>> In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM,
>> OTHERS), the source device is enabled via coresight_enable_source_sysfs()
>> before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the
>> original code jumped directly to err_source, which only calls
>> coresight_disable_path() and coresight_release_path(). The source device
>> was left enabled with an incremented refcnt but no path tracked for it,
>> leaving the device in an inconsistent state.
>>
>> Disable the source before jumping to err_source so the enable and path
>> operations are fully unwound.
>>
>> Fixes: 1f5149c7751c ("coresight: Move all sysfs code to sysfs file")
>> Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>
> 
> Actually I have noticed this. Since my PM series will remove IDR things,
> and I don't think anyone really hit idr alloc error, this is why I
> didn't send fix for this.
> 
> Anyway, this is a reasonable fix. I will send out my PM series later
> in today, I will pick this patch into my series and rebase on it, hope
> this is easier for all of us.

Well noted. Please feel free to pick it into your series.

Thanks,
Jie

> 
> Thanks,
> Leo



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

* Re: [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure
  2026-05-11  9:28   ` Jie Gan
@ 2026-05-11  9:40     ` Leo Yan
  2026-05-11  9:42       ` Jie Gan
  0 siblings, 1 reply; 6+ messages in thread
From: Leo Yan @ 2026-05-11  9:40 UTC (permalink / raw)
  To: Jie Gan
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
	Tingwei Zhang, coresight, linux-arm-kernel, linux-kernel, Jie Gan

On Mon, May 11, 2026 at 05:28:37PM +0800, Jie Gan wrote:
> Hi Leo,
> 
> On 5/11/2026 5:24 PM, Leo Yan wrote:
> > On Mon, May 11, 2026 at 05:04:44PM +0800, Jie Gan wrote:
> > > In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM,
> > > OTHERS), the source device is enabled via coresight_enable_source_sysfs()
> > > before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the
> > > original code jumped directly to err_source, which only calls
> > > coresight_disable_path() and coresight_release_path(). The source device
> > > was left enabled with an incremented refcnt but no path tracked for it,
> > > leaving the device in an inconsistent state.
> > > 
> > > Disable the source before jumping to err_source so the enable and path
> > > operations are fully unwound.
> > > 
> > > Fixes: 1f5149c7751c ("coresight: Move all sysfs code to sysfs file")
> > > Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>
> > 
> > Actually I have noticed this. Since my PM series will remove IDR things,
> > and I don't think anyone really hit idr alloc error, this is why I
> > didn't send fix for this.
> > 
> > Anyway, this is a reasonable fix. I will send out my PM series later
> > in today, I will pick this patch into my series and rebase on it, hope
> > this is easier for all of us.
> 
> Well noted. Please feel free to pick it into your series.

Thanks! Just note, I updated the Fixes tag as:

  Fixes: 5c0016d7b343 ("coresight: core: Use IDR for non-cpu bound sources' paths.")

Which is the original patch for the issue.

Thanks,
Leo


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

* Re: [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure
  2026-05-11  9:40     ` Leo Yan
@ 2026-05-11  9:42       ` Jie Gan
  0 siblings, 0 replies; 6+ messages in thread
From: Jie Gan @ 2026-05-11  9:42 UTC (permalink / raw)
  To: Leo Yan
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
	Tingwei Zhang, coresight, linux-arm-kernel, linux-kernel, Jie Gan



On 5/11/2026 5:40 PM, Leo Yan wrote:
> On Mon, May 11, 2026 at 05:28:37PM +0800, Jie Gan wrote:
>> Hi Leo,
>>
>> On 5/11/2026 5:24 PM, Leo Yan wrote:
>>> On Mon, May 11, 2026 at 05:04:44PM +0800, Jie Gan wrote:
>>>> In coresight_enable_sysfs(), for non-CPU sources (SOFTWARE, TPDM,
>>>> OTHERS), the source device is enabled via coresight_enable_source_sysfs()
>>>> before idr_alloc_u32() maps the path. If idr_alloc_u32() fails, the
>>>> original code jumped directly to err_source, which only calls
>>>> coresight_disable_path() and coresight_release_path(). The source device
>>>> was left enabled with an incremented refcnt but no path tracked for it,
>>>> leaving the device in an inconsistent state.
>>>>
>>>> Disable the source before jumping to err_source so the enable and path
>>>> operations are fully unwound.
>>>>
>>>> Fixes: 1f5149c7751c ("coresight: Move all sysfs code to sysfs file")
>>>> Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>
>>>
>>> Actually I have noticed this. Since my PM series will remove IDR things,
>>> and I don't think anyone really hit idr alloc error, this is why I
>>> didn't send fix for this.
>>>
>>> Anyway, this is a reasonable fix. I will send out my PM series later
>>> in today, I will pick this patch into my series and rebase on it, hope
>>> this is easier for all of us.
>>
>> Well noted. Please feel free to pick it into your series.
> 
> Thanks! Just note, I updated the Fixes tag as:
> 
>    Fixes: 5c0016d7b343 ("coresight: core: Use IDR for non-cpu bound sources' paths.")

Thanks for the correction.

Jie

> 
> Which is the original patch for the issue.
> 
> Thanks,
> Leo



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

end of thread, other threads:[~2026-05-11  9:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11  9:04 [PATCH] coresight: fix source not disabled on idr_alloc_u32 failure Jie Gan
2026-05-11  9:20 ` Jie Gan
2026-05-11  9:24 ` Leo Yan
2026-05-11  9:28   ` Jie Gan
2026-05-11  9:40     ` Leo Yan
2026-05-11  9:42       ` Jie Gan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox