2024-03-15 05:52:40

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: [PATCH v2 3/3] wifi: ti: 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: Kalle Valo <[email protected]>
CC: [email protected]
Signed-off-by: Li Zhijian <[email protected]>
---
V2: subject updated

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]/
Signed-off-by: Li Zhijian <[email protected]>
---
drivers/net/wireless/ti/wlcore/sysfs.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/sysfs.c b/drivers/net/wireless/ti/wlcore/sysfs.c
index f0c7e09b314d..c07acfcbbd9c 100644
--- a/drivers/net/wireless/ti/wlcore/sysfs.c
+++ b/drivers/net/wireless/ti/wlcore/sysfs.c
@@ -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;
--
2.29.2



2024-03-18 09:16:50

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] wifi: ti: Convert sprintf/snprintf to sysfs_emit

Li Zhijian <[email protected]> writes:

> 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 <[email protected]>
> CC: [email protected]
> Signed-off-by: Li Zhijian <[email protected]>
> ---
> V2: subject updated
>
> 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]/
> Signed-off-by: Li Zhijian <[email protected]>

Please resubmit the whole patchset as v3.

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#resubmit_the_whole_patchset


--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

2024-03-18 09:43:05

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] wifi: ti: Convert sprintf/snprintf to sysfs_emit

Kalle,


On 18/03/2024 17:16, Kalle Valo wrote:
> Li Zhijian <[email protected]> writes:
>
>> 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 <[email protected]>
>> CC: [email protected]
>> Signed-off-by: Li Zhijian <[email protected]>
>> ---
>> V2: subject updated
>>
>> 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]/
>> Signed-off-by: Li Zhijian <[email protected]>
>
> Please resubmit the whole patchset as v3.


May I know what's wrong with this V2? or what update should I do in V3


> Even if just one patch has changed in a patch series resubmit the whole patchset (and remember to increase the version number), do not just resubmit that one changed patch. The reason is that it's difficult to apply patches in correct order when some of them are submitted separately.

I thought I had followed this rule. Feel free to let me know if I missed something


Thanks
Zhijian

>
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#resubmit_the_whole_patchset
>
>

2024-03-18 10:05:12

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] wifi: ti: Convert sprintf/snprintf to sysfs_emit

"Zhijian Li (Fujitsu)" <[email protected]> writes:

> Kalle,
>
>
> On 18/03/2024 17:16, Kalle Valo wrote:
>> Li Zhijian <[email protected]> writes:
>>
>>> 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 <[email protected]>
>>> CC: [email protected]
>>> Signed-off-by: Li Zhijian <[email protected]>
>>> ---
>>> V2: subject updated
>>>
>>> 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]/
>>> Signed-off-by: Li Zhijian <[email protected]>
>>
>> Please resubmit the whole patchset as v3.
>
>
> May I know what's wrong with this V2? or what update should I do in V3

Sorry, my mistake. I didn't see patch 1 and I assumed it was not sent.
But I checked patchwork now and I do see all three patches:

https://patchwork.kernel.org/project/linux-wireless/list/?series=835497

So no need to resend anything because of this.

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches