linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: debug: remove redundant call to strlen
@ 2020-02-08 16:25 Colin King
  2020-02-09 17:54 ` Felipe Balbi
  2020-02-10  8:32 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2020-02-08 16:25 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, linux-usb; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The call to strlen is redundant since the return value is assigned
to variable len but not subsequently used. Remove the redundant
call.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/usb/dwc3/debug.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index e56beb9d1e36..ee964352c8e2 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -296,8 +296,6 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
 				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
 				" (Active)" : " (Not Active)");
 
-		len = strlen(str);
-
 		/* Control Endpoints */
 		if (epnum <= 1) {
 			int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
-- 
2.25.0


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

* Re: [PATCH] usb: dwc3: debug: remove redundant call to strlen
  2020-02-08 16:25 [PATCH] usb: dwc3: debug: remove redundant call to strlen Colin King
@ 2020-02-09 17:54 ` Felipe Balbi
  2020-02-10  8:32 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Felipe Balbi @ 2020-02-09 17:54 UTC (permalink / raw)
  To: Colin King, Greg Kroah-Hartman, linux-usb; +Cc: kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1927 bytes --]

Colin King <colin.king@canonical.com> writes:

> From: Colin Ian King <colin.king@canonical.com>
>
> The call to strlen is redundant since the return value is assigned
> to variable len but not subsequently used. Remove the redundant
> call.
>
> Addresses-Coverity: ("Unused value")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/usb/dwc3/debug.h | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
> index e56beb9d1e36..ee964352c8e2 100644
> --- a/drivers/usb/dwc3/debug.h
> +++ b/drivers/usb/dwc3/debug.h
> @@ -296,8 +296,6 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
>  				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
>  				" (Active)" : " (Not Active)");
>  
> -		len = strlen(str);
> -

looking at the code here. The problem is elsewhere:

| case DWC3_DEPEVT_XFERNOTREADY:
| 	len = strlen(str);
| 	snprintf(str + len, size - len, "Transfer Not Ready [%d]%s",
| 			event->parameters,
| 			status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
| 			" (Active)" : " (Not Active)");
|
| 	len = strlen(str);
|
| 	/* Control Endpoints */
| 	if (epnum <= 1) {
| 		int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
| 		switch (phase) {
| 		case DEPEVT_STATUS_CONTROL_DATA:
| 			snprintf(str + ret, size - ret,
| 					" [Data Phase]");
| 			break;
| 		case DEPEVT_STATUS_CONTROL_STATUS:
| 			snprintf(str + ret, size - ret,
| 					" [Status Phase]");

these two should use str + len and size - len. However, a better fix
would be drop the usage of strlen() and just use the return value from
snprintf().

Do you want to produce that patch, instead? It could be two patches:

	1. replace ret with len in these two cases (a bug fix, possibly
	        Cc stable)
        2. drop usage of strlen() in the entire function (a new feature,
	        for v5.7

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] usb: dwc3: debug: remove redundant call to strlen
  2020-02-08 16:25 [PATCH] usb: dwc3: debug: remove redundant call to strlen Colin King
  2020-02-09 17:54 ` Felipe Balbi
@ 2020-02-10  8:32 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-02-10  8:32 UTC (permalink / raw)
  To: Colin King
  Cc: Felipe Balbi, Greg Kroah-Hartman, linux-usb, kernel-janitors,
	linux-kernel

On Sat, Feb 08, 2020 at 04:25:08PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The call to strlen is redundant since the return value is assigned
> to variable len but not subsequently used. Remove the redundant
> call.
> 
> Addresses-Coverity: ("Unused value")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/usb/dwc3/debug.h | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
> index e56beb9d1e36..ee964352c8e2 100644
> --- a/drivers/usb/dwc3/debug.h
> +++ b/drivers/usb/dwc3/debug.h
> @@ -296,8 +296,6 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
>  				status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
>  				" (Active)" : " (Not Active)");
>  
> -		len = strlen(str);

This code is buggy.  It's a mixup between ret and len.  Get rid of "ret"
and use "len" throughout.

Unlike userspace snprintf() the kernel version always returns a positive
value.  It returns the number of bytes that would have been copied if
there were enough space.  This code should probably be changed to use
scnprintf() which returns the number of bytes which were copied
successfully.

The remove all the strlen() calls.  It should just be += the return.

	len += scnprintf(str + len, size - len, "Transfer Not Ready [%d] %s",
			 event->parameters,
			 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
				"(Active)" : "(Not Active)");

regards,
dan carpenter


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

end of thread, other threads:[~2020-02-10  8:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-08 16:25 [PATCH] usb: dwc3: debug: remove redundant call to strlen Colin King
2020-02-09 17:54 ` Felipe Balbi
2020-02-10  8:32 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).