* [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
@ 2025-07-07 12:20 Jonathan Velez
2025-07-08 1:15 ` Damien Le Moal
0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Velez @ 2025-07-07 12:20 UTC (permalink / raw)
To: dlemoal, cassel; +Cc: linux-ide, linux-kernel, shuah, 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.
Signed-off-by: Jonathan Velez <jonvelez12345@gmail.com>
---
drivers/ata/libata-transport.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index e898be49df6b..62415fe67a11 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -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) \
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
2025-07-07 12:20 [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes Jonathan Velez
@ 2025-07-08 1:15 ` Damien Le Moal
2025-07-09 13:16 ` Jonathan Velez
0 siblings, 1 reply; 6+ messages in thread
From: Damien Le Moal @ 2025-07-08 1:15 UTC (permalink / raw)
To: Jonathan Velez, cassel; +Cc: linux-ide, linux-kernel, shuah
On 7/7/25 9:20 PM, Jonathan Velez wrote:
> 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().
>
> Signed-off-by: Jonathan Velez <jonvelez12345@gmail.com>
Otherwise, looks good.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
2025-07-08 1:15 ` Damien Le Moal
@ 2025-07-09 13:16 ` Jonathan Velez
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Velez @ 2025-07-09 13:16 UTC (permalink / raw)
To: Damien Le Moal; +Cc: cassel, linux-ide, linux-kernel, shuah
> On Jul 7, 2025, at 9:15 PM, Damien Le Moal <dlemoal@kernel.org> wrote:
>
> On 7/7/25 9:20 PM, Jonathan Velez wrote:
>> 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().
I will amend the commit message and submit V2 of the patch.
>
>>
>> Signed-off-by: Jonathan Velez <jonvelez12345@gmail.com>
>
> Otherwise, looks good.
>
> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Thank you, I’m considering reviewing the rest of the libata-transport.c module for similar updates. Thoughts?
> --
> Damien Le Moal
> Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
@ 2025-07-09 13:33 Jonathan Velez
2025-07-09 13:47 ` Niklas Cassel
2025-07-09 13:49 ` Niklas Cassel
0 siblings, 2 replies; 6+ messages in thread
From: Jonathan Velez @ 2025-07-09 13:33 UTC (permalink / raw)
To: dlemoal, cassel; +Cc: linux-kernel, linux-ide, shuah, 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,
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>
---
drivers/ata/libata-transport.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index e898be49df6b..62415fe67a11 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -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) \
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
2025-07-09 13:33 Jonathan Velez
@ 2025-07-09 13:47 ` Niklas Cassel
2025-07-09 13:49 ` Niklas Cassel
1 sibling, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2025-07-09 13:47 UTC (permalink / raw)
To: Jonathan Velez; +Cc: dlemoal, linux-kernel, linux-ide, shuah
Hello 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
On Wed, Jul 09, 2025 at 01:33:30PM +0000, Jonathan Velez wrote:
> 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>
> ---
> drivers/ata/libata-transport.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
> index e898be49df6b..62415fe67a11 100644
> --- a/drivers/ata/libata-transport.c
> +++ b/drivers/ata/libata-transport.c
> @@ -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) \
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
2025-07-09 13:33 Jonathan Velez
2025-07-09 13:47 ` Niklas Cassel
@ 2025-07-09 13:49 ` Niklas Cassel
1 sibling, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2025-07-09 13:49 UTC (permalink / raw)
To: dlemoal, Jonathan Velez; +Cc: linux-kernel, linux-ide, shuah
On Wed, 09 Jul 2025 13:33:30 +0000, Jonathan Velez wrote:
> 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().
>
> [...]
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-09 13:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 12:20 [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes Jonathan Velez
2025-07-08 1:15 ` Damien Le Moal
2025-07-09 13:16 ` Jonathan Velez
-- strict thread matches above, loose matches on Subject: below --
2025-07-09 13:33 Jonathan Velez
2025-07-09 13:47 ` Niklas Cassel
2025-07-09 13:49 ` Niklas Cassel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).