* [PATCH] ACPI: fan: Replace sprintf/scnprintf with sysfs_emit in show functions
@ 2025-06-21 5:52 Abdelrahman Fekry
2025-07-02 17:58 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Abdelrahman Fekry @ 2025-06-21 5:52 UTC (permalink / raw)
To: rafael, lenb
Cc: skhan, linux-acpi, linux-kernel, linux-kernel-mentees,
Abdelrahman Fekry
Update two sysfs show() functions in the ACPI fan driver to use sysfs_emit()
and sysfs_emit_at() instead of sprintf() and scnprintf().
- show_fan_speed(): replaced sprintf() with sysfs_emit().
- show_state(): replaced scnprintf() with sysfs_emit() for the first write,
and retained sysfs_emit_at() for incremental writes.
This change is in accordance with Documentation/filesystems/sysfs.rst,
which recommends using sysfs_emit/sysfs_emit_at in all sysfs show()
callbacks for buffer safety, clarity, and consistency.
Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
---
drivers/acpi/fan_attr.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/fan_attr.c b/drivers/acpi/fan_attr.c
index 22d29ac2447c..6a53da3d6d82 100644
--- a/drivers/acpi/fan_attr.c
+++ b/drivers/acpi/fan_attr.c
@@ -22,9 +22,9 @@ static ssize_t show_state(struct device *dev, struct device_attribute *attr, cha
int count;
if (fps->control == 0xFFFFFFFF || fps->control > 100)
- count = scnprintf(buf, PAGE_SIZE, "not-defined:");
+ count = sysfs_emit(buf, "not-defined:");
else
- count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
+ count = sysfs_emit(buf, "%lld:", fps->control);
if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
count += sysfs_emit_at(buf, count, "not-defined:");
@@ -59,7 +59,7 @@ static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr,
if (status)
return status;
- return sprintf(buf, "%lld\n", fst.speed);
+ return sysfs_emit(buf, "%lld\n", fst.speed);
}
static ssize_t show_fine_grain_control(struct device *dev, struct device_attribute *attr, char *buf)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ACPI: fan: Replace sprintf/scnprintf with sysfs_emit in show functions
2025-06-21 5:52 [PATCH] ACPI: fan: Replace sprintf/scnprintf with sysfs_emit in show functions Abdelrahman Fekry
@ 2025-07-02 17:58 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-07-02 17:58 UTC (permalink / raw)
To: Abdelrahman Fekry
Cc: rafael, lenb, skhan, linux-acpi, linux-kernel,
linux-kernel-mentees
On Sat, Jun 21, 2025 at 7:52 AM Abdelrahman Fekry
<abdelrahmanfekry375@gmail.com> wrote:
>
> Update two sysfs show() functions in the ACPI fan driver to use sysfs_emit()
> and sysfs_emit_at() instead of sprintf() and scnprintf().
>
> - show_fan_speed(): replaced sprintf() with sysfs_emit().
> - show_state(): replaced scnprintf() with sysfs_emit() for the first write,
> and retained sysfs_emit_at() for incremental writes.
>
> This change is in accordance with Documentation/filesystems/sysfs.rst,
> which recommends using sysfs_emit/sysfs_emit_at in all sysfs show()
> callbacks for buffer safety, clarity, and consistency.
>
> Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
> ---
> drivers/acpi/fan_attr.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/fan_attr.c b/drivers/acpi/fan_attr.c
> index 22d29ac2447c..6a53da3d6d82 100644
> --- a/drivers/acpi/fan_attr.c
> +++ b/drivers/acpi/fan_attr.c
> @@ -22,9 +22,9 @@ static ssize_t show_state(struct device *dev, struct device_attribute *attr, cha
> int count;
>
> if (fps->control == 0xFFFFFFFF || fps->control > 100)
> - count = scnprintf(buf, PAGE_SIZE, "not-defined:");
> + count = sysfs_emit(buf, "not-defined:");
> else
> - count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
> + count = sysfs_emit(buf, "%lld:", fps->control);
>
> if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
> count += sysfs_emit_at(buf, count, "not-defined:");
> @@ -59,7 +59,7 @@ static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr,
> if (status)
> return status;
>
> - return sprintf(buf, "%lld\n", fst.speed);
> + return sysfs_emit(buf, "%lld\n", fst.speed);
> }
>
> static ssize_t show_fine_grain_control(struct device *dev, struct device_attribute *attr, char *buf)
> --
Applied as 6.17 material, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-02 17:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-21 5:52 [PATCH] ACPI: fan: Replace sprintf/scnprintf with sysfs_emit in show functions Abdelrahman Fekry
2025-07-02 17:58 ` 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