mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: dtor@vmware.com, micah@vmware.com, sarah.a.sharp@linux.intel.com,
	gregkh@suse.de, ak@linux.intel.com, linux-kernel@vger.kernel.org,
	stable@kernel.org, tim.bird@am.sony.com
Subject: [PATCH] [77/106] USB: xhci - fix math in xhci_get_endpoint_interval()
Date: Tue, 26 Apr 2011 14:13:58 -0700 (PDT)	[thread overview]
Message-ID: <20110426211358.C58BB3E1886@tassilo.jf.intel.com> (raw)
In-Reply-To: <20110426212.641772347@firstfloor.org>

2.6.35-longterm review patch.  If anyone has any objections, please let me 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>
Signed-off-by: Andi Kleen <ak@linux.intel.com>

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

Index: linux-2.6.35.y/drivers/usb/host/xhci-mem.c
===================================================================
--- linux-2.6.35.y.orig/drivers/usb/host/xhci-mem.c
+++ linux-2.6.35.y/drivers/usb/host/xhci-mem.c
@@ -961,6 +961,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
@@ -978,43 +1019,35 @@ 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, "
-						"ep desc says %d microframes\n",
-						ep->desc.bEndpointAddress,
-						1 << interval,
-						8*ep->desc.bInterval);
+		    usb_endpoint_xfer_isoc(&ep->desc)) {
+
+			interval = xhci_parse_frame_interval(udev, ep);
 		}
 		break;
 	default:

  parent reply	other threads:[~2011-04-26 21:24 UTC|newest]

