Skip to contentSkip to conversation

sparc: use snprintf() in show() methods

PATCH In review Chen Zhou 3 participants 7 messages May 9, 2020 – May 13, 2020 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore

Chen Zhou

author
#0 lore raw

cover sparc: use snprintf() in show() methods

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

show() methods should return the number of bytes printed into the buffer. This is the return value of scnprintf().

Chen Zhou (2):
sparc: use snprintf() in show_pciobppath_attr() in pci.c
sparc: use snprintf() in show_pciobppath_attr() in vio.c

 arch/sparc/kernel/pci.c | 2 +-
 arch/sparc/kernel/vio.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/2 sparc: use snprintf() in show_pciobppath_attr() in pci.c

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

show_pciobppath_attr() should return the number of bytes printed into the buffer. This is the return value of scnprintf().

---
 arch/sparc/kernel/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/pci.c +1 -1
index 5ed43828e078..a41ad562ed4e 100644
@@ -593,7 +593,7 @@ show_pciobppath_attr(struct device * dev, struct device_attribute * attr, char *
 	pdev = to_pci_dev(dev);
 	dp = pdev->dev.of_node;
 
-	return snprintf (buf, PAGE_SIZE, "%pOF\n", dp);
+	return scnprintf(buf, PAGE_SIZE, "%pOF\n", dp);
 }
 
 static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_pciobppath_attr, NULL);
Signature · 1 line
2.20.1
author
#2 lore raw

PATCH 2/2 sparc: use snprintf() in show_pciobppath_attr() in vio.c

In reply to Chen Zhou

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

show_pciobppath_attr() should return the number of bytes printed into the buffer. This is the return value of scnprintf().

---
 arch/sparc/kernel/vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/vio.c +1 -1
index c7cad9b7bba7..4f57056ed463 100644
@@ -193,7 +193,7 @@ show_pciobppath_attr(struct device *dev, struct device_attribute *attr,
 	vdev = to_vio_dev(dev);
 	dp = vdev->dp;
 
-	return snprintf (buf, PAGE_SIZE, "%pOF\n", dp);
+	return scnprintf(buf, PAGE_SIZE, "%pOF\n", dp);
 }
 
 static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH,
Signature · 1 line
2.20.1
#3 lore raw
In reply to Chen Zhou
Quoted 2 lines · Chen Zhou

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

[]

Quoted 3 lines

Chen Zhou (2):
sparc: use snprintf() in show_pciobppath_attr() in pci.c
sparc: use snprintf() in show_pciobppath_attr() in vio.c

Your subjects are a bit off: snprintf vs scnprintf

author
#4 lore raw

Sorry, i made a mistake, should be scnprintf().

Quoted 12 lines · Joe Perches
Quoted 2 lines · Chen Zhou

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

[]

Quoted 3 lines

Chen Zhou (2):
sparc: use snprintf() in show_pciobppath_attr() in pci.c
sparc: use snprintf() in show_pciobppath_attr() in vio.c

Your subjects are a bit off: snprintf vs scnprintf

#5 lore raw
Quoted 1 line · chenzhou

Sorry, i made a mistake, should be scnprintf().

No worries.

But why do you think this is useful?
Is it likely that either snprint length will exceed PAGE_SIZE?

Quoted 16 lines · Joe Perches
Quoted 12 lines · Chen Zhou
Quoted 2 lines

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

[]

Quoted 3 lines

Chen Zhou (2):
sparc: use snprintf() in show_pciobppath_attr() in pci.c
sparc: use snprintf() in show_pciobppath_attr() in vio.c

Your subjects are a bit off: snprintf vs scnprintf

maintainer
#6 lore raw
In reply to Chen Zhou

From: Chen Zhou <[email protected]>
Date: Sat, 9 May 2020 17:18:47 +0800

Quoted 5 lines

snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.

show() methods should return the number of bytes printed into the buffer. This is the return value of scnprintf().

Series applied with Subject lines corrected.