lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1b1a8514-e74f-439f-a3ab-ad19dda49c22@intel.com>
Date: Wed, 7 Feb 2024 10:10:50 +0200
From: Adrian Hunter <adrian.hunter@...el.com>
To: Li Zhijian <lizhijian@...itsu.com>, linux-kernel@...r.kernel.org
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
 Arnaldo Carvalho de Melo <acme@...nel.org>,
 Mark Rutland <mark.rutland@....com>,
 Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
 Jiri Olsa <jolsa@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
 Ian Rogers <irogers@...gle.com>, Thomas Gleixner <tglx@...utronix.de>,
 Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>,
 x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
 linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v2 2/4] arch/x86/events/core: Convert sprintf/snprintf to
 sysfs_emit

On 26/01/24 08:13, Li Zhijian wrote:
> Per filesystems/sysfs.rst, show() should only use sysfs_emit()
> or sysfs_emit_at() when formatting the value to be returned to user space.
> 
> coccinelle complains that there are still a couple of functions that use
> snprintf(). Convert them to sysfs_emit().
> 
>> ./arch/x86/events/core.c:1895:11-19: WARNING: please use sysfs_emit
>                            ^^^^^ this one cannot convert to sysfs_emit
>                                  where it intends to print a sub-string.
> 
>> ./arch/x86/events/core.c:2542:8-16: WARNING: please use sysfs_emit
>> ./arch/x86/events/core.c:2600:8-16: WARNING: please use sysfs_emit
> 
> Most of this patch is generated by:
> $ make coccicheck MODE=patch COCCI=scripts/coccinelle/api/device_attr_show.cocci M=arch/x86/events/core.c | sed -n '6,$p' | patch -p1
> 
> No functional change intended
> 
> CC: Peter Zijlstra <peterz@...radead.org>
> CC: Ingo Molnar <mingo@...hat.com>
> CC: Arnaldo Carvalho de Melo <acme@...nel.org>
> CC: Mark Rutland <mark.rutland@....com>
> CC: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
> CC: Jiri Olsa <jolsa@...nel.org>
> CC: Namhyung Kim <namhyung@...nel.org>
> CC: Ian Rogers <irogers@...gle.com>
> CC: Adrian Hunter <adrian.hunter@...el.com>
> CC: Thomas Gleixner <tglx@...utronix.de>
> CC: Borislav Petkov <bp@...en8.de>
> CC: Dave Hansen <dave.hansen@...ux.intel.com>
> CC: x86@...nel.org
> CC: "H. Peter Anvin" <hpa@...or.com>
> CC: linux-perf-users@...r.kernel.org
> Signed-off-by: Li Zhijian <lizhijian@...itsu.com>

Reviewed-by: Adrian Hunter <adrian.hunter@...el.com>

> ---
> V2:
> - Address Adrian's comment:
>   leave "snprintf(page, next_str - str + 1, "%s", str)" alone, it
>   intends to print a sub-string, that cannot covert to sysfs_emit simply.
> -
> V2: extract patch from the patch set[1] so that maintainer accept it separately.
> [1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
> Signed-off-by: Li Zhijian <lizhijian@...itsu.com>
> ---
>  arch/x86/events/core.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> index 09050641ce5d..20d963196e4c 100644
> --- a/arch/x86/events/core.c
> +++ b/arch/x86/events/core.c
> @@ -1832,7 +1832,7 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, cha
>  
>  	/* string trumps id */
>  	if (pmu_attr->event_str)
> -		return sprintf(page, "%s\n", pmu_attr->event_str);
> +		return sysfs_emit(page, "%s\n", pmu_attr->event_str);
>  
>  	return x86_pmu.events_sysfs_show(page, config);
>  }
> @@ -1855,7 +1855,7 @@ ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
>  	 * if they are owned by some other guest.  The user tool
>  	 * has to re-read when a thread sibling gets onlined later.
>  	 */
> -	return sprintf(page, "%s",
> +	return sysfs_emit(page, "%s",
>  			topology_max_smt_threads() > 1 ?
>  			pmu_attr->event_str_ht :
>  			pmu_attr->event_str_noht);
> @@ -1872,7 +1872,7 @@ ssize_t events_hybrid_sysfs_show(struct device *dev,
>  	int i;
>  
>  	if (hweight64(pmu_attr->pmu_type) == 1)
> -		return sprintf(page, "%s", pmu_attr->event_str);
> +		return sysfs_emit(page, "%s", pmu_attr->event_str);
>  
>  	/*
>  	 * Hybrid PMUs may support the same event name, but with different
> @@ -1894,7 +1894,7 @@ ssize_t events_hybrid_sysfs_show(struct device *dev,
>  			if (next_str)
>  				return snprintf(page, next_str - str + 1, "%s", str);
>  			else
> -				return sprintf(page, "%s", str);
> +				return sysfs_emit(page, "%s", str);
>  		}
>  		str = strchr(str, ';');
>  		str++;
> @@ -2539,7 +2539,7 @@ static ssize_t get_attr_rdpmc(struct device *cdev,
>  			      struct device_attribute *attr,
>  			      char *buf)
>  {
> -	return snprintf(buf, 40, "%d\n", x86_pmu.attr_rdpmc);
> +	return sysfs_emit(buf, "%d\n", x86_pmu.attr_rdpmc);
>  }
>  
>  static ssize_t set_attr_rdpmc(struct device *cdev,
> @@ -2597,7 +2597,7 @@ static ssize_t max_precise_show(struct device *cdev,
>  				  struct device_attribute *attr,
>  				  char *buf)
>  {
> -	return snprintf(buf, PAGE_SIZE, "%d\n", x86_pmu_max_precise());
> +	return sysfs_emit(buf, "%d\n", x86_pmu_max_precise());
>  }
>  
>  static DEVICE_ATTR_RO(max_precise);


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