linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Li Zhijian <lizhijian@fujitsu.com>, linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 2/4] arch/x86/events/core: Convert sprintf/snprintf to sysfs_emit
Date: Wed, 7 Feb 2024 10:10:50 +0200	[thread overview]
Message-ID: <1b1a8514-e74f-439f-a3ab-ad19dda49c22@intel.com> (raw)
In-Reply-To: <20240126061319.245901-2-lizhijian@fujitsu.com>

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@infradead.org>
> CC: Ingo Molnar <mingo@redhat.com>
> CC: Arnaldo Carvalho de Melo <acme@kernel.org>
> CC: Mark Rutland <mark.rutland@arm.com>
> CC: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> CC: Jiri Olsa <jolsa@kernel.org>
> CC: Namhyung Kim <namhyung@kernel.org>
> CC: Ian Rogers <irogers@google.com>
> CC: Adrian Hunter <adrian.hunter@intel.com>
> CC: Thomas Gleixner <tglx@linutronix.de>
> CC: Borislav Petkov <bp@alien8.de>
> CC: Dave Hansen <dave.hansen@linux.intel.com>
> CC: x86@kernel.org
> CC: "H. Peter Anvin" <hpa@zytor.com>
> CC: linux-perf-users@vger.kernel.org
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.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@fujitsu.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);


  reply	other threads:[~2024-02-07  8:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240126061319.245901-1-lizhijian@fujitsu.com>
2024-01-26  6:13 ` [PATCH v2 2/4] arch/x86/events/core: Convert sprintf/snprintf to sysfs_emit Li Zhijian
2024-02-07  8:10   ` Adrian Hunter [this message]
2024-01-26  6:13 ` [PATCH v2 3/4] arch/x86/events/core: use scnprintf to print sub-string Li Zhijian
2024-02-07  8:11   ` Adrian Hunter
2024-01-26  6:13 ` [PATCH v2 4/4] arch/x86/events/intel: Convert snprintf/sprintf to sysfs_emit Li Zhijian
2024-02-07  8:12   ` Adrian Hunter

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=1b1a8514-e74f-439f-a3ab-ad19dda49c22@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=lizhijian@fujitsu.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).