mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Dmitry Torokhov <dtor@vmware.com>,
	Sarah Sharp <sarah.a.sharp@linux.intel.com>
Subject: [23/26] USB: xhci - fix math in xhci_get_endpoint_interval()
Date: Tue, 19 Apr 2011 14:02:39 -0700	[thread overview]
Message-ID: <20110419210324.696932202@clark.kroah.org> (raw)
In-Reply-To: <20110419210333.GA17417@kroah.com>

2.6.33-longterm review patch.  If anyone has any objections, please let us know.

------------------

From: Dmitry Torokhov <dtor@vmware.com>

commit dfa49c4ad120a784ef1ff0717168aa79f55a483a upstream.

When parsing exponent-expressed intervals we subtract 1 from the
value and then expect it to match with original + 1, which is
highly unlikely, and we end with frequent spew:

	usb 3-4: ep 0x83 - rounding interval to 512 microframes

Also, parsing interval for fullspeed isochronous endpoints was
incorrect - according to USB spec they use exponent-based
intervals (but xHCI spec claims frame-based intervals). I trust
USB spec more, especially since USB core agrees with it.

This should be queued for stable kernels back to 2.6.31.

Reviewed-by: Micah Elizabeth Scott <micah@vmware.com>
Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/usb/host/xhci-mem.c |   85 ++++++++++++++++++++++++++++++++------------
 1 file changed, 62 insertions(+), 23 deletions(-)

--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -492,6 +492,47 @@ int xhci_setup_addressable_virt_dev(stru
 	return 0;
 }
 
+/*
+ * Convert interval expressed as 2^(bInterval - 1) == interval into
+ * straight exponent value 2^n == interval.
+ *
+ */
+static unsigned int xhci_parse_exponent_interval(struct usb_device *udev,
+		struct usb_host_endpoint *ep)
+{
+	unsigned int interval;
+
+	interval = clamp_val(ep->desc.bInterval, 1, 16) - 1;
+	if (interval != ep->desc.bInterval - 1)
+		dev_warn(&udev->dev,
+			 "ep %#x - rounding interval to %d microframes\n",
+			 ep->desc.bEndpointAddress,
+			 1 << interval);
+
+	return interval;
+}
+
+/*
+ * Convert bInterval expressed in frames (in 1-255 range) to exponent of
+ * microframes, rounded down to nearest power of 2.
+ */
+static unsigned int xhci_parse_frame_interval(struct usb_device *udev,
+		struct usb_host_endpoint *ep)
+{
+	unsigned int interval;
+
+	interval = fls(8 * ep->desc.bInterval) - 1;
+	interval = clamp_val(interval, 3, 10);
+	if ((1 << interval) != 8 * ep->desc.bInterval)
+		dev_warn(&udev->dev,
+			 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n",
+			 ep->desc.bEndpointAddress,
+			 1 << interval,
+			 8 * ep->desc.bInterval);
+
+	return interval;
+}
+
 /* Return the polling or NAK interval.
  *
  * The polling interval is expressed in "microframes".  If xHCI's Interval field
@@ -509,40 +550,38 @@ static inline unsigned int xhci_get_endp
 	case USB_SPEED_HIGH:
 		/* Max NAK rate */
 		if (usb_endpoint_xfer_control(&ep->desc) ||
-				usb_endpoint_xfer_bulk(&ep->desc))
+		    usb_endpoint_xfer_bulk(&ep->desc)) {
 			interval = ep->desc.bInterval;
+			break;
+		}
 		/* Fall through - SS and HS isoc/int have same decoding */
+
 	case USB_SPEED_SUPER:
 		if (usb_endpoint_xfer_int(&ep->desc) ||
-				usb_endpoint_xfer_isoc(&ep->desc)) {
-			if (ep->desc.bInterval == 0)
-				interval = 0;
-			else
-				interval = ep->desc.bInterval - 1;
-			if (interval > 15)
-				interval = 15;
-			if (interval != ep->desc.bInterval + 1)
-				dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n",
-						ep->desc.bEndpointAddress, 1 << interval);
+		    usb_endpoint_xfer_isoc(&ep->desc)) {
+			interval = xhci_parse_exponent_interval(udev, ep);
 		}
 		break;
