2024-03-14 08:59:17

by Li Zhijian

[permalink] [raw]
Subject: [PATCH v2 1/4] HID: hid-picolcd_core: 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: "Bruno PrĂ©mont" <[email protected]>
CC: Jiri Kosina <[email protected]>
CC: Benjamin Tissoires <[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/hid/hid-picolcd_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
index bbda231a7ce3..fa46fb6eab3f 100644
--- a/drivers/hid/hid-picolcd_core.c
+++ b/drivers/hid/hid-picolcd_core.c
@@ -256,9 +256,9 @@ static ssize_t picolcd_operation_mode_show(struct device *dev,
struct picolcd_data *data = dev_get_drvdata(dev);

if (data->status & PICOLCD_BOOTLOADER)
- return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
+ return sysfs_emit(buf, "[bootloader] lcd\n");
else
- return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
+ return sysfs_emit(buf, "bootloader [lcd]\n");
}

static ssize_t picolcd_operation_mode_store(struct device *dev,
@@ -301,7 +301,7 @@ static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
{
struct picolcd_data *data = dev_get_drvdata(dev);

- return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
+ return sysfs_emit(buf, "%hu\n", data->opmode_delay);
}

static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
--
2.29.2



2024-03-14 10:40:54

by Li Zhijian

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] HID: hid-picolcd_core: Convert sprintf/snprintf to sysfs_emit


Sorry Bruno, i forgot to address your comments for V1, I will re-send a new version later.
Please ignore this one.

Thanks
Zhijian


On 14/03/2024 16:47, Li Zhijian wrote:
> 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: "Bruno PrĂ©mont" <[email protected]>
> CC: Jiri Kosina <[email protected]>
> CC: Benjamin Tissoires <[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/hid/hid-picolcd_core.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
> index bbda231a7ce3..fa46fb6eab3f 100644
> --- a/drivers/hid/hid-picolcd_core.c
> +++ b/drivers/hid/hid-picolcd_core.c
> @@ -256,9 +256,9 @@ static ssize_t picolcd_operation_mode_show(struct device *dev,
> struct picolcd_data *data = dev_get_drvdata(dev);
>
> if (data->status & PICOLCD_BOOTLOADER)
> - return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
> + return sysfs_emit(buf, "[bootloader] lcd\n");
> else
> - return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
> + return sysfs_emit(buf, "bootloader [lcd]\n");
> }
>
> static ssize_t picolcd_operation_mode_store(struct device *dev,
> @@ -301,7 +301,7 @@ static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
> {
> struct picolcd_data *data = dev_get_drvdata(dev);
>
> - return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
> + return sysfs_emit(buf, "%hu\n", data->opmode_delay);
> }
>
> static ssize_t picolcd_operation_mode_delay_store(struct device *dev,