* [PATCH] ACPI: TAD: Replace sprintf with sysfs_emit
@ 2025-07-16 12:35 Sukrut Heroorkar
2025-07-16 19:15 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Sukrut Heroorkar @ 2025-07-16 12:35 UTC (permalink / raw)
To: rafel, linux-acpi, linux-kernel
Cc: skhan, david.hunter.linux, Sukrut Heroorkar
Replace use of sprintf in *_show attributes with sysfs_emit for writing
to sysfs. While the current implementation works, sysfs_emit helps prevent
potential buffer overflows and aligns with kernel documentation
Documentation/filesystems/sysfs.rst.
Tested on an x86_64 system with acpi_tad built as a module:
- Inserted patched acpi_tad.ko successfully
- Verified /sys/devices/platform/ACPI000E:00/time and /caps are accessible
- Confirmed correct output from 'cat' with no dmesg errors
Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
---
drivers/acpi/acpi_tad.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c
index 825c2a8acea4..91d7d90c47da 100644
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -233,7 +233,7 @@ static ssize_t time_show(struct device *dev, struct device_attribute *attr,
if (ret)
return ret;
- return sprintf(buf, "%u:%u:%u:%u:%u:%u:%d:%u\n",
+ return sysfs_emit(buf, "%u:%u:%u:%u:%u:%u:%d:%u\n",
rt.year, rt.month, rt.day, rt.hour, rt.minute, rt.second,
rt.tz, rt.daylight);
}
@@ -428,7 +428,7 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
{
struct acpi_tad_driver_data *dd = dev_get_drvdata(dev);
- return sprintf(buf, "0x%02X\n", dd->capabilities);
+ return sysfs_emit(buf, "0x%02X\n", dd->capabilities);
}
static DEVICE_ATTR_RO(caps);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ACPI: TAD: Replace sprintf with sysfs_emit
2025-07-16 12:35 [PATCH] ACPI: TAD: Replace sprintf with sysfs_emit Sukrut Heroorkar
@ 2025-07-16 19:15 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-07-16 19:15 UTC (permalink / raw)
To: Sukrut Heroorkar
Cc: rafel, linux-acpi, linux-kernel, skhan, david.hunter.linux
On Wed, Jul 16, 2025 at 2:36 PM Sukrut Heroorkar <hsukrut3@gmail.com> wrote:
>
> Replace use of sprintf in *_show attributes with sysfs_emit for writing
> to sysfs. While the current implementation works, sysfs_emit helps prevent
> potential buffer overflows and aligns with kernel documentation
> Documentation/filesystems/sysfs.rst.
>
> Tested on an x86_64 system with acpi_tad built as a module:
> - Inserted patched acpi_tad.ko successfully
> - Verified /sys/devices/platform/ACPI000E:00/time and /caps are accessible
> - Confirmed correct output from 'cat' with no dmesg errors
>
> Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
> ---
> drivers/acpi/acpi_tad.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c
> index 825c2a8acea4..91d7d90c47da 100644
> --- a/drivers/acpi/acpi_tad.c
> +++ b/drivers/acpi/acpi_tad.c
> @@ -233,7 +233,7 @@ static ssize_t time_show(struct device *dev, struct device_attribute *attr,
> if (ret)
> return ret;
>
> - return sprintf(buf, "%u:%u:%u:%u:%u:%u:%d:%u\n",
> + return sysfs_emit(buf, "%u:%u:%u:%u:%u:%u:%d:%u\n",
> rt.year, rt.month, rt.day, rt.hour, rt.minute, rt.second,
> rt.tz, rt.daylight);
> }
> @@ -428,7 +428,7 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
> {
> struct acpi_tad_driver_data *dd = dev_get_drvdata(dev);
>
> - return sprintf(buf, "0x%02X\n", dd->capabilities);
> + return sysfs_emit(buf, "0x%02X\n", dd->capabilities);
> }
>
> static DEVICE_ATTR_RO(caps);
> --
Applied as 6.17 material, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-16 19:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 12:35 [PATCH] ACPI: TAD: Replace sprintf with sysfs_emit Sukrut Heroorkar
2025-07-16 19:15 ` Rafael J. Wysocki
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).