-	/* Convert bInterval (in 1-255 frames) to microframes and round down to
-	 * nearest power of 2.
-	 */
+
 	case USB_SPEED_FULL:
+		if (usb_endpoint_xfer_int(&ep->desc)) {
+			interval = xhci_parse_exponent_interval(udev, ep);
+			break;
+		}
+		/*
+		 * Fall through for isochronous endpoint interval decoding
+		 * since it uses the same rules as low speed interrupt
+		 * endpoints.
+		 */
+
 	case USB_SPEED_LOW:
 		if (usb_endpoint_xfer_int(&ep->desc) ||
-				usb_endpoint_xfer_isoc(&ep->desc)) {
-			interval = fls(8*ep->desc.bInterval) - 1;
-			if (interval > 10)
-				interval = 10;
-			if (interval < 3)
-				interval = 3;
-			if ((1 << interval) != 8*ep->desc.bInterval)
-				dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n",
-						ep->desc.bEndpointAddress, 1 << interval);
+		    usb_endpoint_xfer_isoc(&ep->desc)) {
+
+			interval = xhci_parse_frame_interval(udev, ep);
 		}
 		break;
+
 	default:
 		BUG();
 	}



  parent reply	other threads:[~2011-04-19 21:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-19 21:03 [00/26] 2.6.33.12-longterm review Greg KH
2011-04-19 21:02 ` [01/26] cifs: always do is_path_accessible check in cifs_mount Greg KH
2011-04-19 21:02 ` [02/26] [media] video: sn9c102: world-wirtable sysfs files Greg KH
2011-04-19 21:02 ` [03/26] UBIFS: restrict world-writable debugfs files Greg KH
2011-04-19 21:02 ` [04/26] NET: cdc-phonet, handle empty phonet header Greg KH
2011-04-19 21:02 ` [05/26] x86: Fix a bogus unwind annotation in lib/semaphore_32.S Greg KH
2011-04-19 21:02 ` [06/26] [IA64] tioca: Fix assignment from incompatible pointer warnings Greg KH
2011-04-19 21:02 ` [07/26] [IA64] mca.c: Fix cast from integer to pointer warning Greg KH
2011-04-19 21:02 ` [08/26] ramfs: fix memleak on no-mmu arch Greg KH
2011-04-19 21:02 ` [09/26] MAINTAINERS: update STABLE BRANCH info Greg KH
2011-04-19 21:02 ` [10/26] UBIFS: fix oops when R/O file-system is fsynced Greg KH
2011-04-19 21:02 ` [11/26] x86, AMD: Set ARAT feature on AMD processors Greg KH
2011-04-19 21:02 ` [12/26] x86, cpu: AMD errata checking framework Greg KH
2011-04-19 21:02 ` [13/26] x86, cpu: Clean up AMD erratum 400 workaround Greg KH
2011-04-19 21:02 ` [14/26] x86, amd: Disable GartTlbWlkErr when BIOS forgets it Greg KH
2011-04-19 21:02 ` [15/26] USB: ftdi_sio: Added IDs for CTI USB Serial Devices Greg KH
2011-04-19 21:02 ` [16/26] USB: ftdi_sio: add PID for OCT DK201 docking station Greg KH
2011-04-19 21:02 ` [17/26] USB: ftdi_sio: add ids for Hameg HO720 and HO730 Greg KH
2011-04-19 21:02 ` [18/26] next_pidmap: fix overflow condition Greg KH
2011-04-19 21:02 ` [19/26] proc: do proper range check on readdir offset Greg KH
2011-04-19 21:02 ` [20/26] USB: EHCI: unlink unused QHs when the controller is stopped Greg KH
2011-04-19 21:02 ` [21/26] USB: fix formatting of SuperSpeed endpoints in /proc/bus/usb/devices Greg KH
2011-04-19 21:02 ` [22/26] USB: xhci - fix unsafe macro definitions Greg KH
2011-04-19 21:02 ` Greg KH [this message]
2011-04-19 21:02 ` [24/26] x86, cpu: Fix regression in AMD errata checking code Greg KH
2011-04-19 21:02 ` [25/26] net: ax25: fix information leak to userland harder Greg KH
2011-04-19 21:02 ` [26/26] net: fix rds_iovec page count overflow Greg KH

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=20110419210324.696932202@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dtor@vmware.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®