[PATCH] perf/x86/intel: replace scnprintf in show functions with sysfs_emit

From: cgel . zte
Date: Tue Nov 16 2021 - 06:39:46 EST


From: Changcheng Deng <deng.changcheng@xxxxxxxxxx>

Fix the coccicheck warning:
WARNING: use scnprintf or sprintf

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: Changcheng Deng <deng.changcheng@xxxxxxxxxx>
---
arch/x86/events/intel/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 4d679b2d6024..ad87a48bfb41 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5115,7 +5115,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,
@@ -5149,7 +5149,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);
@@ -5165,7 +5165,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);
--
2.25.1