From: Tom Rix <trix@redhat.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
usb-storage@lists.one-eyed-alien.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: storage: initialize variable
Date: Mon, 24 Aug 2020 06:13:09 -0700 [thread overview]
Message-ID: <34834bbc-12e5-3fe1-7bb3-7a4c03acb03f@redhat.com> (raw)
In-Reply-To: <20200823004903.GB292576@rowland.harvard.edu>
On 8/22/20 5:49 PM, Alan Stern wrote:
> On Sat, Aug 22, 2020 at 02:18:39PM -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 initialize to partial to 0.
>>
>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
>> drivers/usb/storage/transport.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
>> index 238a8088e17f..ce920851b1f2 100644
>> --- a/drivers/usb/storage/transport.c
>> +++ b/drivers/usb/storage/transport.c
>> @@ -461,7 +461,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
>> int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
>> struct scsi_cmnd* srb)
>> {
>> - unsigned int partial;
>> + unsigned int partial = 0;
>> int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
>> scsi_sg_count(srb), scsi_bufflen(srb),
>> &partial);
>> @@ -484,7 +484,7 @@ int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
>> void *buf, unsigned int length_left, int use_sg, int *residual)
>> {
>> int result;
>> - unsigned int partial;
>> + unsigned int partial = 0;
>>
>> /* are we scatter-gathering? */
>> if (use_sg) {
> Yes, this is a bug. But the right way to fix it is to change
> usb_stor_bulk_transfer_sglist(): Make it store 0 to *act_len at the
> start.
>
> That way you change only one localized piece of code, instead of
> changing multiple callers and leaving a possibility of more errors being
> added in the future.
I'll respin the patch.
It will exchange the compile time initialization fix for a run time if-check fix.
> Alan Stern
>
prev parent reply other threads:[~2020-08-24 13:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-22 21:18 [PATCH] usb: storage: initialize variable trix
2020-08-23 0:49 ` Alan Stern
2020-08-24 13:13 ` Tom Rix [this message]
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=34834bbc-12e5-3fe1-7bb3-7a4c03acb03f@redhat.com \
--to=trix@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--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