Re: [PATCH] drivers: most: replace snprintf in show functions with sysfs_emit

From: Greg KH
Date: Wed Nov 03 2021 - 04:28:37 EST


On Wed, Nov 03, 2021 at 08:23:13AM +0000, cgel.zte@xxxxxxxxx wrote:
> From: Jing Yao <yao.jing2@xxxxxxxxxx>
>
> coccicheck complains about the use of snprintf() in sysfs show
> funcitons:
> WARNING use scnprintf or sprintf
>
> Use sysfs_emit instead of scnprintf, snprintf or sprintf makes more
> sense.
>
> Reported-by: Zeal Robot <zealci@xxxxxxxxxx>

This "robot" is not coccicheck.


> Signed-off-by: Jing Yao <yao.jing2@xxxxxxxxxx>
> ---
> drivers/most/most_usb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
> index acabb7715b42..dccbec16000c 100644
> --- a/drivers/most/most_usb.c
> +++ b/drivers/most/most_usb.c
> @@ -831,7 +831,7 @@ static ssize_t value_show(struct device *dev, struct device_attribute *attr,
> int err;
>
> if (sysfs_streq(name, "arb_address"))
> - return snprintf(buf, PAGE_SIZE, "%04x\n", dci_obj->reg_addr);
> + return sysfs_emit(buf, "%04x\n", dci_obj->reg_addr);
>
> if (sysfs_streq(name, "arb_value"))
> reg_addr = dci_obj->reg_addr;
> --
> 2.25.1

Why did you only change one of the instances of this in this function
and not both?

Are you going to send a follow-on patch to change the other use of
snprintf() here?

Please do it all in one patch, and fix your "robot" to correctly notify
you of mistakes like this.

thanks,

greg k-h