All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: replace snprintf in show functions with sysfs_emit
@ 2021-10-13  3:27 Qing Wang
  2021-10-13  6:19 ` Greg Kroah-Hartman
       [not found] ` <AA2A8gBxEnrQndzc*evdgarV.9.1634105950804.Hmail.wangqing@vivo.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Qing Wang @ 2021-10-13  3:27 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-usb, linux-kernel; +Cc: Qing Wang

coccicheck complains about the use of snprintf() in sysfs show functions.

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

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 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 fa2e49d..6387c0d 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.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: replace snprintf in show functions with sysfs_emit
  2021-10-13  3:27 [PATCH] usb: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-13  6:19 ` Greg Kroah-Hartman
       [not found] ` <AA2A8gBxEnrQndzc*evdgarV.9.1634105950804.Hmail.wangqing@vivo.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-10-13  6:19 UTC (permalink / raw)
  To: Qing Wang; +Cc: linux-usb, linux-kernel

On Tue, Oct 12, 2021 at 08:27:47PM -0700, Qing Wang wrote:
> coccicheck complains about the use of snprintf() in sysfs show functions.
> 
> Fix the following coccicheck warning:
> drivers/usb/core/sysfs.c:730:8-16: WARNING: use scnprintf or sprintf.
> drivers/usb/core/sysfs.c:921:8-16: WARNING: use scnprintf or sprintf.
> 
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
> 
> Signed-off-by: Qing Wang <wangqing@vivo.com>
> ---
>  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 fa2e49d..6387c0d 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.7.4
> 

If you are going to change this file, you should do this for all of the
sysfs show functions in this file, not just 2 of them, right?  Please
change this patch to do that.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* 回复: [PATCH] usb: replace snprintf in show functions with sysfs_emit
       [not found] ` <AA2A8gBxEnrQndzc*evdgarV.9.1634105950804.Hmail.wangqing@vivo.com>
@ 2021-10-13  6:52   ` 王擎
  2021-10-13  7:07     ` Greg Kroah-Hartman
       [not found]     ` <AGUA7ADTEv9Q*f-TXCLIpKpn.9.1634108876473.Hmail.wangqing@vivo.com>
  0 siblings, 2 replies; 6+ messages in thread
From: 王擎 @ 2021-10-13  6:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

 
>> On Tue, Oct 12, 2021 at 08:27:47PM -0700, Qing Wang wrote:
>> coccicheck complains about the use of snprintf() in sysfs show functions.
>> 
>> Fix the following coccicheck warning:
>> drivers/usb/core/sysfs.c:730:8-16: WARNING: use scnprintf or sprintf.
>> drivers/usb/core/sysfs.c:921:8-16: WARNING: use scnprintf or sprintf.
>> 
>> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>> 
>> Signed-off-by: Qing Wang <wangqing@vivo.com>
>> ---
>>  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 fa2e49d..6387c0d 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.7.4
>> 
> 
> If you are going to change this file, you should do this for all of the
> sysfs show functions in this file, not just 2 of them, right?  Please
> change this patch to do that.
>
> thanks,
> 
> greg k-h

Only these 2 snprintf need to be modified, other show functions
used sprintf do not need to modify.

Thanks,

Qing

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: 回复: [PATCH] usb: replace snprintf in show functions with sysfs_emit
  2021-10-13  6:52   ` 回复: " 王擎
@ 2021-10-13  7:07     ` Greg Kroah-Hartman
       [not found]     ` <AGUA7ADTEv9Q*f-TXCLIpKpn.9.1634108876473.Hmail.wangqing@vivo.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-10-13  7:07 UTC (permalink / raw)
  To: 王擎; +Cc: linux-usb, linux-kernel

On Wed, Oct 13, 2021 at 06:52:53AM +0000, 王擎 wrote:
>  
> >> On Tue, Oct 12, 2021 at 08:27:47PM -0700, Qing Wang wrote:
> >> coccicheck complains about the use of snprintf() in sysfs show functions.
> >> 
> >> Fix the following coccicheck warning:
> >> drivers/usb/core/sysfs.c:730:8-16: WARNING: use scnprintf or sprintf.
> >> drivers/usb/core/sysfs.c:921:8-16: WARNING: use scnprintf or sprintf.
> >> 
> >> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
> >> 
> >> Signed-off-by: Qing Wang <wangqing@vivo.com>
> >> ---
> >>  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 fa2e49d..6387c0d 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.7.4
> >> 
> > 
> > If you are going to change this file, you should do this for all of the
> > sysfs show functions in this file, not just 2 of them, right?  Please
> > change this patch to do that.
> >
> > thanks,
> > 
> > greg k-h
> 
> Only these 2 snprintf need to be modified, other show functions
> used sprintf do not need to modify.

I do not think you understand the change you are trying to make here.

Either the whole file should use the same api, or just leave it as-is as
it obviously works properly today :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* 回复: 回复: [PATCH] usb: replace snprintf in show functions with sysfs_emit
       [not found]     ` <AGUA7ADTEv9Q*f-TXCLIpKpn.9.1634108876473.Hmail.wangqing@vivo.com>
