[PATCH 05/42] arch/x86/events/intel: Convert snprintf to sysfs_emit
From: Li Zhijian
Date: Mon Jan 15 2024 - 23:54:19 EST
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/intel/core.c:5496:8-16: WARNING: please use sysfs_emit
> ./arch/x86/events/intel/core.c:5530:8-16: WARNING: please use sysfs_emit
> ./arch/x86/events/intel/core.c:5546:8-16: WARNING: please use sysfs_emit
> ./arch/x86/events/intel/pt.c:99:8-16: WARNING: please use sysfs_emit
No functional change intended
CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
CC: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CC: Mark Rutland <mark.rutland@xxxxxxx>
CC: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
CC: Jiri Olsa <jolsa@xxxxxxxxxx>
CC: Namhyung Kim <namhyung@xxxxxxxxxx>
CC: Ian Rogers <irogers@xxxxxxxxxx>
CC: Adrian Hunter <adrian.hunter@xxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Borislav Petkov <bp@xxxxxxxxx>
CC: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
CC: x86@xxxxxxxxxx
CC: "H. Peter Anvin" <hpa@xxxxxxxxx>
CC: linux-perf-users@xxxxxxxxxxxxxxx
Signed-off-by: Li Zhijian <lizhijian@xxxxxxxxxxx>
---
arch/x86/events/intel/core.c | 6 +++---
arch/x86/events/intel/pt.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 0f2786d4e405..aa5fa64a923b 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5493,7 +5493,7 @@ static ssize_t show_sysctl_tfa(struct device *cdev,
struct device_attribute *attr,
char *buf)
{
- return snprintf(buf, 40, "%d\n", allow_tsx_force_abort);
+ return sysfs_emit(buf, "%d\n", allow_tsx_force_abort);
}
static ssize_t set_sysctl_tfa(struct device *cdev,
@@ -5527,7 +5527,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);
@@ -5543,7 +5543,7 @@ static ssize_t pmu_name_show(struct device *cdev,
struct device_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str);
+ return sysfs_emit(buf, "%s\n", pmu_name_str);
}
static DEVICE_ATTR_RO(pmu_name);
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 8e2a12235e62..30bba5f3a840 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -96,7 +96,7 @@ static ssize_t pt_cap_show(struct device *cdev,
container_of(attr, struct dev_ext_attribute, attr);
enum pt_capabilities cap = (long)ea->var;
- return snprintf(buf, PAGE_SIZE, "%x\n", intel_pt_validate_hw_cap(cap));
+ return sysfs_emit(buf, "%x\n", intel_pt_validate_hw_cap(cap));
}
static struct attribute_group pt_cap_group __ro_after_init = {
--
2.29.2