[PATCH 2/2] coresight: perf: Use %px for printing pointers

Leo Yan leo.yan at arm.com
Thu Jun 12 02:11:28 PDT 2025


On Thu, Jun 12, 2025 at 11:14:00AM +0530, Anshuman Khandual wrote:
> On 11/06/25 8:14 PM, Leo Yan wrote:
> > Use "%px" to print a pointer, which is better than casting the pointer
> > to unsigned long and printing it with the "%lx" specifier.
> > 
> > Note, the printing format will be updated as 64-bit value:
> > 
> >   # cat /sys/devices/cs_etm/sinks/trbe0
> >   0x000000003744496a
> 
> But what was it before this patch is applied ? Just wondering if
> there are sysfs changes that might be visible to the user space.

Good question. Before this patch, the printing does not pad with
leading zeros, so the output result is:

    # cat /sys/devices/cs_etm/sinks/trbe0
    0x3744496a

The perf tool in user space extracts the lower 32-bit value with the
specifier "%x". I verified that this would be fine that the tool can
read out the hash value properly.

    ret = perf_pmu__scan_file(pmu, path, "%x", &hash);

Thanks,
Leo


> > This commit dismisses the following smatch warnings:
> > 
> >   coresight-etm-perf.c:854 etm_perf_sink_name_show() warn: argument 4 to %lx specifier is cast from pointer
> >   coresight-etm-perf.c:946 etm_perf_cscfg_event_show() warn: argument 4 to %lx specifier is cast from pointer
> > 
> > Signed-off-by: Leo Yan <leo.yan at arm.com>
> > ---
> >  drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > index f1551c08ecb20ebd7feab82dbaee3176e6bcc999..f677c08233ba1a28b277674662c6e6db904873dd 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > @@ -851,7 +851,7 @@ static ssize_t etm_perf_sink_name_show(struct device *dev,
> >  	struct dev_ext_attribute *ea;
> >  
> >  	ea = container_of(dattr, struct dev_ext_attribute, attr);
> > -	return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
> > +	return scnprintf(buf, PAGE_SIZE, "0x%px\n", ea->var);
> >  }
> >  
> >  static struct dev_ext_attribute *
> > @@ -943,7 +943,7 @@ static ssize_t etm_perf_cscfg_event_show(struct device *dev,
> >  	struct dev_ext_attribute *ea;
> >  
> >  	ea = container_of(dattr, struct dev_ext_attribute, attr);
> > -	return scnprintf(buf, PAGE_SIZE, "configid=0x%lx\n", (unsigned long)(ea->var));
> > +	return scnprintf(buf, PAGE_SIZE, "configid=0x%px\n", ea->var);
> >  }
> >  
> >  int etm_perf_add_symlink_cscfg(struct device *dev, struct cscfg_config_desc *config_desc)
> > 



More information about the linux-arm-kernel mailing list