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

wifi: b43: Convert sprintf/snprintf to sysfs_emit

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: Larry Finger <Larry.Finger@lwfinger.net>
CC: Kalle Valo <kvalo@kernel.org>
CC: linux-wireless@vger.kernel.org
CC: b43-dev@lists.infradead.org
Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240315055211.1347548-2-lizhijian@fujitsu.com

authored by

Li Zhijian and committed by
Kalle Valo
6db5c15c c76936a7

+10 -19
+4 -9
drivers/net/wireless/broadcom/b43/sysfs.c
··· 53 53 54 54 switch (wldev->phy.g->interfmode) { 55 55 case B43_INTERFMODE_NONE: 56 - count = 57 - snprintf(buf, PAGE_SIZE, 58 - "0 (No Interference Mitigation)\n"); 56 + count = sysfs_emit(buf, "0 (No Interference Mitigation)\n"); 59 57 break; 60 58 case B43_INTERFMODE_NONWLAN: 61 - count = 62 - snprintf(buf, PAGE_SIZE, 63 - "1 (Non-WLAN Interference Mitigation)\n"); 59 + count = sysfs_emit(buf, 60 + "1 (Non-WLAN Interference Mitigation)\n"); 64 61 break; 65 62 case B43_INTERFMODE_MANUALWLAN: 66 - count = 67 - snprintf(buf, PAGE_SIZE, 68 - "2 (WLAN Interference Mitigation)\n"); 63 + count = sysfs_emit(buf, "2 (WLAN Interference Mitigation)\n"); 69 64 break; 70 65 default: 71 66 B43_WARN_ON(1);
+6 -10
drivers/net/wireless/broadcom/b43legacy/sysfs.c
··· 75 75 76 76 switch (wldev->phy.interfmode) { 77 77 case B43legacy_INTERFMODE_NONE: 78 - count = snprintf(buf, PAGE_SIZE, "0 (No Interference" 79 - " Mitigation)\n"); 78 + count = sysfs_emit(buf, "0 (No Interference Mitigation)\n"); 80 79 break; 81 80 case B43legacy_INTERFMODE_NONWLAN: 82 - count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference" 83 - " Mitigation)\n"); 81 + count = sysfs_emit(buf, 82 + "1 (Non-WLAN Interference Mitigation)\n"); 84 83 break; 85 84 case B43legacy_INTERFMODE_MANUALWLAN: 86 - count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference" 87 - " Mitigation)\n"); 85 + count = sysfs_emit(buf, "2 (WLAN Interference Mitigation)\n"); 88 86 break; 89 87 default: 90 88 B43legacy_WARN_ON(1); ··· 153 155 mutex_lock(&wldev->wl->mutex); 154 156 155 157 if (wldev->short_preamble) 156 - count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble" 157 - " enabled)\n"); 158 + count = sysfs_emit(buf, "1 (Short Preamble enabled)\n"); 158 159 else 159 - count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble" 160 - " disabled)\n"); 160 + count = sysfs_emit(buf, "0 (Short Preamble disabled)\n"); 161 161 162 162 mutex_unlock(&wldev->wl->mutex); 163 163