Skip to contentSkip to conversation

perf/x86/amd:Convert snprintf() to sysfs_emit()

PATCH In review Jules Irenge 1 participant 1 message Nov 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 perf/x86/amd:Convert snprintf() to sysfs_emit()

Coccinelle reports a warning
WARNING: use scnprintf or sprintf

Following the advice on kernel documentation
https://www.kernel.org/doc/html/latest/filesystems/sysfs.html

For show(device *...) functions, only use sysfs_emit() or sysfs_emit_at() especially when formatting the value to be returned to user space. Convert snprintf() to sysfs_emit()

---
 arch/x86/events/amd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/amd/core.c +1 -1
index e24976593a29..f2fef75d464c 100644
@@ -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);
Signature · 1 line
2.41.0