]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dm: sysfs: use sysfs_emit() in dm-sysfs.c
authorVivek BalachandharTN <vivek.balachandhar@gmail.com>
Wed, 15 Oct 2025 07:45:02 +0000 (07:45 +0000)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 20 Oct 2025 13:22:21 +0000 (15:22 +0200)
Replace sprintf()+strlen() with sysfs_emit(), the preferred helper for
sysfs show() routines. sysfs_emit() returns the number of bytes written,
guarantees NUL-termination, and clamps to PAGE_SIZE-1.

Reference: Documentation/filesystems/sysfs.rst.

No functional change intended.

Signed-off-by: Vivek BalachandharTN <vivek.balachandhar@gmail.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-sysfs.c

index bfaef27ca79f4ad85d65a54450ddf321aba832ff..22bc70923a839255ebdc21c627e9e695e19c849e 100644 (file)
@@ -86,17 +86,13 @@ static ssize_t dm_attr_uuid_show(struct mapped_device *md, char *buf)
 
 static ssize_t dm_attr_suspended_show(struct mapped_device *md, char *buf)
 {
-       sprintf(buf, "%d\n", dm_suspended_md(md));
-
-       return strlen(buf);
+       return sysfs_emit(buf, "%d\n", dm_suspended_md(md));
 }
 
 static ssize_t dm_attr_use_blk_mq_show(struct mapped_device *md, char *buf)
 {
        /* Purely for userspace compatibility */
-       sprintf(buf, "%d\n", true);
-
-       return strlen(buf);
+       return sysfs_emit(buf, "%d\n", true);
 }
 
 static DM_ATTR_RO(name);