ACPI: TAD: Replace sprintf() with sysfs_emit()

Replace sprintf() in *_show() callbacks of sysfs attributes with
sysfs_emit().

While the current implementation works, sysfs_emit() helps to 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>
Link: https://patch.msgid.link/20250716123543.495628-1-hsukrut3@gmail.com
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Sukrut Heroorkar 2025-07-16 14:35:43 +02:00 committed by Rafael J. Wysocki
parent 347e9f5043
commit cf115ebad3

View file

@ -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);