Skip to contentSkip to conversation

ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes

PATCH In review Jonathan Velez 2 participants 3 messages Jul 7, 2025 – Jul 9, 2025 libata

lore
Share & tools
lore
#0 lore raw

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, scnprintf() was converted to sysfs_emit(). This aligns with the sysfs guidance provided in Documentation/filesystems/sysfs.rst.

---
 drivers/ata/libata-transport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ata/libata-transport.c +2 -2
index e898be49df6b..62415fe67a11 100644
@@ -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
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jonathan Velez

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, scnprintf() was converted to sysfs_emit(). This aligns with the sysfs guidance provided in Documentation/filesystems/sysfs.rst.

Nit: please use assertive style (no past tense/passive form)

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

Quoted 2 lines

Otherwise, looks good.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#2 lore raw
Quoted 9 lines · Damien Le Moal
Quoted 4 lines · Jonathan Velez

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.

Quoted 8 lines
Quoted 3 lines

To avoid output defects with the ATA transport class simple attributes, scnprintf() was converted to sysfs_emit(). This aligns with the sysfs guidance provided in Documentation/filesystems/sysfs.rst.

Nit: please use assertive style (no past tense/passive form)

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

I will amend the commit message and submit V2 of the patch.

Quoted 7 lines
Quoted 3 lines

Otherwise, looks good.

Thank you, I’m considering reviewing the rest of the libata-transport.c module for similar updates. Thoughts?

Quoted 3 lines
Signature · 2 lines
Damien Le Moal
Western Digital Research