platform/x86: thinkpad_acpi: Fix coccinelle warnings
authorYe Guojin <ye.guojin@zte.com.cn>
Mon, 18 Oct 2021 09:17:50 +0000 (09:17 +0000)
committerHans de Goede <hdegoede@redhat.com>
Tue, 19 Oct 2021 15:18:37 +0000 (17:18 +0200)
coccicheck complains about the use of snprintf() in sysfs show
functions:

WARNING  use scnprintf or sprintf

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Ye Guojin <ye.guojin@zte.com.cn>
Link: https://lore.kernel.org/r/20211018091750.858826-1-ye.guojin@zte.com.cn
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/x86/thinkpad_acpi.c

index 07b9710d500e67828de44c1d2fc1ba0d2f464f88..cd5c3a04dba3a7e6eeae02c12ee0176bff9c8678 100644 (file)
@@ -1275,7 +1275,7 @@ static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id,
                        return status;
        }
 
-       return snprintf(buf, PAGE_SIZE, "%d\n",
+       return sysfs_emit(buf, "%d\n",
                        (status == TPACPI_RFK_RADIO_ON) ? 1 : 0);
 }
 
@@ -1368,14 +1368,14 @@ static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf)
 /* interface_version --------------------------------------------------- */
 static ssize_t interface_version_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
+       return sysfs_emit(buf, "0x%08x\n", TPACPI_SYSFS_VERSION);
 }
 static DRIVER_ATTR_RO(interface_version);
 
 /* debug_level --------------------------------------------------------- */
 static ssize_t debug_level_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
+       return sysfs_emit(buf, "0x%04x\n", dbg_level);
 }
 
 static ssize_t debug_level_store(struct device_driver *drv, const char *buf,
@@ -1395,7 +1395,7 @@ static DRIVER_ATTR_RW(debug_level);
 /* version ------------------------------------------------------------- */
 static ssize_t version_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%s v%s\n",
+       return sysfs_emit(buf, "%s v%s\n",
                        TPACPI_DESC, TPACPI_VERSION);
 }
 static DRIVER_ATTR_RO(version);
@@ -1407,7 +1407,7 @@ static DRIVER_ATTR_RO(version);
 /* wlsw_emulstate ------------------------------------------------------ */
 static ssize_t wlsw_emulstate_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate);
+       return sysfs_emit(buf, "%d\n", !!tpacpi_wlsw_emulstate);
 }
 
 static ssize_t wlsw_emulstate_store(struct device_driver *drv, const char *buf,
@@ -1430,7 +1430,7 @@ static DRIVER_ATTR_RW(wlsw_emulstate);
 /* bluetooth_emulstate ------------------------------------------------- */
 static ssize_t bluetooth_emulstate_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate);
+       return sysfs_emit(buf, "%d\n", !!tpacpi_bluetooth_emulstate);
 }
 
 static ssize_t bluetooth_emulstate_store(struct device_driver *drv,
@@ -1450,7 +1450,7 @@ static DRIVER_ATTR_RW(bluetooth_emulstate);
 /* wwan_emulstate ------------------------------------------------- */
 static ssize_t wwan_emulstate_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate);
+       return sysfs_emit(buf, "%d\n", !!tpacpi_wwan_emulstate);
 }
 
 static ssize_t wwan_emulstate_store(struct device_driver *drv, const char *buf,
@@ -1470,7 +1470,7 @@ static DRIVER_ATTR_RW(wwan_emulstate);
 /* uwb_emulstate ------------------------------------------------- */
 static ssize_t uwb_emulstate_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate);
+       return sysfs_emit(buf, "%d\n", !!tpacpi_uwb_emulstate);
 }
 
 static ssize_t uwb_emulstate_store(struct device_driver *drv, const char *buf,
@@ -2678,7 +2678,7 @@ static ssize_t hotkey_enable_show(struct device *dev,
        if (res)
                return res;
 
-       return snprintf(buf, PAGE_SIZE, "%d\n", status);
+       return sysfs_emit(buf, "%d\n", status);
 }
 
 static ssize_t hotkey_enable_store(struct device *dev,
@@ -2706,7 +2706,7 @@ static ssize_t hotkey_mask_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_user_mask);
+       return sysfs_emit(buf, "0x%08x\n", hotkey_user_mask);
 }
 
 static ssize_t hotkey_mask_store(struct device *dev,
@@ -2754,7 +2754,7 @@ static ssize_t hotkey_bios_mask_show(struct device *dev,
 {
        printk_deprecated_attribute("hotkey_bios_mask",
                        "This attribute is useless.");
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
+       return sysfs_emit(buf, "0x%08x\n", hotkey_orig_mask);
 }
 
 static DEVICE_ATTR_RO(hotkey_bios_mask);
@@ -2764,7 +2764,7 @@ static ssize_t hotkey_all_mask_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n",
+       return sysfs_emit(buf, "0x%08x\n",
                                hotkey_all_mask | hotkey_source_mask);
 }
 
@@ -2775,7 +2775,7 @@ static ssize_t hotkey_adaptive_all_mask_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n",
+       return sysfs_emit(buf, "0x%08x\n",
                        hotkey_adaptive_all_mask | hotkey_source_mask);
 }
 