Thread overview: 125+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-26 21:12 [PATCH] [0/106] 2.6.35.13 longterm review Andi Kleen
2011-04-26 21:12 ` [PATCH] [1/106] mm: page allocator: adjust the per-cpu counter threshold when memory is low Andi Kleen
2011-04-26 21:12 ` [PATCH] [2/106] qla2xxx: Make the FC port capability mutual exclusive Andi Kleen
2011-04-26 21:12 ` [PATCH] [3/106] staging: usbip: bugfixes related to kthread conversion Andi Kleen
2011-04-26 21:12 ` [PATCH] [4/106] staging: usbip: bugfix add number of packets for isochronous frames Andi Kleen
2011-04-26 21:12 ` [PATCH] [5/106] staging: usbip: bugfix for isochronous packets and optimization Andi Kleen
2011-04-26 21:12 ` [PATCH] [6/106] staging: hv: Fix GARP not sent after Quick Migration Andi Kleen
2011-04-26 21:12 ` [PATCH] [7/106] staging: hv: use sync_bitops when interacting with the hypervisor Andi Kleen
2011-04-26 21:12 ` [PATCH] [8/106] xfs: prevent leaking uninitialized stack memory in FSGEOMETRY_V1 Andi Kleen
2011-04-27  5:26   ` Dave Chinner
2011-04-27 15:00     ` Andi Kleen
2011-04-28  0:04       ` Dave Chinner
2011-04-26 21:12 ` [PATCH] [9/106] irda: validate peer name and attribute lengths Andi Kleen
2011-04-26 21:12 ` [PATCH] [10/106] irda: prevent heap corruption on invalid nickname Andi Kleen
2011-04-26 21:12 ` [PATCH] [11/106] nilfs2: fix data loss in mmap page write for hole blocks Andi Kleen
2011-04-26 21:12 ` [PATCH] [12/106] ASoC: Explicitly say registerless widgets have no register Andi Kleen
2011-04-26 21:12 ` [PATCH] [13/106] ALSA: ens1371: fix Creative Ectiva support Andi Kleen
2011-04-26 21:12 ` [PATCH] [14/106] ROSE: prevent heap corruption with bad facilities Andi Kleen
2011-04-26 21:12 ` [PATCH] [15/106] Btrfs: Fix uninitialized root flags for subvolumes Andi Kleen
2011-04-26 21:12 ` [PATCH] [16/106] x86, mtrr, pat: Fix one cpu getting out of sync during resume Andi Kleen
2011-04-26 21:12 ` [PATCH] [17/106] UBIFS: do not read flash unnecessarily Andi Kleen
2011-04-26 21:12 ` [PATCH] [18/106] UBIFS: fix oops on error path in read_pnode Andi Kleen
2011-04-26 21:12 ` [PATCH] [19/106] UBIFS: fix debugging failure in dbg_check_space_info Andi Kleen
2011-04-26 21:12 ` [PATCH] [20/106] quota: Don't write quota info in dquot_commit() Andi Kleen
2011-04-26 21:12 ` [PATCH] [21/106] mm: avoid wrapping vm_pgoff in mremap() Andi Kleen
2011-04-26 21:13 ` [PATCH] [22/106] p54usb: IDs for two new devices Andi Kleen
2011-04-26 21:13 ` [PATCH] [23/106] b43: allocate receive buffers big enough for max frame len + offset Andi Kleen
2011-04-26 21:13 ` [PATCH] [24/106] Bluetooth: sco: fix information leak to userspace Andi Kleen
2011-04-26 21:13 ` [PATCH] [25/106] bridge: netfilter: fix information leak Andi Kleen
2011-04-26 21:13 ` [PATCH] [26/106] Bluetooth: bnep: fix buffer overflow Andi Kleen
2011-04-26 21:13 ` [PATCH] [27/106] Bluetooth: add support for Apple MacBook Pro 8,2 Andi Kleen
2011-04-26 21:13 ` [PATCH] [28/106] Treat writes as new when holes span across page boundaries Andi Kleen
2011-04-26 21:13 ` [PATCH] [29/106] char/tpm: Fix unitialized usage of data buffer Andi Kleen
2011-04-26 21:13 ` [PATCH] [30/106] netfilter: ip_tables: fix infoleak to userspace Andi Kleen
2011-04-26 21:13 ` [PATCH] [31/106] netfilter: arp_tables: " Andi Kleen
2011-04-26 21:13 ` [PATCH] [32/106] netfilter: ipt_CLUSTERIP: fix buffer overflow Andi Kleen
2011-04-26 21:13 ` [PATCH] [33/106] ipv6: netfilter: ip6_tables: fix infoleak to userspace Andi Kleen
2011-04-26 21:13 ` [PATCH] [34/106] mfd: ab3100: world-writable debugfs *_priv files Andi Kleen
2011-04-26 21:13 ` [PATCH] [35/106] drivers/rtc/rtc-ds1511.c: world-writable sysfs nvram file Andi Kleen
2011-04-26 21:13 ` [PATCH] [36/106] drivers/misc/ep93xx_pwm.c: world-writable sysfs files Andi Kleen
2011-04-26 21:13 ` [PATCH] [37/106] econet: 4 byte infoleak to the network Andi Kleen
2011-04-26 21:13 ` [PATCH] [38/106] sound/oss: remove offset from load_patch callbacks Andi Kleen
2011-04-26 21:13 ` [PATCH] [39/106] sound: oss: midi_synth: check get_user() return value Andi Kleen
2011-04-26 21:13 ` [PATCH] [40/106] gro: Reset dev pointer on reuse Andi Kleen
2011-04-26 21:13 ` [PATCH] [41/106] gro: reset skb_iif " Andi Kleen
2011-04-26 21:13 ` [PATCH] [42/106] x86, microcode, AMD: Extend ucode size verification Andi Kleen
2011-04-26 22:44   ` Paul Gortmaker
2011-04-26 23:03     ` Andi Kleen
2011-04-26 21:13 ` [PATCH] [43/106] Squashfs: handle corruption of directory structure Andi Kleen
2011-04-26 21:13 ` [PATCH] [44/106] atm/solos-pci: Don't include frame pseudo-header on transmit hex-dump Andi Kleen
2011-04-26 21:13 ` [PATCH] [45/106] ext4: fix credits computing for indirect mapped files Andi Kleen
2011-04-26 21:13 ` [PATCH] [46/106] nfsd: fix auth_domain reference leak on nlm operations Andi Kleen
2011-04-26 21:13 ` [PATCH] [47/106] net: tipc: fix information leak to userland Andi Kleen
2011-04-26 21:13 ` [PATCH] [48/106] inet_diag: Make sure we actually run the same bytecode we audited Andi Kleen
2011-04-26 21:13 ` [PATCH] [49/106] irda: prevent integer underflow in IRLMP_ENUMDEVICES Andi Kleen
2011-04-26 21:13 ` [PATCH] [50/106] CAN: Use inode instead of kernel address for /proc file Andi Kleen
2011-04-26 21:13 ` [PATCH] [51/106] net: fix rds_iovec page count overflow Andi Kleen
2011-04-26 21:13 ` [PATCH] [52/106] xfs: zero proper structure size for geometry calls Andi Kleen
2011-04-26 21:13 ` [PATCH] [53/106] cifs: always do is_path_accessible check in cifs_mount Andi Kleen
2011-04-26 21:13 ` [PATCH] [54/106] video: sn9c102: world-wirtable sysfs files Andi Kleen
2011-04-26 21:13 ` [PATCH] [55/106] UBIFS: restrict world-writable debugfs files Andi Kleen
2011-04-26 21:13 ` [PATCH] [56/106] NET: cdc-phonet, handle empty phonet header Andi Kleen
2011-04-26 21:13 ` [PATCH] [57/106] x86: Fix a bogus unwind annotation in lib/semaphore_32.S Andi Kleen
2011-04-26 21:13 ` [PATCH] [58/106] tioca: Fix assignment from incompatible pointer warnings Andi Kleen
2011-04-26 21:13 ` [PATCH] [59/106] mca.c: Fix cast from integer to pointer warning Andi Kleen
2011-04-26 21:13 ` [PATCH] [60/106] ramfs: fix memleak on no-mmu arch Andi Kleen
2011-04-26 21:13 ` [PATCH] [61/106] MAINTAINERS: update STABLE BRANCH info Andi Kleen
2011-04-26 21:13 ` [PATCH] [62/106] UBIFS: fix oops when R/O file-system is fsync'ed Andi Kleen
2011-04-26 21:13 ` [PATCH] [63/106] x86, cpu: AMD errata checking framework Andi Kleen
2011-04-26 21:13 ` [PATCH] [64/106] x86, cpu: Clean up AMD erratum 400 workaround Andi Kleen
2011-04-26 21:13 ` [PATCH] [65/106] x86, AMD: Set ARAT feature on AMD processors Andi Kleen
2011-04-26 21:13 ` [PATCH] [66/106] x86, amd: Disable GartTlbWlkErr when BIOS forgets it Andi Kleen
2011-04-26 21:13 ` [PATCH] [67/106] USB: ftdi_sio: Added IDs for CTI USB Serial Devices Andi Kleen
2011-04-26 21:13 ` [PATCH] [68/106] USB: ftdi_sio: add PID for OCT DK201 docking station Andi Kleen
2011-04-26 21:13 ` [PATCH] [69/106] USB: ftdi_sio: add ids for Hameg HO720 and HO730 Andi Kleen
2011-04-26 21:13 ` [PATCH] [70/106] USB: option: Add new ONDA vendor id and product id for ONDA MT825UP Andi Kleen
2011-04-26 21:13 ` [PATCH] [71/106] USB: option: Added support for Samsung GT-B3730/GT-B3710 LTE USB modem Andi Kleen
2011-04-26 21:13 ` [PATCH] [72/106] next_pidmap: fix overflow condition Andi Kleen
2011-04-26 21:13 ` [PATCH] [73/106] proc: do proper range check on readdir offset Andi Kleen
2011-04-26 21:13 ` [PATCH] [74/106] USB: EHCI: unlink unused QHs when the controller is stopped Andi Kleen
2011-04-26 21:13 ` [PATCH] [75/106] USB: fix formatting of SuperSpeed endpoints in /proc/bus/usb/devices Andi Kleen
2011-04-26 21:13 ` [PATCH] [76/106] USB: xhci - fix unsafe macro definitions Andi Kleen
2011-04-26 21:13 ` Andi Kleen [this message]
2011-04-26 21:13 ` [PATCH] [78/106] x86, cpu: Fix regression in AMD errata checking code Andi Kleen
2011-04-26 21:14 ` [PATCH] [79/106] net: ax25: fix information leak to userland harder Andi Kleen
2011-04-26 21:14 ` [PATCH] [80/106] Input: synaptics - fix crash in synaptics_module_init() Andi Kleen
2011-04-26 21:14 ` [PATCH] [81/106] ath9k: fix a chip wakeup related crash in ath9k_start Andi Kleen
2011-04-26 21:14 ` [PATCH] [82/106] ath: add missing regdomain pair 0x5c mapping Andi Kleen
2011-04-26 21:14 ` [PATCH] [83/106] block, blk-sysfs: Fix an err return path in blk_register_queue() Andi Kleen
2011-04-26 21:14 ` [PATCH] [84/106] p54: Initialize extra_len in p54_tx_80211 Andi Kleen
2011-04-26 21:14 ` [PATCH] [85/106] x86, gart: Make sure GART does not map physmem above 1TB Andi Kleen
2011-04-26 21:14 ` [PATCH] [86/106] intel-iommu: Unlink domain from iommu Andi Kleen
2011-04-26 21:14 ` [PATCH] [87/106] intel-iommu: Fix get_domain_for_dev() error path Andi Kleen
2011-04-26 21:14 ` [PATCH] [88/106] drm/radeon/kms: fix bad shift in atom iio table parser Andi Kleen
2011-04-26 21:14 ` [PATCH] [89/106] NFS: nfs_wcc_update_inode() should set nfsi->attr_gencount Andi Kleen
2011-04-26 21:14 ` [PATCH] [90/106] serial/imx: read cts state only after acking cts change irq Andi Kleen
2011-04-26 21:14 ` [PATCH] [91/106] ASoC: Fix output PGA enabling in wm_hubs CODECs Andi Kleen
2011-04-26 21:14 ` [PATCH] [92/106] kconfig: Avoid buffer underrun in choice input Andi Kleen
2011-04-26 21:14 ` [PATCH] [93/106] UBIFS: fix master node recovery Andi Kleen
2011-04-26 21:14 ` [PATCH] [94/106] Remove extra struct page member from the buffer info structure Andi Kleen
2011-04-26 21:14 ` [PATCH] [95/106] dasd: correct device table Andi Kleen
2011-04-26 21:14 ` [PATCH] [96/106] iwlagn: Support new 5000 microcode Andi Kleen
2011-04-27 17:42   ` Tim Gardner
2011-04-27 20:47     ` Valdis.Kletnieks
2011-04-27 22:20       ` Andi Kleen
2011-04-27 22:32         ` wwguy
2011-04-27 22:41           ` Andi Kleen
2011-04-27 22:42             ` wwguy
2011-04-27 22:46               ` Andi Kleen
2011-04-28  2:42                 ` Tim Gardner
2011-04-26 21:14 ` [PATCH] [97/106] uvcvideo: Fix descriptor parsing for video output devices Andi Kleen
2011-04-26 21:14 ` [PATCH] [98/106] Revert "intel_idle: PCI quirk to prevent Lenovo Ideapad s10-3 boot hang" Andi Kleen
2011-04-26 21:14 ` [PATCH] [99/106] ALSA: hda - VIA: Add missing support for VT1718S in A-A path Andi Kleen
2011-04-26 21:14 ` [PATCH] [100/106] ALSA: hda - VIA: Fix stereo mixer recording no sound issue Andi Kleen
2011-04-26 21:14 ` [PATCH] [101/106] From: iwlwifi: fix skb usage after free Andi Kleen
2011-04-26 21:14 ` [PATCH] [102/106] From: intel-iommu: Fix use after release during device attach Andi Kleen
2011-04-26 21:14 ` [PATCH] [103/106] From: USB: Fix unplug of device with active streams Andi Kleen
2011-04-26 21:14 ` [PATCH] [104/106] From: USB: xhci - also free streams when resetting devices Andi Kleen
2011-04-26 21:14 ` [PATCH] [105/106] From: 2.6.35.y: Revert "SH: Add missing consts to sys_execve() declaration" Andi Kleen
2011-04-26 21:14 ` [PATCH] [106/106] Release 2.6.35.13 Andi Kleen
2011-04-27  0:08 ` [stable] [PATCH] [0/106] 2.6.35.13 longterm review Chuck Ebbert
2011-04-27  2:58   ` Andi Kleen
2011-04-27  0:17 ` Tim Bird
2011-04-27  0:21 ` [stable] " Chuck Ebbert
2011-04-27  3:08   ` Andi Kleen

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=20110426211358.C58BB3E1886@tassilo.jf.intel.com \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=dtor@vmware.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=micah@vmware.com \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stable@kernel.org \
    --cc=tim.bird@am.sony.com \
    /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®