Skip to contentSkip to conversation

zorro: sysfs: replace sprintf with sysfs_emit

PATCH In review Stefan Pedratscher 3 participants 3 messages Apr 6 – Apr 27 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zorro: sysfs: replace sprintf with sysfs_emit

Convert sysfs show functions from sprintf to sysfs_emit as recommended by Documentation/filesystems/sysfs.rst. This ensures proper buffer handling and avoids potential buffer overflows.

---
 drivers/zorro/zorro-sysfs.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/zorro/zorro-sysfs.c +8 -7
index 4e967754d8ad..f9a9bcb59e62 100644
@@ -15,6 +15,7 @@
 #include <linux/zorro.h>
 #include <linux/stat.h>
 #include <linux/string.h>
+#include <linux/sysfs.h>
 
 #include <asm/byteorder.h>
 
@@ -29,7 +30,7 @@ static ssize_t name##_show(struct device *dev,				\
 	struct zorro_dev *z;						\
 									\
 	z = to_zorro_dev(dev);						\
-	return sprintf(buf, format_string, z->field);			\
+	return sysfs_emit(buf, format_string, z->field);		\
 }									\
 static DEVICE_ATTR_RO(name);
 
@@ -44,7 +45,7 @@ static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
 	struct zorro_dev *z;
 
 	z = to_zorro_dev(dev);
-	return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
+	return sysfs_emit(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
 }
 static DEVICE_ATTR_RO(serial);
 
@@ -53,10 +54,10 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
 {
 	struct zorro_dev *z = to_zorro_dev(dev);
 
-	return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
-		       (unsigned long)zorro_resource_start(z),
-		       (unsigned long)zorro_resource_end(z),
-		       zorro_resource_flags(z));
+	return sysfs_emit(buf, "0x%08lx 0x%08lx 0x%08lx\n",
+			(unsigned long)zorro_resource_start(z),
+			(unsigned long)zorro_resource_end(z),
+			zorro_resource_flags(z));
 }
 static DEVICE_ATTR_RO(resource);
 
@@ -65,7 +66,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
 {
 	struct zorro_dev *z = to_zorro_dev(dev);
 
-	return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
+	return sysfs_emit(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
 }
 static DEVICE_ATTR_RO(modalias);
 
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw

Hi Stefan,

Quoted 4 lines · Stefan Pedratscher

Convert sysfs show functions from sprintf to sysfs_emit as recommended by Documentation/filesystems/sysfs.rst. This ensures proper buffer handling and avoids potential buffer overflows.

Build, boot and poked around in /sys/bus/zorro tested on my Amiga 4000. Amiga is still in one piece so:

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Stefan Pedratscher

Hi Stefan,

Quoted 5 lines · Stefan Pedratscher

Convert sysfs show functions from sprintf to sysfs_emit as recommended by Documentation/filesystems/sysfs.rst. This ensures proper buffer handling and avoids potential buffer overflows.

Thanks for your patch!

Quoted 4 lines
drivers/zorro/zorro-sysfs.c +0 -0
@@ -53,10 +54,10 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
 {

drivers/zorro/zorro-sysfs.c static ssize_t resource_show(struct device *dev, struct device_attribute *attr, · line 60

Quoted 10 lines
drivers/zorro/zorro-sysfs.c +4 -4
        struct zorro_dev *z = to_zorro_dev(dev);
 
-       return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
-                      (unsigned long)zorro_resource_start(z),
-                      (unsigned long)zorro_resource_end(z),
-                      zorro_resource_flags(z));
+       return sysfs_emit(buf, "0x%08lx 0x%08lx 0x%08lx\n",
+                       (unsigned long)zorro_resource_start(z),
+                       (unsigned long)zorro_resource_end(z),
+                       zorro_resource_flags(z));

Wrong indentation.

drivers/zorro/zorro-sysfs.c static ssize_t resource_show(struct device *dev, struct device_attribute *attr, · line 63

Quoted 3 lines
drivers/zorro/zorro-sysfs.c +0 -0
 }
 static DEVICE_ATTR_RO(resource);
 

The rest LGTM, so

i.e. will queue in the m68k tree for v7.2, with the above fixed.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds