public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] arch/x86/events/amd: Convert snprintf/sprintf to sysfs_emit
@ 2024-01-26  6:13 Li Zhijian
  2024-01-26  6:13 ` [PATCH v2 2/4] arch/x86/events/core: Convert sprintf/snprintf " Li Zhijian
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Li Zhijian @ 2024-01-26  6:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: Li Zhijian, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Thomas Gleixner, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin

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/amd/core.c:1282:8-16: WARNING: please use sysfs_emit

This patch is generated by
$ make coccicheck MODE=patch COCCI=scripts/coccinelle/api/device_attr_show.cocci M=arch/x86/events/amd | 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>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
V2: extract patch from the patch set[1] so that maintainer can accept it separately.
[1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 arch/x86/events/amd/core.c  | 2 +-
 arch/x86/events/amd/iommu.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 81f6d8275b6b..0d520592010c 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -1279,7 +1279,7 @@ static ssize_t branches_show(struct device *cdev,
 			      struct device_attribute *attr,
 			      char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", x86_pmu.lbr_nr);
+	return sysfs_emit(buf, "%d\n", x86_pmu.lbr_nr);
 }
 
 static DEVICE_ATTR_RO(branches);
diff --git a/arch/x86/events/amd/iommu.c b/arch/x86/events/amd/iommu.c
index b15f7b950d2e..1126bda96d8f 100644
--- a/arch/x86/events/amd/iommu.c
+++ b/arch/x86/events/amd/iommu.c
@@ -89,7 +89,7 @@ static ssize_t _iommu_event_show(struct device *dev,
 {
 	struct amd_iommu_event_desc *event =
 		container_of(attr, struct amd_iommu_event_desc, attr);
-	return sprintf(buf, "%s\n", event->event);
+	return sysfs_emit(buf, "%s\n", event->event);
 }
 
 #define AMD_IOMMU_EVENT_DESC(_name, _event)			\
-- 
2.29.2


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

end of thread, other threads:[~2024-02-07  8:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-26  6:13 [PATCH v2 1/4] arch/x86/events/amd: Convert snprintf/sprintf to sysfs_emit Li Zhijian
2024-01-26  6:13 ` [PATCH v2 2/4] arch/x86/events/core: Convert sprintf/snprintf " Li Zhijian
2024-02-07  8:10   ` Adrian Hunter
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
2024-02-07  8:10 ` [PATCH v2 1/4] arch/x86/events/amd: " Adrian Hunter

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