mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vito Caputo <vcaputo@pengaru.com>
To: trix@redhat.com
Cc: stern@rowland.harvard.edu, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] usb: storage: initialize variable
Date: Mon, 24 Aug 2020 14:18:39 -0700	[thread overview]
Message-ID: <20200824211839.6c7m7yhgd7ffq3g3@shells.gnugeneration.com> (raw)
In-Reply-To: <20200824211027.11543-1-trix@redhat.com>

On Mon, Aug 24, 2020 at 02:10:27PM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> clang static analysis reports this representative problem
> 
> transport.c:495:15: warning: Assigned value is garbage or
>   undefined
>         length_left -= partial;
>                    ^  ~~~~~~~
> partial is set only when usb_stor_bulk_transfer_sglist()
> is successful.
> 
> So set partial on entry to 0.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/usb/storage/transport.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
> index 238a8088e17f..044429717dcc 100644
> --- a/drivers/usb/storage/transport.c
> +++ b/drivers/usb/storage/transport.c
> @@ -414,6 +414,9 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
>  {
>  	int result;
>  
> +	if (act_len)
> +		*act_len = 0;
> +
>  	/* don't submit s-g requests during abort processing */
>  	if (test_bit(US_FLIDX_ABORTING, &us->dflags))
>  		return USB_STOR_XFER_ERROR;

At a glance this seems odd to me.  If the caller insists on ignoring
the return value, shouldn't it just initialize partial to zero?

In my experience it's generally frowned upon for functions to store
results in error paths.

Regards,
Vito Caputo

  reply	other threads:[~2020-08-24 21:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 21:10 trix
2020-08-24 21:18 ` Vito Caputo [this message]
2020-08-24 21:31   ` Tom Rix
2020-08-25  0:36     ` Alan Stern
2020-08-25  0:35   ` Alan Stern

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=20200824211839.6c7m7yhgd7ffq3g3@shells.gnugeneration.com \
    --to=vcaputo@pengaru.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=trix@redhat.com \
    --cc=usb-storage@lists.one-eyed-alien.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®