Skip to contentSkip to conversation

x86: events: Convert snprintf() to scnprintf()

PATCH Superseded Jules Irenge 1 participant 1 message Sep 26, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 4/7 x86: events: Convert snprintf() to scnprintf()

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length.

---
 arch/x86/events/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/core.c +3 -3
index f969410d0c90..71695d21ffd1 100644
@@ -1905,7 +1905,7 @@ ssize_t events_hybrid_sysfs_show(struct device *dev,
 		if (x86_pmu.hybrid_pmu[i].cpu_type & pmu->cpu_type) {
 			next_str = strchr(str, ';');
 			if (next_str)
-				return snprintf(page, next_str - str + 1, "%s", str);
+				return scnprintf(page, next_str - str + 1, "%s", str);
 			else
 				return sprintf(page, "%s", str);
 		}
@@ -2566,7 +2566,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 scnprintf(buf, 40, "%d\n", x86_pmu.attr_rdpmc);
 }
 
 static ssize_t set_attr_rdpmc(struct device *cdev,
@@ -2624,7 +2624,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 scnprintf(buf, PAGE_SIZE, "%d\n", x86_pmu_max_precise());
 }
 
 static DEVICE_ATTR_RO(max_precise);
Signature · 1 line
2.37.3