Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: use sysfs_emit in sysfs show functions

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>

authored by

Thorsten Blum and committed by
Jens Axboe
a175ee82 4e56428e

+6 -5
+6 -5
block/partitions/core.c
··· 8 8 #include <linux/major.h> 9 9 #include <linux/slab.h> 10 10 #include <linux/string.h> 11 + #include <linux/sysfs.h> 11 12 #include <linux/ctype.h> 12 13 #include <linux/vmalloc.h> 13 14 #include <linux/raid/detect.h> ··· 178 177 static ssize_t part_partition_show(struct device *dev, 179 178 struct device_attribute *attr, char *buf) 180 179 { 181 - return sprintf(buf, "%d\n", bdev_partno(dev_to_bdev(dev))); 180 + return sysfs_emit(buf, "%d\n", bdev_partno(dev_to_bdev(dev))); 182 181 } 183 182 184 183 static ssize_t part_start_show(struct device *dev, 185 184 struct device_attribute *attr, char *buf) 186 185 { 187 - return sprintf(buf, "%llu\n", dev_to_bdev(dev)->bd_start_sect); 186 + return sysfs_emit(buf, "%llu\n", dev_to_bdev(dev)->bd_start_sect); 188 187 } 189 188 190 189 static ssize_t part_ro_show(struct device *dev, 191 190 struct device_attribute *attr, char *buf) 192 191 { 193 - return sprintf(buf, "%d\n", bdev_read_only(dev_to_bdev(dev))); 192 + return sysfs_emit(buf, "%d\n", bdev_read_only(dev_to_bdev(dev))); 194 193 } 195 194 196 195 static ssize_t part_alignment_offset_show(struct device *dev, 197 196 struct device_attribute *attr, char *buf) 198 197 { 199 - return sprintf(buf, "%u\n", bdev_alignment_offset(dev_to_bdev(dev))); 198 + return sysfs_emit(buf, "%u\n", bdev_alignment_offset(dev_to_bdev(dev))); 200 199 } 201 200 202 201 static ssize_t part_discard_alignment_show(struct device *dev, 203 202 struct device_attribute *attr, char *buf) 204 203 { 205 - return sprintf(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev))); 204 + return sysfs_emit(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev))); 206 205 } 207 206 208 207 static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);