Skip to contentSkip to conversation

x86: event, use scnprintf instead of snprintf

PATCH In review liuyang34 2 participants 2 messages Jan 9, 2020 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

liuyang34

author
#1 lore raw

PATCH 1/1 x86: event, use scnprintf instead of snprintf

In reply to a message not in the archive

the return size will low than PAGE_SIZE but maybe over 40 in show_sysctl_tfa, so use scnprintf instead of snprintf to get real size

---
 arch/x86/events/intel/core.c    | 6 +++---
 arch/x86/events/intel/pt.c      | 2 +-
 arch/x86/platform/uv/uv_sysfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/events/intel/core.c +3 -3
index 3be51aa..bf287b4 100644
@@ -4372,7 +4372,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 scnprintf(buf, 40, "%d\n", allow_tsx_force_abort);
 }
 
 static ssize_t set_sysctl_tfa(struct device *cdev,
@@ -4406,7 +4406,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 scnprintf(buf, PAGE_SIZE, "%d\n", x86_pmu.lbr_nr);
 }
 
 static DEVICE_ATTR_RO(branches);
@@ -4422,7 +4422,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 scnprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str);
 }
 
 static DEVICE_ATTR_RO(pmu_name);
arch/x86/events/intel/pt.c +1 -1
index 1db7a51..4ca7ed9 100644
@@ -92,7 +92,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 scnprintf(buf, PAGE_SIZE, "%x\n", intel_pt_validate_hw_cap(cap));
 }
 
 static struct attribute_group pt_cap_group __ro_after_init = {
arch/x86/platform/uv/uv_sysfs.c +2 -2
index 6221473..aa44c82 100644
@@ -15,13 +15,13 @@ struct kobject *sgi_uv_kobj;
 static ssize_t partition_id_show(struct kobject *kobj,
 			struct kobj_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%ld\n", sn_partition_id);
+	return scnprintf(buf, PAGE_SIZE, "%ld\n", sn_partition_id);
 }
 
 static ssize_t coherence_id_show(struct kobject *kobj,
 			struct kobj_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%ld\n", uv_partition_coherence_id());
+	return scnprintf(buf, PAGE_SIZE, "%ld\n", uv_partition_coherence_id());
 }
 
 static struct kobj_attribute partition_id_attr =
Signature · 1 line
2.7.4
#2 lore raw
Quoted 15 lines · On Thu, Jan 09, 2020 at 02:36:26PM +0800, liuyang34 wrote:

the return size will low than PAGE_SIZE but maybe over 40 in show_sysctl_tfa, so use scnprintf instead of snprintf to get real size

---
 arch/x86/events/intel/core.c    | 6 +++---
 arch/x86/events/intel/pt.c      | 2 +-
 arch/x86/platform/uv/uv_sysfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/events/intel/core.c +0 -0
index 3be51aa..bf287b4 100644

arch/x86/events/intel/core.c static ssize_t show_sysctl_tfa(struct device *cdev, · line 4375

Quoted 5 lines
arch/x86/events/intel/core.c +1 -1
@@ -4372,7 +4372,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 scnprintf(buf, 40, "%d\n", allow_tsx_force_abort);

No, just use sprintf() for all of these. We "know" the buffer size is big enough for a single number. There's no need for fancy checks for any sysfs file.

thanks,

greg k-h