[PATCH v5 06/12] coresight: etm4x: fix leaked trace id

Leo Yan leo.yan at arm.com
Thu Apr 16 09:55:41 PDT 2026


On Wed, Apr 15, 2026 at 05:55:22PM +0100, Yeoreum Yun wrote:
> If etm4_enable_sysfs() fails in cscfg_csdev_enable_active_config(),
> the trace ID may be leaked because it is not released.
> 
> To address this, call etm4_release_trace_id() when etm4_enable_sysfs()
> fails in cscfg_csdev_enable_active_config().
> 
> Reviewed-by: Jie Gan <jie.gan at oss.qualcomm.com>
> Signed-off-by: Yeoreum Yun <yeoreum.yun at arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-etm4x-core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> index f55338a4989d..b199aebbdb60 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -920,8 +920,10 @@ static int etm4_enable_sysfs(struct coresight_device *csdev, struct coresight_pa
>  	cscfg_config_sysfs_get_active_cfg(&cfg_hash, &preset);
>  	if (cfg_hash) {
>  		ret = cscfg_csdev_enable_active_config(csdev, cfg_hash, preset);
> -		if (ret)
> +		if (ret) {
> +			etm4_release_trace_id(drvdata);
>  			return ret;
> +		}

LGTM:

Reviewed-by: Leo Yan <leo.yan at arm.com>

Just recording a bit thoughts.  As Suzuki mentioned, it would be better
to allocate trace IDs within a session.  We might consider maintaining
the trace ID map in the sink driver data, since the sink driver is
unique within a session so it is a central place to allocate trace ID.

We should use paired way for allocation and release. For example:

  coresight_enable_sysfs()
  {
      ...
      coresight_path_assign_trace_id(path);

  failed:
      coresight_path_unassign_trace_id(path);
  }

  coresight_disable_sysfs()
  {
      coresight_path_unassign_trace_id(path);
  }

But this requires broader refactoring.  E.g., the STM driver currently
allocates system trace IDs statically during probe, we might need to
consolidate for all modules to use dynamic allocation.

Thanks,
Leo



More information about the linux-arm-kernel mailing list