From: Jonathan Velez <jonvelez12345@gmail.com>
To: dlemoal@kernel.org, cassel@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
shuah@kernel.org, Jonathan Velez <jonvelez12345@gmail.com>
Subject: [PATCH] ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes
Date: Wed, 9 Jul 2025 13:33:30 +0000 [thread overview]
Message-ID: <20250709133330.3546-1-jonvelez12345@gmail.com> (raw)
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
next reply other threads:[~2025-07-09 13:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 13:33 Jonathan Velez [this message]
2025-07-09 13:47 ` Niklas Cassel
2025-07-09 13:49 ` Niklas Cassel
-- strict thread matches above, loose matches on Subject: below --
2025-07-07 12:20 Jonathan Velez
2025-07-08 1:15 ` Damien Le Moal
2025-07-09 13:16 ` Jonathan Velez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250709133330.3546-1-jonvelez12345@gmail.com \
--to=jonvelez12345@gmail.com \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®