2022-06-13 03:26:27

by Xuezhi Zhang

[permalink] [raw]
Subject: [PATCH v2] usb: core: sysfs: convert sysfs snprintf to sysfs_emit

Fix the following coccicheck warnings:
drivers/usb/core/sysfs.c:921:8-16:
WARNING: use scnprintf or sprintf
drivers/usb/core/sysfs.c:730:8-16:
WARNING: use scnprintf or sprintf

Signed-off-by: Xuezhi Zhang <[email protected]>
---
v2: add correct public mailing list
---
drivers/usb/core/sysfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index fa2e49d432ff..6387c0dfe30e 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -727,7 +727,7 @@ static ssize_t authorized_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct usb_device *usb_dev = to_usb_device(dev);
- return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
+ return sysfs_emit(buf, "%u\n", usb_dev->authorized);
}

/*
@@ -918,7 +918,7 @@ static ssize_t authorized_default_show(struct device *dev,
struct usb_hcd *hcd;

hcd = bus_to_hcd(usb_bus);
- return snprintf(buf, PAGE_SIZE, "%u\n", hcd->dev_policy);
+ return sysfs_emit(buf, "%u\n", hcd->dev_policy);
}

static ssize_t authorized_default_store(struct device *dev,
--
2.34.1


2022-06-21 15:31:30

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2] usb: core: sysfs: convert sysfs snprintf to sysfs_emit

On Mon, Jun 13, 2022 at 10:35:53AM +0800, Xuezhi Zhang wrote:
> Fix the following coccicheck warnings:
> drivers/usb/core/sysfs.c:921:8-16:
> WARNING: use scnprintf or sprintf
> drivers/usb/core/sysfs.c:730:8-16:
> WARNING: use scnprintf or sprintf

Please do not wrap error or warning messages.

>
> Signed-off-by: Xuezhi Zhang <[email protected]>
> ---
> v2: add correct public mailing list
> ---
> drivers/usb/core/sysfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
> index fa2e49d432ff..6387c0dfe30e 100644
> --- a/drivers/usb/core/sysfs.c
> +++ b/drivers/usb/core/sysfs.c
> @@ -727,7 +727,7 @@ static ssize_t authorized_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> struct usb_device *usb_dev = to_usb_device(dev);
> - return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
> + return sysfs_emit(buf, "%u\n", usb_dev->authorized);
> }
>
> /*
> @@ -918,7 +918,7 @@ static ssize_t authorized_default_show(struct device *dev,
> struct usb_hcd *hcd;
>
> hcd = bus_to_hcd(usb_bus);
> - return snprintf(buf, PAGE_SIZE, "%u\n", hcd->dev_policy);
> + return sysfs_emit(buf, "%u\n", hcd->dev_policy);
> }

Any specific reason you are not fixing up all sysfs show entries in this
file? Only doing a few feels odd and wrong, please do the whole file at
once.

thanks,

greg k-h