]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
block: use sysfs_emit in sysfs show functions
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 2 Apr 2026 16:50:00 +0000 (18:50 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 3 Apr 2026 11:07:46 +0000 (05:07 -0600)
Replace sprintf() with sysfs_emit() in sysfs show functions.
sysfs_emit() is preferred for formatting sysfs output because it
provides safer bounds checking.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://patch.msgid.link/20260402164958.894879-4-thorsten.blum@linux.dev
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/partitions/core.c

index 3b5928836c6980a614f8869f4aa24bb66c5c2d7d..5d5332ce586b6b292325e7dc02dca7e41f7ef6bc 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/major.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/sysfs.h>
 #include <linux/ctype.h>
 #include <linux/vmalloc.h>
 #include <linux/raid/detect.h>
@@ -177,31 +178,31 @@ static struct parsed_partitions *check_partition(struct gendisk *hd)
 static ssize_t part_partition_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", bdev_partno(dev_to_bdev(dev)));
+       return sysfs_emit(buf, "%d\n", bdev_partno(dev_to_bdev(dev)));
 }
 
 static ssize_t part_start_show(struct device *dev,
                               struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%llu\n", dev_to_bdev(dev)->bd_start_sect);
+       return sysfs_emit(buf, "%llu\n", dev_to_bdev(dev)->bd_start_sect);
 }
 
 static ssize_t part_ro_show(struct device *dev,
                            struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", bdev_read_only(dev_to_bdev(dev)));
+       return sysfs_emit(buf, "%d\n", bdev_read_only(dev_to_bdev(dev)));
 }
 
 static ssize_t part_alignment_offset_show(struct device *dev,
                                          struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%u\n", bdev_alignment_offset(dev_to_bdev(dev)));
+       return sysfs_emit(buf, "%u\n", bdev_alignment_offset(dev_to_bdev(dev)));
 }
 
 static ssize_t part_discard_alignment_show(struct device *dev,
                                           struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev)));
+       return sysfs_emit(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev)));
 }
 
 static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);