@@ -2786,7 +2786,7 @@ static ssize_t hotkey_recommended_mask_show(struct device *dev,
                                            struct device_attribute *attr,
                                            char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n",
+       return sysfs_emit(buf, "0x%08x\n",
                        (hotkey_all_mask | hotkey_source_mask)
                        & ~hotkey_reserved_mask);
 }
@@ -2800,7 +2800,7 @@ static ssize_t hotkey_source_mask_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask);
+       return sysfs_emit(buf, "0x%08x\n", hotkey_source_mask);
 }
 
 static ssize_t hotkey_source_mask_store(struct device *dev,
@@ -2851,7 +2851,7 @@ static ssize_t hotkey_poll_freq_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq);
+       return sysfs_emit(buf, "%d\n", hotkey_poll_freq);
 }
 
 static ssize_t hotkey_poll_freq_store(struct device *dev,
@@ -2893,7 +2893,7 @@ static ssize_t hotkey_radio_sw_show(struct device *dev,
        /* Opportunistic update */
        tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF));
 
-       return snprintf(buf, PAGE_SIZE, "%d\n",
+       return sysfs_emit(buf, "%d\n",
                        (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1);
 }
 
@@ -2916,7 +2916,7 @@ static ssize_t hotkey_tablet_mode_show(struct device *dev,
        if (res < 0)
                return res;
 
-       return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
+       return sysfs_emit(buf, "%d\n", !!s);
 }
 
 static DEVICE_ATTR_RO(hotkey_tablet_mode);
@@ -2933,7 +2933,7 @@ static ssize_t hotkey_wakeup_reason_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason);
+       return sysfs_emit(buf, "%d\n", hotkey_wakeup_reason);
 }
 
 static DEVICE_ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL);
@@ -2949,7 +2949,7 @@ static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev,
                           struct device_attribute *attr,
                           char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack);
+       return sysfs_emit(buf, "%d\n", hotkey_autosleep_ack);
 }
 
 static DEVICE_ATTR(wakeup_hotunplug_complete, S_IRUGO,
@@ -2984,7 +2984,7 @@ static ssize_t adaptive_kbd_mode_show(struct device *dev,
        if (current_mode < 0)
                return current_mode;
 
-       return snprintf(buf, PAGE_SIZE, "%d\n", current_mode);
+       return sysfs_emit(buf, "%d\n", current_mode);
 }
 
 static ssize_t adaptive_kbd_mode_store(struct device *dev,
@@ -6334,7 +6334,7 @@ static ssize_t thermal_temp_input_show(struct device *dev,
        if (value == TPACPI_THERMAL_SENSOR_NA)
                return -ENXIO;
 
-       return snprintf(buf, PAGE_SIZE, "%d\n", value);
+       return sysfs_emit(buf, "%d\n", value);
 }
 
 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
@@ -8567,7 +8567,7 @@ static ssize_t fan_pwm1_enable_show(struct device *dev,
        } else
                mode = 1;
 
-       return snprintf(buf, PAGE_SIZE, "%d\n", mode);
+       return sysfs_emit(buf, "%d\n", mode);
 }
 
 static ssize_t fan_pwm1_enable_store(struct device *dev,
@@ -8633,7 +8633,7 @@ static ssize_t fan_pwm1_show(struct device *dev,
        if (status > 7)
                status = 7;
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
+       return sysfs_emit(buf, "%u\n", (status * 255) / 7);
 }
 
 static ssize_t fan_pwm1_store(struct device *dev,
@@ -8686,7 +8686,7 @@ static ssize_t fan_fan1_input_show(struct device *dev,
        if (res < 0)
                return res;
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", speed);
+       return sysfs_emit(buf, "%u\n", speed);
 }
 
 static DEVICE_ATTR(fan1_input, S_IRUGO, fan_fan1_input_show, NULL);
@@ -8703,7 +8703,7 @@ static ssize_t fan_fan2_input_show(struct device *dev,
        if (res < 0)
                return res;
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", speed);
+       return sysfs_emit(buf, "%u\n", speed);
 }
 
 static DEVICE_ATTR(fan2_input, S_IRUGO, fan_fan2_input_show, NULL);
@@ -8711,7 +8711,7 @@ static DEVICE_ATTR(fan2_input, S_IRUGO, fan_fan2_input_show, NULL);
 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
 static ssize_t fan_watchdog_show(struct device_driver *drv, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
+       return sysfs_emit(buf, "%u\n", fan_watchdog_maxinterval);
 }
 
 static ssize_t fan_watchdog_store(struct device_driver *drv, const char *buf,