All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Colin King <colin.king@canonical.com>
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: debug: remove redundant call to strlen
Date: Mon, 10 Feb 2020 11:32:43 +0300	[thread overview]
Message-ID: <20200210083243.GW1778@kadam> (raw)
In-Reply-To: <20200208162508.29336-1-colin.king@canonical.com>

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


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Colin King <colin.king@canonical.com>
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: debug: remove redundant call to strlen
Date: Mon, 10 Feb 2020 08:32:43 +0000	[thread overview]
Message-ID: <20200210083243.GW1778@kadam> (raw)
In-Reply-To: <20200208162508.29336-1-colin.king@canonical.com>

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

  parent reply	other threads:[~2020-02-10  8:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-08 16:25 [PATCH] usb: dwc3: debug: remove redundant call to strlen Colin King
2020-02-08 16:25 ` Colin King
2020-02-09 17:54 ` Felipe Balbi
2020-02-09 17:54   ` Felipe Balbi
2020-02-10  8:32 ` Dan Carpenter [this message]
2020-02-10  8:32   ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200210083243.GW1778@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=balbi@kernel.org \
    --cc=colin.king@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.