Linux USB
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Desnes Nunes <desnesn@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	gregkh@linuxfoundation.org
Subject: Re: [PATCH 2/2] usb: storage: rearrange triple nested CSW data phase check
Date: Wed, 29 Oct 2025 21:59:55 -0400	[thread overview]
Message-ID: <a8f5302d-ed93-4b2f-a706-e7e2646986a3@rowland.harvard.edu> (raw)
In-Reply-To: <CACaw+eyo4Yc0=Ak=RWsozDVMzGHaZhW6SBHJUWFqRb6gPzWS8Q@mail.gmail.com>

On Wed, Oct 29, 2025 at 09:39:36PM -0300, Desnes Nunes wrote:
> Hello Alan,
> 
> On Wed, Oct 29, 2025 at 6:54 PM Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > On Wed, Oct 29, 2025 at 04:14:14PM -0300, Desnes Nunes wrote:
> > > This rearranges the triple nested CSW data phase if clause, in order to
> > > make usb_stor_Bulk_transport() code more readlable. No functional change.
> > >
> > > Signed-off-by: Desnes Nunes <desnesn@redhat.com>
> > > ---
> > >  drivers/usb/storage/transport.c | 21 ++++++++++-----------
> > >  1 file changed, 10 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
> > > index 96b81cf6adc7..3f2e1df5ad1e 100644
> > > --- a/drivers/usb/storage/transport.c
> > > +++ b/drivers/usb/storage/transport.c
> > > @@ -1188,18 +1188,17 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
> > >                * check whether it really is a CSW.
> > >                */
> > >               if (result == USB_STOR_XFER_SHORT &&
> > > -                             srb->sc_data_direction == DMA_FROM_DEVICE &&
> > > -                             transfer_length - scsi_get_resid(srb) ==
> > > -                                     US_BULK_CS_WRAP_LEN) {
> > > +                 srb->sc_data_direction == DMA_FROM_DEVICE &&
> > > +                 transfer_length - scsi_get_resid(srb) == US_BULK_CS_WRAP_LEN) {
> >
> > This change has nothing to do with the subject of the patch.  Please
> > leave the code the way it was.
> >
> > >                       struct scatterlist *sg = NULL;
> > > -                     unsigned int offset = 0;
> > > -
> > > -                     if (usb_stor_access_xfer_buf((unsigned char *) bcs,
> > > -                                     US_BULK_CS_WRAP_LEN, srb, &sg,
> > > -                                     &offset, FROM_XFER_BUF) ==
> > > -                                             US_BULK_CS_WRAP_LEN &&
> > > -                                     bcs->Signature ==
> > > -                                             cpu_to_le32(US_BULK_CS_SIGN)) {
> > > +                     unsigned int offset = 0, buflen = 0;
> >
> > It seems silly to initialize buflen to 0 when the very next statement is
> > going to overwrite that value.
> >
> > Also, "buflen" is not a good name for this variable, because the
> > variable does not contain the length of a buffer.  Rather, it will
> > contain the amount of data that got transferred by the
> > usb_stor_access_xfer_buf() routine.  The following "if" statement then
> > tests whether that amount is equal to the buffer length.
> >
> > Alan Stern
> 
> I tried to borrow some code from usb storage protocol, but after these
> observations I do agree it is not a good name here.
> Nonetheless, I will drop this patch from v2 as requested.

I didn't mean that the entire patch should be dropped, just the changes 
to the indentation of the first few lines.

As for the variable name, num_written or something like that would be 
preferable to buflen.  You can make up something better, or you can drop 
the entire patch -- your choice.

Alan Stern

      reply	other threads:[~2025-10-30  1:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 19:14 [PATCH 0/2] usb: storage: Fix memory leak in USB bulk transport Desnes Nunes
2025-10-29 19:14 ` [PATCH 1/2] " Desnes Nunes
2025-10-29 21:49   ` Alan Stern
2025-10-30  0:36     ` Desnes Nunes
2025-10-30  4:42       ` Desnes Nunes
2025-10-30 13:52         ` Alan Stern
2025-10-30 21:20           ` Desnes Nunes
2025-10-29 19:14 ` [PATCH 2/2] usb: storage: rearrange triple nested CSW data phase check Desnes Nunes
2025-10-29 21:54   ` Alan Stern
2025-10-30  0:39     ` Desnes Nunes
2025-10-30  1:59       ` Alan Stern [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=a8f5302d-ed93-4b2f-a706-e7e2646986a3@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=desnesn@redhat.com \
    --cc=gregkh@linuxfoundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox