2024-03-14 09:48:48

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: [PATCH 2/3] net: 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 <[email protected]>
CC: Kalle Valo <[email protected]>
CC: [email protected]
CC: [email protected]
Signed-off-by: Li Zhijian <[email protected]>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/[email protected]/
---
drivers/net/wireless/broadcom/b43/sysfs.c | 13 ++++---------
drivers/net/wireless/broadcom/b43legacy/sysfs.c | 17 +++++++----------
2 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/broadcom/b43/sysfs.c b/drivers/net/wireless/broadcom/b43/sysfs.c
index 0679d132968f..261b2b746a9c 100644
--- a/drivers/net/wireless/broadcom/b43/sysfs.c
+++ b/drivers/net/wireless/broadcom/b43/sysfs.c
@@ -53,19 +53,14 @@ static ssize_t b43_attr_interfmode_show(struct device *dev,

switch (wldev->phy.g->interfmode) {
case B43_INTERFMODE_NONE:
- count =
- snprintf(buf, PAGE_SIZE,
- "0 (No Interference Mitigation)\n");
+ count = sysfs_emit(buf, "0 (No Interference Mitigation)\n");
break;
case B43_INTERFMODE_NONWLAN:
- count =
- snprintf(buf, PAGE_SIZE,
- "1 (Non-WLAN Interference Mitigation)\n");
+ count = sysfs_emit(buf,
+ "1 (Non-WLAN Interference Mitigation)\n");
break;
case B43_INTERFMODE_MANUALWLAN:
- count =
- snprintf(buf, PAGE_SIZE,
- "2 (WLAN Interference Mitigation)\n");
+ count = sysfs_emit(buf, "2 (WLAN Interference Mitigation)\n");
break;
default:
B43_WARN_ON(1);
diff --git a/drivers/net/wireless/broadcom/b43legacy/sysfs.c b/drivers/net/wireless/broadcom/b43legacy/sysfs.c
index eec087ca30e6..b1c5ea4750fa 100644
--- a/drivers/net/wireless/broadcom/b43legacy/sysfs.c
+++ b/drivers/net/wireless/broadcom/b43legacy/sysfs.c
@@ -75,16 +75,15 @@ static ssize_t b43legacy_attr_interfmode_show(struct device *dev,

switch (wldev->phy.interfmode) {
case B43legacy_INTERFMODE_NONE:
- count = snprintf(buf, PAGE_SIZE, "0 (No Interference"
- " Mitigation)\n");
+ count = sysfs_emit(buf, "0 (No Interference" " Mitigation)\n");
break;
case B43legacy_INTERFMODE_NONWLAN:
- count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference"
- " Mitigation)\n");
+ count = sysfs_emit(buf, "1 (Non-WLAN Interference"
+ " Mitigation)\n");
break;
case B43legacy_INTERFMODE_MANUALWLAN:
- count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference"
- " Mitigation)\n");
+ count = sysfs_emit(buf, "2 (WLAN Interference"
+ " Mitigation)\n");
break;
default:
B43legacy_WARN_ON(1);
@@ -155,11 +154,9 @@ static ssize_t b43legacy_attr_preamble_show(struct device *dev,
mutex_lock(&wldev->wl->mutex);

if (wldev->short_preamble)
- count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble"
- " enabled)\n");
+ count = sysfs_emit(buf, "1 (Short Preamble" " enabled)\n");
else
- count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble"
- " disabled)\n");
+ count = sysfs_emit(buf, "0 (Short Preamble" " disabled)\n");

mutex_unlock(&wldev->wl->mutex);

--
2.29.2



2024-03-14 18:33:23

by Michael Büsch

[permalink] [raw]
Subject: Re: [PATCH 2/3] net: b43: Convert sprintf/snprintf to sysfs_emit

On Thu, 14 Mar 2024 17:48:22 +0800
Li Zhijian <[email protected]> wrote:

> case B43legacy_INTERFMODE_NONE:
> - count = snprintf(buf, PAGE_SIZE, "0 (No Interference"
> - " Mitigation)\n");
> + count = sysfs_emit(buf, "0 (No Interference" " Mitigation)\n");
> break;

> if (wldev->short_preamble)
> - count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble"
> - " enabled)\n");
> + count = sysfs_emit(buf, "1 (Short Preamble" " enabled)\n");
> else
> - count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble"
> - " disabled)\n");
> + count = sysfs_emit(buf, "0 (Short Preamble" " disabled)\n");
>

Please either leave the line break in place, or remove the string continuation.



--
Michael Büsch
https://bues.ch/


Attachments:
(No filename) (849.00 B)
OpenPGP digital signature

2024-03-15 01:17:36

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: Re: [PATCH 2/3] net: b43: Convert sprintf/snprintf to sysfs_emit



On 15/03/2024 02:32, Michael Büsch wrote:
> On Thu, 14 Mar 2024 17:48:22 +0800
> Li Zhijian <[email protected]> wrote:
>
>> case B43legacy_INTERFMODE_NONE:
>> - count = snprintf(buf, PAGE_SIZE, "0 (No Interference"
>> - " Mitigation)\n");
>> + count = sysfs_emit(buf, "0 (No Interference" " Mitigation)\n");
>> break;
>
>> if (wldev->short_preamble)
>> - count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble"
>> - " enabled)\n");
>> + count = sysfs_emit(buf, "1 (Short Preamble" " enabled)\n");
>> else
>> - count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble"
>> - " disabled)\n");
>> + count = sysfs_emit(buf, "0 (Short Preamble" " disabled)\n");
>>
>
> Please either leave the line break in place, or remove the string continuation.

Good catch, i will update it.


Thanks
Zhijian

>
>
>