ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
PATCH 1/1 ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
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 inDocumentation/filesystems/sysfs.rst.
--- drivers/ata/libata-transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ata/libata-transport.c +2 -2
@@ -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) \
Signature · 1 line
2.43.0
Niklas Cassel
maintainerHello Jonathan,
You forgot to use -v 2 to git format-patch (so that v2 is in the subject), and you forgot to add a changelog (changes since v1) after the '---'.
No need to resend, but until next time.
Thank you for your contribution.
Kind regards,
Niklas
Quoted 41 lines · Jonathan Velez
sprintf, snprintf, and scnprintf do not consider the
PAGE_SIZEmaximum of the temporary buffer used for outputting sysfs content and they may overrun thePAGE_SIZEbuffer length.To avoid output defects with the ATA transport class simple attributes, use
sysfs_emitinstead ofscnprintf().This aligns with the sysfs guidance provided in
Documentation/filesystems/sysfs.rst.Signed-off-by Jonathan Velez <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- drivers/ata/libata-transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/ata/libata-transport.c +2
-2@@ -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) \Signature · 1 line
2.43.0
Quoted 8 lines · Jonathan Velez
sprintf, snprintf, and scnprintf do not consider the
PAGE_SIZEmaximum of the temporary buffer used for outputting sysfs content and they may overrun thePAGE_SIZEbuffer length.To avoid output defects with the ATA transport class simple attributes, use
sysfs_emitinstead ofscnprintf().[...]
Applied to libata/linux.git (for-6.17), thanks!
[1/1] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
https://git.kernel.org/libata/linux/c/48925ba7
Kind regards,
Niklas