linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-usb@vger.kernel.org, <john453@faraday-tech.com>
Subject: Re: [bug report] usb: host: Faraday fotg210-hcd driver
Date: Tue, 11 Feb 2020 10:24:33 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.2002111021330.1574-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <20200211150308.rqjujcicbx5obxd2@kili.mountain>

On Tue, 11 Feb 2020, Dan Carpenter wrote:

> Hello USB devs,
> 
> The patch 7d50195f6c50: "usb: host: Faraday fotg210-hcd driver" from
> Jul 29, 2013, leads to the following static checker warning:
> 
> 	drivers/usb/host/fotg210-hcd.c:3945 iso_stream_init()
> 	warn: mask and shift to zero
> 
> drivers/usb/host/fotg210-hcd.c
>   3922  static void iso_stream_init(struct fotg210_hcd *fotg210,
>   3923                  struct fotg210_iso_stream *stream, struct usb_device *dev,
>   3924                  int pipe, unsigned interval)
>   3925  {
>   3926          u32 buf1;
>   3927          unsigned epnum, maxp;
>   3928          int is_input;
>   3929          long bandwidth;
>   3930          unsigned multi;
>   3931  
>   3932          /*
>   3933           * this might be a "high bandwidth" highspeed endpoint,
>   3934           * as encoded in the ep descriptor's wMaxPacket field
>   3935           */
>   3936          epnum = usb_pipeendpoint(pipe);
>   3937          is_input = usb_pipein(pipe) ? USB_DIR_IN : 0;
>   3938          maxp = usb_maxpacket(dev, pipe, !is_input);
>   3939          if (is_input)
>   3940                  buf1 = (1 << 11);
>   3941          else
>   3942                  buf1 = 0;
>   3943  
>   3944          maxp = max_packet(maxp);
>   3945          multi = hb_mult(maxp);
>   3946          buf1 |= maxp;
>   3947          maxp *= multi;

This is pretty clearly a case of mistaken reuse of a local variable.  
The argument to hb_mult() should be the output from usb_maxpacket(), 
not the result of the max_packet() calculation.

>   3948  
>   3949          stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum);
>   3950          stream->buf1 = cpu_to_hc32(fotg210, buf1);
>   3951          stream->buf2 = cpu_to_hc32(fotg210, multi);
> 
> The problem is these two defines:
> 
> #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
> #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
> 
> 0x07ff >> 11 is always zero so multi is always 1.
> 
> Should we pass the original value that usb_maxpacket() returned instead
> of the masked value?

Yes.  I suggest introducing a new local variable and using it in place
of maxp in lines 3938, 3944 (the second occurrence), and 3945.

Alan Stern

> regards,
> dan carpenter


  reply	other threads:[~2020-02-11 15:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 15:03 [bug report] usb: host: Faraday fotg210-hcd driver Dan Carpenter
2020-02-11 15:24 ` Alan Stern [this message]
2020-02-11 15:47   ` 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=Pine.LNX.4.44L0.2002111021330.1574-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=dan.carpenter@oracle.com \
    --cc=john453@faraday-tech.com \
    --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;
as well as URLs for NNTP newsgroup(s).