2022-01-27 06:34:05

by David Yang

[permalink] [raw]
Subject: [PATCH] usb: core: replace snprintf with sysfs_emit

From: Yang Guang <[email protected]>

coccinelle report:
./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

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Reported-by: Zeal Robot <[email protected]>
Signed-off-by: Yang Guang <[email protected]>
Signed-off-by: David Yang <[email protected]>
---
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.30.2


2022-01-27 12:10:07

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] usb: core: replace snprintf with sysfs_emit

On Thu, Jan 27, 2022 at 07:54:54AM +0800, [email protected] wrote:
> From: Yang Guang <[email protected]>
>
> coccinelle report:
> ./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
>
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>
> Reported-by: Zeal Robot <[email protected]>

Again, no, this did not report this. I'll keep ignoring changes like
this that get this wrong.

> Signed-off-by: Yang Guang <[email protected]>
> Signed-off-by: David Yang <[email protected]>
> ---
> 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.30.2
>

Also this change is not correct, why are you only doing this for 2 sysfs
files and not all of them? Is there anything incorrect about the
current sysfs handling in this file that requires them to be changed to
use the new api?

greg k-h