wifi: ti: Convert sprintf/snprintf to sysfs_emit
authorLi Zhijian <lizhijian@fujitsu.com>
Fri, 15 Mar 2024 05:52:11 +0000 (13:52 +0800)
committerKalle Valo <kvalo@kernel.org>
Thu, 21 Mar 2024 15:07:54 +0000 (17:07 +0200)
Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() will be converted as weel if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Kalle Valo <kvalo@kernel.org>
CC: linux-wireless@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240315055211.1347548-3-lizhijian@fujitsu.com
drivers/net/wireless/ti/wlcore/sysfs.c

index f0c7e09b314df86bb2c88c235dff20beb7f0c744..c07acfcbbd9c8179bd312840efda43e7e9c5e6a0 100644 (file)
@@ -19,11 +19,8 @@ static ssize_t bt_coex_state_show(struct device *dev,
        struct wl1271 *wl = dev_get_drvdata(dev);
        ssize_t len;
 
-       len = PAGE_SIZE;
-
        mutex_lock(&wl->mutex);
-       len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
-                      wl->sg_enabled);
+       len = sysfs_emit(buf, "%d\n\n0 - off\n1 - on\n", wl->sg_enabled);
        mutex_unlock(&wl->mutex);
 
        return len;
@@ -78,13 +75,11 @@ static ssize_t hw_pg_ver_show(struct device *dev,
        struct wl1271 *wl = dev_get_drvdata(dev);
        ssize_t len;
 
-       len = PAGE_SIZE;
-
        mutex_lock(&wl->mutex);
        if (wl->hw_pg_ver >= 0)
-               len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
+               len = sysfs_emit(buf, "%d\n", wl->hw_pg_ver);
        else
-               len = snprintf(buf, len, "n/a\n");
+               len = sysfs_emit(buf, "n/a\n");
        mutex_unlock(&wl->mutex);
 
        return len;