@ 2021-10-13  7:20       ` 王擎
  2021-10-13  7:28         ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: 王擎 @ 2021-10-13  7:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

 
>> >> On Tue, Oct 12, 2021 at 08:27:47PM -0700, Qing Wang wrote:
>> >> coccicheck complains about the use of snprintf() in sysfs show functions.
>> >> 
>> >> Fix the following coccicheck warning:
>> >> drivers/usb/core/sysfs.c:730:8-16: WARNING: use scnprintf or sprintf.
>> >> drivers/usb/core/sysfs.c:921:8-16: WARNING: use scnprintf or sprintf.
>> >> 
>> >> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>> >> 
>> >> Signed-off-by: Qing Wang <wangqing@vivo.com>
>> >> ---
>> >>  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 fa2e49d..6387c0d 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.7.4
>> >> 
>> > 
>> > If you are going to change this file, you should do this for all of the
>> > sysfs show functions in this file, not just 2 of them, right?  Please
>> > change this patch to do that.
>> >
>> > thanks,
>> > 
>> > greg k-h
>> 
>> Only these 2 snprintf need to be modified, other show functions
>> used sprintf do not need to modify.
> 
> I do not think you understand the change you are trying to make here.
> 
> Either the whole file should use the same api, or just leave it as-is as
> it obviously works properly today :)
> 
> thanks,
> 
> greg k-h

snprintf() returns the length of the string, not the length actually written.
Here only correct this issue, as to whether it overflows should be 
guaranteed by the caller of sprintf().

Thanks,

Qing

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: 回复: 回复: [PATCH] usb: replace snprintf in show functions with sysfs_emit
  2021-10-13  7:20       ` 回复: " 王擎
@ 2021-10-13  7:28         ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-10-13  7:28 UTC (permalink / raw)
  To: 王擎; +Cc: linux-usb, linux-kernel

On Wed, Oct 13, 2021 at 07:20:25AM +0000, 王擎 wrote:
>  
> >> >> On Tue, Oct 12, 2021 at 08:27:47PM -0700, Qing Wang wrote:
> >> >> coccicheck complains about the use of snprintf() in sysfs show functions.
> >> >> 
> >> >> Fix the following coccicheck warning:
> >> >> drivers/usb/core/sysfs.c:730:8-16: WARNING: use scnprintf or sprintf.
> >> >> drivers/usb/core/sysfs.c:921:8-16: WARNING: use scnprintf or sprintf.
> >> >> 
> >> >> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
> >> >> 
> >> >> Signed-off-by: Qing Wang <wangqing@vivo.com>
> >> >> ---
> >> >>  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 fa2e49d..6387c0d 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.7.4
> >> >> 
> >> > 
> >> > If you are going to change this file, you should do this for all of the
> >> > sysfs show functions in this file, not just 2 of them, right?  Please
> >> > change this patch to do that.
> >> >
> >> > thanks,
> >> > 
> >> > greg k-h
> >> 
> >> Only these 2 snprintf need to be modified, other show functions
> >> used sprintf do not need to modify.
> > 
> > I do not think you understand the change you are trying to make here.
> > 
> > Either the whole file should use the same api, or just leave it as-is as
> > it obviously works properly today :)
> > 
> > thanks,
> > 
> > greg k-h
> 
> snprintf() returns the length of the string, not the length actually written.
> Here only correct this issue, as to whether it overflows should be 
> guaranteed by the caller of sprintf().

But for all of these, there is no overflow possible, that's not the
issue here.

As-is, this code works just fine.  If you really want to change it, as
per the recommendation of some static checker, then do so for the whole
file, to be unified and make sense overall.  Do not just blindly follow
a static tool for no good reason :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-13  7:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13  3:27 [PATCH] usb: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-13  6:19 ` Greg Kroah-Hartman
     [not found] ` <AA2A8gBxEnrQndzc*evdgarV.9.1634105950804.Hmail.wangqing@vivo.com>
2021-10-13  6:52   ` 回复: " 王擎
2021-10-13  7:07     ` Greg Kroah-Hartman
     [not found]     ` <AGUA7ADTEv9Q*f-TXCLIpKpn.9.1634108876473.Hmail.wangqing@vivo.com>
2021-10-13  7:20       ` 回复: " 王擎
2021-10-13  7:28         ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.