Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1260473pxa; Sat, 22 Aug 2020 18:13:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw867IbXdKlS/di1KguXt1hgFcjzrIMHbagDgOWGdHG01nkxGq7wCoaWFWDL4TqCaU7Hmp1 X-Received: by 2002:a17:906:2542:: with SMTP id j2mr92246ejb.442.1598145190076; Sat, 22 Aug 2020 18:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598145190; cv=none; d=google.com; s=arc-20160816; b=0ca2T2Cgag1d0B5ftlO4zSEqvMZbBfVY9FoRcZFpaRFQgHucuT6//E47Qpmpb6EqxU 2xH524xGImNIQ6WUMCbps2TFUm+q6OaXmaLdC4pzW4r46gFCITOMmCqXAA7pgq11gXrJ tphZRe5ExHMBAiznyS69gg6jpe5UEwObatom6bXFWMVFmXYdlR8nxLcqCqDUHAEmAWvZ wwgn8myX7b7TZ7oFScw7MXm+6mHQD9ffkzpS7AWXafzdw+Z+PdLV8LK6gA8+zpAWs+h1 RGAYVYt4lKbk8kI0iTYRJ7TQ07KuWyiyMaXjHL7/+/OJdYiaBtTyVZvAaz39y0pikXlc 12VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=b/NoN2xPN+oCMQvN072HgsZ8oJoZ1Sf3G/dUMxZJqCA=; b=AQr587slj/HDEAxcJFTp7Nvbv39GBiJ12APwU/BqEfZ6k5jqanuvEnf2DRoH4GRgtt WSHVoAdwzShZ0H0794AmN+ah2ujXMsghmzaX0khKXwPRruDNmTxxaA01J9ENuWx/a6/I S3of159wH8m7AB8D/G6DvdKapi1d8aIuOZWkWU9M10vtI/Z+rhWKNNkgywY9bmKYIiB7 4MQSYTGiPK6KYp+zRF561QWASxr83nQI2Jec8YWRx2BmRFm95bpQJJFJTsK/rbGZZkPP JY4Hi48b9G5D10MVrWKR525+JjFTpZdGpzebkX+STusNx1vLGQVcnM9KwE+ZVgJF+t5f zFag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz6si4911238edb.254.2020.08.22.18.12.46; Sat, 22 Aug 2020 18:13:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725924AbgHWAtE (ORCPT + 99 others); Sat, 22 Aug 2020 20:49:04 -0400 Received: from netrider.rowland.org ([192.131.102.5]:50219 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725768AbgHWAtE (ORCPT ); Sat, 22 Aug 2020 20:49:04 -0400 Received: (qmail 292705 invoked by uid 1000); 22 Aug 2020 20:49:03 -0400 Date: Sat, 22 Aug 2020 20:49:03 -0400 From: Alan Stern To: trix@redhat.com 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 Message-ID: <20200823004903.GB292576@rowland.harvard.edu> References: <20200822211839.5117-1-trix@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200822211839.5117-1-trix@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 22, 2020 at 02:18:39PM -0700, trix@redhat.com wrote: > From: Tom Rix > > 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 > --- > 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. Alan Stern