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

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 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>

authored by

Jonathan Velez and committed by
Niklas Cassel
48925ba7 c5fccfe9

+2 -2
+2 -2
drivers/ata/libata-transport.c
··· 202 202 { \ 203 203 struct ata_port *ap = transport_class_to_port(dev); \ 204 204 \ 205 - return scnprintf(buf, 20, format_string, cast ap->field); \ 205 + return sysfs_emit(buf, format_string, cast ap->field); \ 206 206 } 207 207 208 208 #define ata_port_simple_attr(field, name, format_string, type) \ ··· 389 389 { \ 390 390 struct ata_device *ata_dev = transport_class_to_dev(dev); \ 391 391 \ 392 - return scnprintf(buf, 20, format_string, cast ata_dev->field); \ 392 + return sysfs_emit(buf, format_string, cast ata_dev->field); \ 393 393 } 394 394 395 395 #define ata_dev_simple_attr(field, format_string, type) \