Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86: sony-laptop: replace snprintf in show functions with sysfs_emit

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/20211022090851.1065538-1-ye.guojin@zte.com.cn
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Ye Guojin and committed by
Hans de Goede
c4b9ad6b 21d91e20

+18 -28
+18 -28
drivers/platform/x86/sony-laptop.c
··· 964 964 if (item->validate) 965 965 value = item->validate(SNC_VALIDATE_OUT, value); 966 966 967 - return snprintf(buffer, PAGE_SIZE, "%d\n", value); 967 + return sysfs_emit(buffer, "%d\n", value); 968 968 } 969 969 970 970 static ssize_t sony_nc_sysfs_store(struct device *dev, ··· 1811 1811 static ssize_t sony_nc_kbd_backlight_mode_show(struct device *dev, 1812 1812 struct device_attribute *attr, char *buffer) 1813 1813 { 1814 - ssize_t count = 0; 1815 - count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->mode); 1816 - return count; 1814 + return sysfs_emit(buffer, "%d\n", kbdbl_ctl->mode); 1817 1815 } 1818 1816 1819 1817 static int __sony_nc_kbd_backlight_timeout_set(u8 value) ··· 1853 1855 static ssize_t sony_nc_kbd_backlight_timeout_show(struct device *dev, 1854 1856 struct device_attribute *attr, char *buffer) 1855 1857 { 1856 - ssize_t count = 0; 1857 - count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->timeout); 1858 - return count; 1858 + return sysfs_emit(buffer, "%d\n", kbdbl_ctl->timeout); 1859 1859 } 1860 1860 1861 1861 static int sony_nc_kbd_backlight_setup(struct platform_device *pd, ··· 2047 2051 break; 2048 2052 } 2049 2053 2050 - return snprintf(buffer, PAGE_SIZE, "%d\n", status); 2054 + return sysfs_emit(buffer, "%d\n", status); 2051 2055 } 2052 2056 2053 2057 static ssize_t sony_nc_battery_care_health_show(struct device *dev, 2054 2058 struct device_attribute *attr, char *buffer) 2055 2059 { 2056 - ssize_t count = 0; 2057 2060 unsigned int health; 2058 2061 2059 2062 if (sony_call_snc_handle(bcare_ctl->handle, 0x0200, &health)) 2060 2063 return -EIO; 2061 2064 2062 - count = snprintf(buffer, PAGE_SIZE, "%d\n", health & 0xff); 2063 - 2064 - return count; 2065 + return sysfs_emit(buffer, "%d\n", health & 0xff); 2065 2066 } 2066 2067 2067 2068 static int sony_nc_battery_care_setup(struct platform_device *pd, ··· 2208 2215 static ssize_t sony_nc_thermal_mode_show(struct device *dev, 2209 2216 struct device_attribute *attr, char *buffer) 2210 2217 { 2211 - ssize_t count = 0; 2212 2218 int mode = sony_nc_thermal_mode_get(); 2213 2219 2214 2220 if (mode < 0) 2215 2221 return mode; 2216 2222 2217 - count = snprintf(buffer, PAGE_SIZE, "%s\n", snc_thermal_profiles[mode]); 2218 - 2219 - return count; 2223 + return sysfs_emit(buffer, "%s\n", snc_thermal_profiles[mode]); 2220 2224 } 2221 2225 2222 2226 static int sony_nc_thermal_setup(struct platform_device *pd) ··· 2351 2361 2352 2362 while (pos < LID_RESUME_MAX) { 2353 2363 if (&lid_ctl->attrs[pos].attr == &attr->attr) 2354 - return snprintf(buffer, PAGE_SIZE, "%d\n", 2364 + return sysfs_emit(buffer, "%d\n", 2355 2365 (lid_ctl->status >> pos) & 0x01); 2356 2366 pos++; 2357 2367 } ··· 2483 2493 if (pos < 0) 2484 2494 return pos; 2485 2495 2486 - return snprintf(buffer, PAGE_SIZE, "%s\n", 2496 + return sysfs_emit(buffer, "%s\n", 2487 2497 pos == SPEED ? "speed" : 2488 2498 pos == STAMINA ? "stamina" : 2489 2499 pos == AUTO ? "auto" : "unknown"); ··· 2558 2568 if (sony_call_snc_handle(0x0131, 0x0100, &result)) 2559 2569 return -EIO; 2560 2570 2561 - return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01); 2571 + return sysfs_emit(buffer, "%d\n", result & 0x01); 2562 2572 } 2563 2573 2564 2574 static int sony_nc_highspeed_charging_setup(struct platform_device *pd) ··· 2632 2642 if (sony_call_snc_handle(0x0121, 0x0200, &result)) 2633 2643 return -EIO; 2634 2644 2635 - return snprintf(buffer, PAGE_SIZE, "%d\n", result & 1); 2645 + return sysfs_emit(buffer, "%d\n", result & 1); 2636 2646 } 2637 2647 2638 2648 static int sony_nc_lowbatt_setup(struct platform_device *pd) ··· 2698 2708 if (sony_call_snc_handle(0x0149, 0x0100, &result)) 2699 2709 return -EIO; 2700 2710 2701 - return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01); 2711 + return sysfs_emit(buffer, "%d\n", result & 0x01); 2702 2712 } 2703 2713 2704 2714 static ssize_t sony_nc_fanspeed_show(struct device *dev, ··· 2709 2719 if (sony_call_snc_handle(0x0149, 0x0300, &result)) 2710 2720 return -EIO; 2711 2721 2712 - return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0xff); 2722 + return sysfs_emit(buffer, "%d\n", result & 0xff); 2713 2723 } 2714 2724 2715 2725 static int sony_nc_fanspeed_setup(struct platform_device *pd) ··· 2805 2815 if (sony_call_snc_handle(0x0155, 0x0000, &result)) 2806 2816 return -EIO; 2807 2817 2808 - return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01); 2818 + return sysfs_emit(buffer, "%d\n", result & 0x01); 2809 2819 } 2810 2820 2811 2821 static int sony_nc_usb_charge_setup(struct platform_device *pd) ··· 2860 2870 if (sony_call_snc_handle(0x011D, 0x0000, &result)) 2861 2871 return -EIO; 2862 2872 2863 - return snprintf(buffer, PAGE_SIZE, "%d\n", result); 2873 + return sysfs_emit(buffer, "%d\n", result); 2864 2874 } 2865 2875 2866 2876 static int sony_nc_panelid_setup(struct platform_device *pd) ··· 2988 2998 if (sony_call_snc_handle(tp_ctl->handle, 0x000, &result)) 2989 2999 return -EINVAL; 2990 3000 2991 - return snprintf(buffer, PAGE_SIZE, "%d\n", !(result & 0x01)); 3001 + return sysfs_emit(buffer, "%d\n", !(result & 0x01)); 2992 3002 } 2993 3003 2994 3004 static int sony_nc_touchpad_setup(struct platform_device *pd, ··· 3905 3915 { 3906 3916 ssize_t count; 3907 3917 mutex_lock(&spic_dev.lock); 3908 - count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power); 3918 + count = sysfs_emit(buffer, "%d\n", spic_dev.wwan_power); 3909 3919 mutex_unlock(&spic_dev.lock); 3910 3920 return count; 3911 3921 } ··· 3944 3954 { 3945 3955 ssize_t count = 0; 3946 3956 mutex_lock(&spic_dev.lock); 3947 - count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power); 3957 + count = sysfs_emit(buffer, "%d\n", spic_dev.bluetooth_power); 3948 3958 mutex_unlock(&spic_dev.lock); 3949 3959 return count; 3950 3960 } ··· 3986 3996 if (sony_pic_get_fanspeed(&value)) 3987 3997 return -EIO; 3988 3998 3989 - return snprintf(buffer, PAGE_SIZE, "%d\n", value); 3999 + return sysfs_emit(buffer, "%d\n", value); 3990 4000 } 3991 4001 3992 4002 #define SPIC_ATTR(_name, _mode) \