1. 26 1月, 2013 2 次提交
    • A
      USB: EHCI: unlink one async QH at a time · 6e0c3339
      Alan Stern 提交于
      This patch (as1648) fixes a regression affecting nVidia EHCI
      controllers.  Evidently they don't like to have more than one async QH
      unlinked at a time.  I can't imagine how they manage to mess it up,
      but at least one of them does.
      
      The patch changes the async unlink logic in two ways:
      
      	Each time an IAA cycle is started, only the first QH on the
      	async unlink list is handled (rather than all of them).
      
      	Async QHs do not all get unlinked as soon as they have been
      	empty for long enough.  Instead, only the last one (i.e., the
      	one that has been on the schedule the longest) is unlinked,
      	and then only if no other unlinks are in progress at the time.
      
      This means that when multiple QHs are empty, they won't be unlinked as
      quickly as before.  That's okay; it won't affect correct operation of
      the driver or add an excessive load.  Multiple unlinks tend to be
      relatively rare in any case.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-and-tested-by: NPiergiorgio Sartor <piergiorgio.sartor@nexgo.de>
      Cc: stable <stable@vger.kernel.org> # 3.6
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6e0c3339
    • A
      USB: EHCI: remove ASS/PSS polling timeout · 55bcdce8
      Alan Stern 提交于
      This patch (as1647) attempts to work around a problem that seems to
      affect some nVidia EHCI controllers.  They sometimes take a very long
      time to turn off their async or periodic schedules.  I don't know if
      this is a result of other problems, but in any case it seems wise not
      to depend on schedule enables or disables taking effect in any
      specific length of time.
      
      The patch removes the existing 20-ms timeout for enabling and
      disabling the schedules.  The driver will now continue to poll the
      schedule state at 1-ms intervals until the controller finally decides
      to obey the most recent command issued by the driver.  Just in case
      this hides a problem, a debugging message will be logged if the
      controller takes longer than 20 polls.
      
      I don't know if this will actually fix anything, but it can't hurt.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Tested-by: NPiergiorgio Sartor <piergiorgio.sartor@nexgo.de>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      55bcdce8
  2. 25 1月, 2013 5 次提交
    • D
      usb: Prevent dead ports when xhci is not enabled · 58b2939b
      David Moore 提交于
      When the xHCI driver is not available, actively switch the ports to EHCI
      mode since some BIOSes leave them in xHCI mode where they would
      otherwise appear dead.  This was discovered on a  Dell Optiplex 7010,
      but it's possible other systems could be affected.
      
      This should be backported to kernels as old as 3.0, that contain the
      commit 69e848c2 "Intel xhci: Support
      EHCI/xHCI port switching."
      Signed-off-by: NDavid Moore <david.moore@gmail.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      58b2939b
    • A
      USB: XHCI: fix memory leak of URB-private data · 48c3375c
      Alan Stern 提交于
      This patch (as1640) fixes a memory leak in xhci-hcd.  The urb_priv
      data structure isn't always deallocated in the handle_tx_event()
      routine for non-control transfers.  The patch adds a kfree() call so
      that all paths end up freeing the memory properly.
      
      This patch should be backported to kernels as old as 2.6.36, that
      contain the commit 8e51adcc "USB: xHCI:
      Introduce urb_priv structure"
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Reported-and-tested-by: NMartin Mokrejs <mmokrejs@fold.natur.cuni.cz>
      CC: <stable@vger.kernel.org>
      48c3375c
    • N
      drivers: xhci: fix incorrect bit test · ba7b5c22
      Nickolai Zeldovich 提交于
      Fix incorrect bit test that originally showed up in
      4ee823b8 "USB/xHCI: Support
      device-initiated USB 3.0 resume."
      
      Use '&' instead of '&&'.
      
      This should be backported to kernels as old as 3.4.
      Signed-off-by: NNickolai Zeldovich <nickolai@csail.mit.edu>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      ba7b5c22
    • S
      xhci: Fix TD size for isochronous URBs. · f18f8ed2
      Sarah Sharp 提交于
      To calculate the TD size for a particular TRB in an isoc TD, we need
      know the endpoint's max packet size.  Isochronous endpoints also encode
      the number of additional service opportunities in their wMaxPacketSize
      field.  The TD size calculation did not mask off those bits before using
      the field.  This resulted in incorrect TD size information for
      isochronous TRBs when an URB frame buffer crossed a 64KB boundary.
      
      For example:
       - an isoc endpoint has 2 additional service opportunites and
         a max packet size of 1020 bytes
       - a frame transfer buffer contains 3060 bytes
       - one frame buffer crosses a 64KB boundary, and must be split into
         one 1276 byte TRB, and one 1784 byte TRB.
      
      The TD size is is the number of packets that remain to be transferred
      for a TD after processing all the max packet sized packets in the
      current TRB and all previous TRBs.
      
      For this TD, the number of packets to be transferred is (3060 / 1020),
      or 3.  The first TRB contains 1276 bytes, which means it contains one
      full packet, and a 256 byte remainder.  After processing all the max
      packet-sized packets in the first TRB, the host will have 2 packets left
      to transfer.
      
      The old code would calculate the TD size for the first TRB as:
      
      total packet count = DIV_ROUND_UP (TD length / endpoint wMaxPacketSize)
      total packet count - (first TRB length / endpoint wMaxPacketSize)
      
      The math should have been:
      
      total packet count = DIV_ROUND_UP (3060 / 1020) = 3
      3 - (1276 / 1020) = 2
      
      Since the old code didn't mask off the additional service interval bits
      from the wMaxPacketSize field, the math ended up as
      
      total packet count = DIV_ROUND_UP (3060 / 5116) = 1
      1 - (1276 / 5116) = 1
      
      Fix this by masking off the number of additional service opportunities
      in the wMaxPacketSize field.
      
      This patch should be backported to stable kernels as old as 3.0, that
      contain the commit 4da6e6f2 "xhci 1.0:
      Update TD size field format."  It may not apply well to kernels older
      than 3.2 because of commit 29cc8897
      "USB: use usb_endpoint_maxp() instead of le16_to_cpu()".
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      f18f8ed2
    • S
      xhci: Fix isoc TD encoding. · 760973d2
      Sarah Sharp 提交于
      An isochronous TD is comprised of one isochronous TRB chained to zero or
      more normal TRBs.  Only the isoc TRB has the TBC and TLBPC fields.  The
      normal TRBs must set those fields to zeroes.  The code was setting the
      TBC and TLBPC fields for both isoc and normal TRBs.  Fix this.
      
      This should be backported to stable kernels as old as 3.0, that contain
      the commit b61d378f " xhci 1.0: Set
      transfer burst last packet count field."
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      760973d2
  3. 24 1月, 2013 1 次提交
    • A
      USB: EHCI: fix build error in ehci-mxc · dba63b2f
      Alan Stern 提交于
      This patch (as1643b) fixes a build error in ehci-hcd when compiling for
      ARM with allmodconfig:
      
      drivers/usb/host/ehci-hcd.c:1285:0: warning: "PLATFORM_DRIVER" redefined [enabled by default]
      drivers/usb/host/ehci-hcd.c:1255:0: note: this is the location of the previous definition
      drivers/usb/host/ehci-mxc.c:280:31: warning: 'ehci_mxc_driver' defined but not used [-Wunused-variable]
      drivers/usb/host/ehci-hcd.c:1285:0: warning: "PLATFORM_DRIVER" redefined [enabled by default]
      drivers/usb/host/ehci-hcd.c:1255:0: note: this is the location of the previous definition
      
      The fix is to convert ehci-mxc over to the new "ehci-hcd is a library"
      scheme so that it can coexist peacefully with the ehci-platform
      driver.  As part of the conversion the ehci_mxc_priv data structure,
      which was allocated dynamically, is now placed where it belongs: in
      the private area at the end of struct ehci_hcd.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Tested-by: NShawn Guo <shawn.guo@linaro.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dba63b2f
  4. 23 1月, 2013 4 次提交
  5. 12 1月, 2013 4 次提交
    • F
      usb: host: ohci-tmio: fix compile warning · 8e8de5ab
      Felipe Balbi 提交于
      Fix the following compile warning:
      
      In file included from drivers/usb/host/ohci-hcd.c:1170:0:
      drivers/usb/host/ohci-tmio.c: In function 'tmio_start_hc':
      drivers/usb/host/ohci-tmio.c:130:2: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type 'resource_size_t' [-Wformat]
      
      seen on ARM 32-bit builds.
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8e8de5ab
    • A
      USB: ehci-fsl: fix regression on mpc5121e · f66dea70
      Anatolij Gustschin 提交于
      mpc5121e doesn't have system interface registers, accessing this
      register address space cause the machine check exception and a
      kernel crash:
      
      ...
      Machine check in kernel mode.
      Caused by (from SRR1=49030): Transfer error ack signal
      Oops: Machine check, sig: 7 [#1]
      MPC5121 ADS
      Modules linked in:
      NIP: c025fd60 LR: c0265bb4 CTR: 00000000
      REGS: df82dac0 TRAP: 0200   Not tainted
      (3.7.0-rc7-00641-g81e6c91)
      MSR: 00049030 <EE,ME,IR,DR>  CR: 42002024  XER: 20000000
      TASK = df824b70[1] 'swapper' THREAD: df82c000
      GPR00: 00000000 df82db70 df824b70 df3ed0f0 00000003 00000000 00000000 00000000
      GPR08: 00000020 32000000 c03550ec 20000000 22002028 00000000 c0003f5c 00000000
      GPR16: 00000000 00000000 00000000 00000000 00000000 00000000 c0423898 c0450000
      GPR24: 00000077 00000002 e5086180 1c000c00 e5086000 df33ec00 00000003 df34e000
      NIP [c025fd60] ehci_fsl_setup_phy+0xd0/0x354
      LR [c0265bb4] ehci_fsl_setup+0x220/0x284
      ...
      
      Fix it by checking 'have_sysif_regs' flag before register access.
      Signed-off-by: NAnatolij Gustschin <agust@denx.de>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f66dea70
    • A
      USB: fsl-mph-dr-of: fix regression on mpc5121e · 7c1029ba
      Anatolij Gustschin 提交于
      fsl-ehci probing fails on mpc5121e:
      ...
      ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
      fsl-ehci fsl-ehci.0: Freescale On-Chip EHCI Host Controller
      fsl-ehci fsl-ehci.0: new USB bus registered, assigned bus number 1
      fsl-ehci fsl-ehci.0: Could not get controller version
      fsl-ehci fsl-ehci.0: can't setup
      fsl-ehci fsl-ehci.0: USB bus 1 deregistered
      fsl-ehci fsl-ehci.0: init fsl-ehci.0 fail, -22
      fsl-ehci: probe of fsl-ehci.0 failed with error -22
      
      Fix it by returning appropriate version info for mpc5121, too.
      Signed-off-by: NAnatolij Gustschin <agust@denx.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c1029ba
    • F
      usb: imx21-hcd: Include missing linux/module.h · bbc0313d
      Fabio Estevam 提交于
      Include <linux/module.h>, so that the following errors are fixed:
      
      drivers/usb/host/imx21-hcd.c:1929:20: error: expected declaration specifiers or '...' before string constant
      drivers/usb/host/imx21-hcd.c:1930:15: error: expected declaration specifiers or '...' before string constant
      drivers/usb/host/imx21-hcd.c:1931:16: error: expected declaration specifiers or '...' before string constant
      drivers/usb/host/imx21-hcd.c:1932:14: error: expected declaration specifiers or '...' before string constant
      Signed-off-by: NFabio Estevam <fabio.estevam@freescale.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bbc0313d
  6. 08 1月, 2013 1 次提交
  7. 04 1月, 2013 4 次提交
    • G
      Drivers: usb: host: ehci-orion.c: remove __devinitdata marking · 59a609a9
      Greg Kroah-Hartman 提交于
      This snuck in from a different tree during the merge and needs to be
      removed.
      
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      59a609a9
    • S
      xhci: Avoid "dead ports", add roothub port polling. · c52804a4
      Sarah Sharp 提交于
      The USB core hub thread (khubd) is designed with external USB hubs in
      mind.  It expects that if a port status change bit is set, the hub will
      continue to send a notification through the hub status data transfer.
      Basically, it expects hub notifications to be level-triggered.
      
      The xHCI host controller is designed to be edge-triggered on the logical
      'OR' of all the port status change bits.  When all port status change
      bits are clear, and a new change bit is set, the xHC will generate a
      Port Status Change Event.  If another change bit is set in the same port
      status register before the first bit is cleared, it will not send
      another event.
      
      This means that the hub code may lose port status changes because of
      race conditions between clearing change bits.  The user sees this as a
      "dead port" that doesn't react to device connects.
      
      The fix is to turn on port polling whenever a new change bit is set.
      Once the USB core issues a hub status request that shows that no change
      bits are set in any USB ports, turn off port polling.
      
      We can't allow the USB core to poll the roothub for port events during
      host suspend because if the PCI host is in D3cold, the port registers
      will be all f's.  Instead, stop the port polling timer, and
      unconditionally restart it when the host resumes.  If there are no port
      change bits set after the resume, the first call to hub_status_data will
      disable polling.
      
      This patch should be backported to stable kernels with the first xHCI
      support, 2.6.31 and newer, that include the commit
      0f2a7930 "USB: xhci: Root hub support."
      There will be merge conflicts because the check for HC_STATE_SUSPENDED
      was moved into xhci_suspend in 3.8.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Cc: stable@vger.kernel.org
      c52804a4
    • S
      USB: Allow USB 3.0 ports to be disabled. · 41e7e056
      Sarah Sharp 提交于
      If hot and warm reset fails, or a port remains in the Compliance Mode,
      the USB core needs to be able to disable a USB 3.0 port.  Unlike USB 2.0
      ports, once the port is placed into the Disabled link state, it will not
      report any new device connects.  To get device connect notifications, we
      need to put the link into the Disabled state, and then the RxDetect
      state.
      
      The xHCI driver needs to atomically clear all change bits on USB 3.0
      port disable, so that we get Port Status Change Events for future port
      changes.  We could technically do this in the USB core instead of in the
      xHCI roothub code, since the port state machine can't advance out of the
      disabled state until we set the link state to RxDetect.  However,
      external USB 3.0 hubs don't need this code.  They are level-triggered,
      not edge-triggered like xHCI, so they will continue to send interrupt
      events when any change bit is set.  Therefore it doesn't make sense to
      put this code in the USB core.
      
      This patch is part of a series to fix several reports of infinite loops
      on device enumeration failure.  This includes John, when he boots with
      a USB 3.0 device (Roseweil eusb3 enclosure) attached to his NEC 0.96
      host controller.  The fix requires warm reset support, so it does not
      make sense to backport this patch to stable kernels without warm reset
      support.
      
      This patch should be backported to kernels as old as 3.2, contain the
      commit ID 75d7cf72 "usbcore: refine warm
      reset logic"
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: NJohn Covici <covici@ccs.covici.com>
      Cc: stable@vger.kernel.org
      41e7e056
    • S
      xhci: Handle HS bulk/ctrl endpoints that don't NAK. · 55c1945e
      Sarah Sharp 提交于
      A high speed control or bulk endpoint may have bInterval set to zero,
      which means it does not NAK.  If bInterval is non-zero, it means the
      endpoint NAKs at a rate of 2^(bInterval - 1).
      
      The xHCI code to compute the NAK interval does not handle the special
      case of zero properly.  The current code unconditionally subtracts one
      from bInterval and uses it as an exponent.  This causes a very large
      bInterval to be used, and warning messages like these will be printed:
      
      usb 1-1: ep 0x1 - rounding interval to 32768 microframes, ep desc says 0 microframes
      
      This may cause the xHCI host hardware to reject the Configure Endpoint
      command, which means the HS device will be unusable under xHCI ports.
      
      This patch should be backported to kernels as old as 2.6.31, that contain
      commit dfa49c4a "USB: xhci - fix math in
      xhci_get_endpoint_interval()".
      Reported-by: NVincent Pelletier <plr.vincent@gmail.com>
      Suggested-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      55c1945e
  8. 13 12月, 2012 1 次提交
  9. 29 11月, 2012 1 次提交
  10. 27 11月, 2012 1 次提交
    • A
      USB: OHCI: workaround for hardware bug: retired TDs not added to the Done Queue · 50ce5c06
      Alan Stern 提交于
      This patch (as1636) is a partial workaround for a hardware bug
      affecting OHCI controllers by NVIDIA at least, maybe others too.  When
      the controller retires a Transfer Descriptor, it is supposed to add
      the TD onto the Done Queue.  But sometimes this doesn't happen, with
      the result that ohci-hcd never realizes the corresponding transfer has
      finished.  Symptoms can vary; a typical result is that USB audio stops
      working after a while.
      
      The patch works around the problem by recognizing that TDs are always
      processed in order.  Therefore, if a later TD is found on the Done
      Queue than all the earlier TDs for the same endpoint must be finished
      as well.
      
      Unfortunately this won't solve the problem in cases where the missing
      TD is the last one in the endpoint's queue.  A complete fix would
      require a signficant amount of change to the driver.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Tested-by: NOliver Neukum <oneukum@suse.de>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      50ce5c06
  11. 24 11月, 2012 1 次提交
  12. 22 11月, 2012 5 次提交
  13. 15 11月, 2012 4 次提交
  14. 14 11月, 2012 1 次提交
  15. 13 11月, 2012 5 次提交
    • F
      usb: host: xhci: move HC_STATE_SUSPENDED check to xhci_suspend() · 77b84767
      Felipe Balbi 提交于
      that check will have to be done by all users
      of xhci_suspend() so it sounds a lot better to
      move the check to xhci_suspend() in order to
      avoid code duplication.
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      77b84767
    • A
      usb: host: xhci: Stricter conditional for Z1 system models for Compliance Mode Patch · b0e4e606
      Alexis R. Cortes 提交于
      This minor patch creates a more stricter conditional for the Z1 sytems for applying
      the Compliance Mode Patch, this to avoid the quirk to be applied to models that
      contain a "Z1" in their dmi product string but are different from Z1 systems.
      
      This patch should be backported to stable kernels as old as 3.2, that
      contain the commit 71c731a2 "usb: host:
      xhci: Fix Compliance Mode on SN65LVPE502CP Hardware"
      Signed-off-by: NAlexis R. Cortes <alexis.cortes@ti.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      b0e4e606
    • S
      xhci: Extend Fresco Logic MSI quirk. · bba18e33
      Sarah Sharp 提交于
      Ali reports that plugging a device into the Fresco Logic xHCI host with
      PCI device ID 1400 produces an IRQ error:
      
       do_IRQ: 3.176 No irq handler for vector (irq -1)
      
      Other early Fresco Logic host revisions don't support MSI, even though
      their PCI config space claims they do.  Extend the quirk to disabling
      MSI to this chipset revision.  Also enable the short transfer quirk,
      since it's likely this revision also has that quirk, and it should be
      harmless to enable.
      
      04:00.0 0c03: 1b73:1400 (rev 01) (prog-if 30 [XHCI])
              Subsystem: 1d5c:1000
              Physical Slot: 3
              Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
              Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
              Latency: 0, Cache Line Size: 64 bytes
              Interrupt: pin A routed to IRQ 51
              Region 0: Memory at d4600000 (32-bit, non-prefetchable) [size=64K]
              Capabilities: [50] Power Management version 3
                      Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold-)
                      Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-
              Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
                      Address: 00000000feeff00c  Data: 41b1
              Capabilities: [80] Express (v1) Endpoint, MSI 00
                      DevCap: MaxPayload 128 bytes, PhantFunc 0, Latency L0s <2us, L1 <32us
                              ExtTag- AttnBtn- AttnInd- PwrInd- RBE+ FLReset-
                      DevCtl: Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
                              RlxdOrd+ ExtTag- PhantFunc- AuxPwr- NoSnoop+
                              MaxPayload 128 bytes, MaxReadReq 512 bytes
                      DevSta: CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr- TransPend-
                      LnkCap: Port #0, Speed 2.5GT/s, Width x1, ASPM L0s L1, Latency L0 unlimited, L1 unlimited
                              ClockPM- Surprise- LLActRep- BwNot-
                      LnkCtl: ASPM Disabled; RCB 64 bytes Disabled- Retrain- CommClk+
                              ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
                      LnkSta: Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
              Kernel driver in use: xhci_hcd
      
      This patch should be backported to stable kernels as old as 2.6.36, that
      contain the commit f5182b41 "xhci:
      Disable MSI for some Fresco Logic hosts."
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Reported-by: NA Sh <smr.ash1991@gmail.com>
      Tested-by: NA Sh <smr.ash1991@gmail.com>
      Cc: stable@vger.kernel.org
      bba18e33
    • J
      xhci: fix null-pointer dereference when destroying half-built segment rings · 68e5254a
      Julius Werner 提交于
      xhci_alloc_segments_for_ring() builds a list of xhci_segments and links
      the tail to head at the end (forming a ring). When it bails out for OOM
      reasons half-way through, it tries to destroy its half-built list with
      xhci_free_segments_for_ring(), even though it is not a ring yet. This
      causes a null-pointer dereference upon hitting the last element.
      
      Furthermore, one of its callers (xhci_ring_alloc()) mistakenly believes
      the output parameters to be valid upon this kind of OOM failure, and
      calls xhci_ring_free() on them. Since the (incomplete) list/ring should
      already be destroyed in that case, this would lead to a use after free.
      
      This patch fixes those issues by having xhci_alloc_segments_for_ring()
      destroy its half-built, non-circular list manually and destroying the
      invalid struct xhci_ring in xhci_ring_alloc() with a plain kfree().
      
      This patch should be backported to kernels as old as 2.6.31, that
      contains the commit 0ebbab37 "USB: xhci:
      Ring allocation and initialization."
      
      A separate patch will need to be developed for kernels older than 3.4,
      since the ring allocation code was refactored in that kernel.
      Signed-off-by: NJulius Werner <jwerner@chromium.org>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      68e5254a
    • S
      xHCI: Fix TD Size calculation on 1.0 hosts. · 4525c0a1
      Sarah Sharp 提交于
      The xHCI 1.0 specification made a change to the TD Size field in TRBs.
      The value is now the number of packets that remain to be sent in the TD,
      not including this TRB.  The TD Size value for the last TRB in a TD must
      always be zero.
      
      The xHCI function xhci_v1_0_td_remainder() attempts to calculate this,
      but it gets it wrong.  First, it erroneously reuses the old
      xhci_td_remainder function, which will right shift the value by 10.  The
      xHCI 1.0 spec as of June 2011 says nothing about right shifting by 10.
      Second, it does not set the TD size for the last TRB in a TD to zero.
      
      Third, it uses roundup instead of DIV_ROUND_UP.  The total packet count
      is supposed to be the total number of bytes in this TD, divided by the
      max packet size, rounded up.  DIV_ROUND_UP is the right function to use
      in that case.
      
      With the old code, a TD on an endpoint with max packet size 1024 would
      be set up like so:
      TRB 1, TRB length = 600 bytes, TD size = 0
      TRB 1, TRB length = 200 bytes, TD size = 0
      TRB 1, TRB length = 100 bytes, TD size = 0
      
      With the new code, the TD would be set up like this:
      TRB 1, TRB length = 600 bytes, TD size = 1
      TRB 1, TRB length = 200 bytes, TD size = 1
      TRB 1, TRB length = 100 bytes, TD size = 0
      
      This commit should be backported to kernels as old as 3.0, that contain
      the commit 4da6e6f2 "xhci 1.0: Update TD
      size field format."
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Reported-by: NChintan Mehta <chintan.mehta@sibridgetech.com>
      Reported-by: NShimmer Huang <shimmering.h@gmail.com>
      Tested-by: NBhavik Kothari <bhavik.kothari@sibridgetech.com>
      Tested-by: NShimmer Huang <shimmering.h@gmail.com>
      Cc: stable@vger.kernel.org
      4525c0a1