linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sukrut Heroorkar <hsukrut3@gmail.com>
To: rafel@kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
	Sukrut Heroorkar <hsukrut3@gmail.com>
Subject: [PATCH] ACPI: TAD: Replace sprintf with sysfs_emit
Date: Wed, 16 Jul 2025 14:35:43 +0200	[thread overview]
Message-ID: <20250716123543.495628-1-hsukrut3@gmail.com> (raw)

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


             reply	other threads:[~2025-07-16 12:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-16 12:35 Sukrut Heroorkar [this message]
2025-07-16 19:15 ` [PATCH] ACPI: TAD: Replace sprintf with sysfs_emit Rafael J. Wysocki

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=20250716123543.495628-1-hsukrut3@gmail.com \
    --to=hsukrut3@gmail.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafel@kernel.org \
    --cc=skhan@linuxfoundation.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;
as well as URLs for NNTP newsgroup(s).