]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
authorJonathan Velez <jonvelez12345@gmail.com>
Wed, 9 Jul 2025 13:33:30 +0000 (13:33 +0000)
committerNiklas Cassel <cassel@kernel.org>
Wed, 9 Jul 2025 13:48:17 +0000 (15:48 +0200)
sprintf, snprintf, and scnprintf do not consider the PAGE_SIZE maximum
of the temporary buffer used for outputting sysfs content and they may
overrun the PAGE_SIZE buffer length.

To avoid output defects with the ATA transport class simple attributes,
use sysfs_emit instead of scnprintf().

This aligns with the sysfs guidance provided in
Documentation/filesystems/sysfs.rst.

Signed-off-by: Jonathan Velez <jonvelez12345@gmail.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://lore.kernel.org/r/20250709133330.3546-1-jonvelez12345@gmail.com
Signed-off-by: Niklas Cassel <cassel@kernel.org>
drivers/ata/libata-transport.c

index e898be49df6b54676b3989db33b846996bb40a26..62415fe67a11e77ca68e7d371e7425a567495417 100644 (file)
@@ -202,7 +202,7 @@ show_ata_port_##name(struct device *dev,                            \
 {                                                                      \
        struct ata_port *ap = transport_class_to_port(dev);             \
                                                                        \
-       return scnprintf(buf, 20, format_string, cast ap->field);       \
+       return sysfs_emit(buf, format_string, cast ap->field);          \
 }
 
 #define ata_port_simple_attr(field, name, format_string, type)         \
@@ -389,7 +389,7 @@ show_ata_dev_##field(struct device *dev,                            \
 {                                                                      \
        struct ata_device *ata_dev = transport_class_to_dev(dev);       \
                                                                        \
-       return scnprintf(buf, 20, format_string, cast ata_dev->field);  \
+       return sysfs_emit(buf, format_string, cast ata_dev->field);     \
 }
 
 #define ata_dev_simple_attr(field, format_string, type)                \