]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ACPI: fan: Replace sprintf()/scnprintf() with sysfs_emit() in show() functions
authorAbdelrahman Fekry <abdelrahmanfekry375@gmail.com>
Sat, 21 Jun 2025 05:52:00 +0000 (08:52 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 2 Jul 2025 17:57:28 +0000 (19:57 +0200)
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>
Link: https://patch.msgid.link/20250621055200.166361-1-abdelrahmanfekry375@gmail.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/fan_attr.c

index 22d29ac2447cc28d5c7bf30e02f4d7ce533f0017..6a53da3d6d826a7999c72395a585e3b32f5e5d96 100644 (file)
@@ -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)