Skip to content

Commit 7c427f4

Browse files
committed
Merge tag 'usb-3.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB fixes from Greg KH: "Here are a number of fixes for the USB core and drivers for 3.4-rc2 Lots of tiny xhci fixes here, a few usb-serial driver fixes and new device ids, and a smattering of other minor fixes in different USB drivers. Signed-off-by: Greg Kroah-Hartman <[email protected]>" * tag 'usb-3.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (30 commits) USB: update usbtmc api documentation xHCI: Correct the #define XHCI_LEGACY_DISABLE_SMI xHCI: use gfp flags from caller instead of GFP_ATOMIC xHCI: add XHCI_RESET_ON_RESUME quirk for VIA xHCI host USB: fix bug of device descriptor got from superspeed device xhci: Fix register save/restore order. xhci: Restore event ring dequeue pointer on resume. xhci: Don't write zeroed pointers to xHC registers. xhci: Warn when hosts don't halt. xhci: don't re-enable IE constantly usb: xhci: fix section mismatch in linux-next xHCI: correct to print the true HSEE of USBCMD USB: serial: fix race between probe and open UHCI: hub_status_data should indicate if ports are resuming EHCI: keep track of ports being resumed and indicate in hub_status_data USB: fix race between root-hub suspend and remote wakeup USB: sierra: add support for Sierra Wireless MC7710 USB: ftdi_sio: fix race condition in TIOCMIWAIT, and abort of TIOCMIWAIT when the device is removed USB: ftdi_sio: fix status line change handling for TIOCMIWAIT and TIOCGICOUNT USB: don't ignore suspend errors for root hubs ...
2 parents f4f9c1a + 9de2922 commit 7c427f4

32 files changed

+216
-118
lines changed

Documentation/ABI/stable/sysfs-driver-usb-usbtmc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
What: /sys/bus/usb/drivers/usbtmc/devices/*/interface_capabilities
2-
What: /sys/bus/usb/drivers/usbtmc/devices/*/device_capabilities
1+
What: /sys/bus/usb/drivers/usbtmc/*/interface_capabilities
2+
What: /sys/bus/usb/drivers/usbtmc/*/device_capabilities
33
Date: August 2008
44
Contact: Greg Kroah-Hartman <[email protected]>
55
Description:
@@ -12,8 +12,8 @@ Description:
1212
The files are read only.
1313

1414

15-
What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_interface_capabilities
16-
What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_device_capabilities
15+
What: /sys/bus/usb/drivers/usbtmc/*/usb488_interface_capabilities
16+
What: /sys/bus/usb/drivers/usbtmc/*/usb488_device_capabilities
1717
Date: August 2008
1818
Contact: Greg Kroah-Hartman <[email protected]>
1919
Description:
@@ -27,7 +27,7 @@ Description:
2727
The files are read only.
2828

2929

30-
What: /sys/bus/usb/drivers/usbtmc/devices/*/TermChar
30+
What: /sys/bus/usb/drivers/usbtmc/*/TermChar
3131
Date: August 2008
3232
Contact: Greg Kroah-Hartman <[email protected]>
3333
Description:
@@ -40,7 +40,7 @@ Description:
4040
sent to the device or not.
4141

4242

43-
What: /sys/bus/usb/drivers/usbtmc/devices/*/TermCharEnabled
43+
What: /sys/bus/usb/drivers/usbtmc/*/TermCharEnabled
4444
Date: August 2008
4545
Contact: Greg Kroah-Hartman <[email protected]>
4646
Description:
@@ -51,7 +51,7 @@ Description:
5151
published by the USB-IF.
5252

5353

54-
What: /sys/bus/usb/drivers/usbtmc/devices/*/auto_abort
54+
What: /sys/bus/usb/drivers/usbtmc/*/auto_abort
5555
Date: August 2008
5656
Contact: Greg Kroah-Hartman <[email protected]>
5757
Description:

Documentation/usb/URB.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ that if the completion handler or anyone else tries to resubmit it
168168
they will get a -EPERM error. Thus you can be sure that when
169169
usb_kill_urb() returns, the URB is totally idle.
170170

171+
There is a lifetime issue to consider. An URB may complete at any
172+
time, and the completion handler may free the URB. If this happens
173+
while usb_unlink_urb or usb_kill_urb is running, it will cause a
174+
memory-access violation. The driver is responsible for avoiding this,
175+
which often means some sort of lock will be needed to prevent the URB
176+
from being deallocated while it is still in use.
177+
178+
On the other hand, since usb_unlink_urb may end up calling the
179+
completion handler, the handler must not take any lock that is held
180+
when usb_unlink_urb is invoked. The general solution to this problem
181+
is to increment the URB's reference count while holding the lock, then
182+
drop the lock and call usb_unlink_urb or usb_kill_urb, and then
183+
decrement the URB's reference count. You increment the reference
184+
count by calling
185+
186+
struct urb *usb_get_urb(struct urb *urb)
187+
188+
(ignore the return value; it is the same as the argument) and
189+
decrement the reference count by calling usb_free_urb. Of course,
190+
none of this is necessary if there's no danger of the URB being freed
191+
by the completion handler.
192+
171193

172194
1.7. What about the completion handler?
173195

Documentation/usb/usbmon.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ An input control transfer to get a port status.
183183
d5ea89a0 3575914555 S Ci:1:001:0 s a3 00 0000 0003 0004 4 <
184184
d5ea89a0 3575914560 C Ci:1:001:0 0 4 = 01050000
185185

186-
An output bulk transfer to send a SCSI command 0x5E in a 31-byte Bulk wrapper
187-
to a storage device at address 5:
186+
An output bulk transfer to send a SCSI command 0x28 (READ_10) in a 31-byte
187+
Bulk wrapper to a storage device at address 5:
188188

189-
dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 5e000000 00000000 00000600 00000000 00000000 00000000 000000
189+
dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 ad000000 00800000 80010a28 20000000 20000040 00000000 000000
190190
dd65f0e8 4128379808 C Bo:1:005:2 0 31 >
191191

192192
* Raw binary format and API

drivers/usb/Kconfig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
# USB device configuration
33
#
44

5-
menuconfig USB_SUPPORT
6-
bool "USB support"
7-
depends on HAS_IOMEM
8-
default y
9-
---help---
10-
This option adds core support for Universal Serial Bus (USB).
11-
You will also need drivers from the following menu to make use of it.
12-
135
# many non-PCI SOC chips embed OHCI
146
config USB_ARCH_HAS_OHCI
157
boolean
@@ -63,6 +55,14 @@ config USB_ARCH_HAS_XHCI
6355
boolean
6456
default PCI
6557

58+
menuconfig USB_SUPPORT
59+
bool "USB support"
60+
depends on HAS_IOMEM
61+
default y
62+
---help---
63+
This option adds core support for Universal Serial Bus (USB).
64+
You will also need drivers from the following menu to make use of it.
65+
6666
if USB_SUPPORT
6767

6868
config USB_COMMON

drivers/usb/core/driver.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,13 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
11891189
if (status == 0) {
11901190
status = usb_suspend_device(udev, msg);
11911191

1192-
/* Again, ignore errors during system sleep transitions */
1193-
if (!PMSG_IS_AUTO(msg))
1192+
/*
1193+
* Ignore errors from non-root-hub devices during
1194+
* system sleep transitions. For the most part,
1195+
* these devices should go to low power anyway when
1196+
* the entire bus is suspended.
1197+
*/
1198+
if (udev->parent && !PMSG_IS_AUTO(msg))
11941199
status = 0;
11951200
}
11961201

drivers/usb/core/hcd.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,18 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
19781978
if (status == 0) {
19791979
usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
19801980
hcd->state = HC_STATE_SUSPENDED;
1981+
1982+
/* Did we race with a root-hub wakeup event? */
1983+
if (rhdev->do_remote_wakeup) {
1984+
char buffer[6];
1985+
1986+
status = hcd->driver->hub_status_data(hcd, buffer);
1987+
if (status != 0) {
1988+
dev_dbg(&rhdev->dev, "suspend raced with wakeup event\n");
1989+
hcd_bus_resume(rhdev, PMSG_AUTO_RESUME);
1990+
status = -EBUSY;
1991+
}
1992+
}
19811993
} else {
19821994
spin_lock_irq(&hcd_root_hub_lock);
19831995
if (!HCD_DEAD(hcd)) {

drivers/usb/core/hub.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,6 +3163,22 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
31633163
if (retval)
31643164
goto fail;
31653165

3166+
/*
3167+
* Some superspeed devices have finished the link training process
3168+
* and attached to a superspeed hub port, but the device descriptor
3169+
* got from those devices show they aren't superspeed devices. Warm
3170+
* reset the port attached by the devices can fix them.
3171+
*/
3172+
if ((udev->speed == USB_SPEED_SUPER) &&
3173+
(le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) {
3174+
dev_err(&udev->dev, "got a wrong device descriptor, "
3175+
"warm reset device\n");
3176+
hub_port_reset(hub, port1, udev,
3177+
HUB_BH_RESET_TIME, true);
3178+
retval = -EINVAL;
3179+
goto fail;
3180+
}
3181+
31663182
if (udev->descriptor.bMaxPacketSize0 == 0xff ||
31673183
udev->speed == USB_SPEED_SUPER)
31683184
i = 512;

drivers/usb/core/message.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ static void sg_complete(struct urb *urb)
308308
retval = usb_unlink_urb(io->urbs [i]);
309309
if (retval != -EINPROGRESS &&
310310
retval != -ENODEV &&
311-
retval != -EBUSY)
311+
retval != -EBUSY &&
312+
retval != -EIDRM)
312313
dev_err(&io->dev->dev,
313314
"%s, unlink --> %d\n",
314315
__func__, retval);
@@ -317,7 +318,6 @@ static void sg_complete(struct urb *urb)
317318
}
318319
spin_lock(&io->lock);
319320
}
320-
urb->dev = NULL;
321321

322322
/* on the last completion, signal usb_sg_wait() */
323323
io->bytes += urb->actual_length;
@@ -524,7 +524,6 @@ void usb_sg_wait(struct usb_sg_request *io)
524524
case -ENXIO: /* hc didn't queue this one */
525525
case -EAGAIN:
526526
case -ENOMEM:
527-
io->urbs[i]->dev = NULL;
528527
retval = 0;
529528
yield();
530529
break;
@@ -542,7 +541,6 @@ void usb_sg_wait(struct usb_sg_request *io)
542541

543542
/* fail any uncompleted urbs */
544543
default:
545-
io->urbs[i]->dev = NULL;
546544
io->urbs[i]->status = retval;
547545
dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
548546
__func__, retval);
@@ -593,7 +591,10 @@ void usb_sg_cancel(struct usb_sg_request *io)
593591
if (!io->urbs [i]->dev)
594592
continue;
595593
retval = usb_unlink_urb(io->urbs [i]);
596-
if (retval != -EINPROGRESS && retval != -EBUSY)
594+
if (retval != -EINPROGRESS
595+
&& retval != -ENODEV
596+
&& retval != -EBUSY
597+
&& retval != -EIDRM)
597598
dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
598599
__func__, retval);
599600
}

drivers/usb/core/urb.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ EXPORT_SYMBOL_GPL(usb_submit_urb);
539539
* never submitted, or it was unlinked before, or the hardware is already
540540
* finished with it), even if the completion handler has not yet run.
541541
*
542+
* The URB must not be deallocated while this routine is running. In
543+
* particular, when a driver calls this routine, it must insure that the
544+
* completion handler cannot deallocate the URB.
545+
*
542546
* Unlinking and Endpoint Queues:
543547
*
544548
* [The behaviors and guarantees described below do not apply to virtual
@@ -603,6 +607,10 @@ EXPORT_SYMBOL_GPL(usb_unlink_urb);
603607
* with error -EPERM. Thus even if the URB's completion handler always
604608
* tries to resubmit, it will not succeed and the URB will become idle.
605609
*
610+
* The URB must not be deallocated while this routine is running. In
611+
* particular, when a driver calls this routine, it must insure that the
612+
* completion handler cannot deallocate the URB.
613+
*
606614
* This routine may not be used in an interrupt context (such as a bottom
607615
* half or a completion handler), or when holding a spinlock, or in other
608616
* situations where the caller can't schedule().
@@ -640,6 +648,10 @@ EXPORT_SYMBOL_GPL(usb_kill_urb);
640648
* with error -EPERM. Thus even if the URB's completion handler always
641649
* tries to resubmit, it will not succeed and the URB will become idle.
642650
*
651+
* The URB must not be deallocated while this routine is running. In
652+
* particular, when a driver calls this routine, it must insure that the
653+
* completion handler cannot deallocate the URB.
654+
*
643655
* This routine may not be used in an interrupt context (such as a bottom
644656
* half or a completion handler), or when holding a spinlock, or in other
645657
* situations where the caller can't schedule().

drivers/usb/gadget/inode.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,6 @@ static void destroy_ep_files (struct dev_data *dev)
15741574
DBG (dev, "%s %d\n", __func__, dev->state);
15751575

15761576
/* dev->state must prevent interference */
1577-
restart:
15781577
spin_lock_irq (&dev->lock);
15791578
while (!list_empty(&dev->epfiles)) {
15801579
struct ep_data *ep;

drivers/usb/host/ehci-hcd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ static int ehci_reset (struct ehci_hcd *ehci)
347347
if (ehci->debug)
348348
dbgp_external_startup();
349349

350+
ehci->port_c_suspend = ehci->suspended_ports =
351+
ehci->resuming_ports = 0;
350352
return retval;
351353
}
352354

@@ -939,6 +941,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
939941
* like usb_port_resume() does.
940942
*/
941943
ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
944+
set_bit(i, &ehci->resuming_ports);
942945
ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
943946
mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
944947
}

drivers/usb/host/ehci-hub.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,10 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
223223
* remote wakeup, we must fail the suspend.
224224
*/
225225
if (hcd->self.root_hub->do_remote_wakeup) {
226-
port = HCS_N_PORTS(ehci->hcs_params);
227-
while (port--) {
228-
if (ehci->reset_done[port] != 0) {
229-
spin_unlock_irq(&ehci->lock);
230-
ehci_dbg(ehci, "suspend failed because "
231-
"port %d is resuming\n",
232-
port + 1);
233-
return -EBUSY;
234-
}
226+
if (ehci->resuming_ports) {
227+
spin_unlock_irq(&ehci->lock);
228+
ehci_dbg(ehci, "suspend failed because a port is resuming\n");
229+
return -EBUSY;
235230
}
236231
}
237232

@@ -554,16 +549,12 @@ static int
554549
ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
555550
{
556551
struct ehci_hcd *ehci = hcd_to_ehci (hcd);
557-
u32 temp, status = 0;
552+
u32 temp, status;
558553
u32 mask;
559554
int ports, i, retval = 1;
560555
unsigned long flags;
561556
u32 ppcd = 0;
562557

563-
/* if !USB_SUSPEND, root hub timers won't get shut down ... */
564-
if (ehci->rh_state != EHCI_RH_RUNNING)
565-
return 0;
566-
567558
/* init status to no-changes */
568559
buf [0] = 0;
569560
ports = HCS_N_PORTS (ehci->hcs_params);
@@ -572,6 +563,11 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
572563
retval++;
573564
}
574565

566+
/* Inform the core about resumes-in-progress by returning
567+
* a non-zero value even if there are no status changes.
568+
*/
569+
status = ehci->resuming_ports;
570+
575571
/* Some boards (mostly VIA?) report bogus overcurrent indications,
576572
* causing massive log spam unless we completely ignore them. It
577573
* may be relevant that VIA VT8235 controllers, where PORT_POWER is
@@ -846,6 +842,7 @@ static int ehci_hub_control (
846842
ehci_writel(ehci,
847843
temp & ~(PORT_RWC_BITS | PORT_RESUME),
848844
status_reg);
845+
clear_bit(wIndex, &ehci->resuming_ports);
849846
retval = handshake(ehci, status_reg,
850847
PORT_RESUME, 0, 2000 /* 2msec */);
851848
if (retval != 0) {
@@ -864,6 +861,7 @@ static int ehci_hub_control (
864861
ehci->reset_done[wIndex])) {
865862
status |= USB_PORT_STAT_C_RESET << 16;
866863
ehci->reset_done [wIndex] = 0;
864+
clear_bit(wIndex, &ehci->resuming_ports);
867865

868866
/* force reset to complete */
869867
ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
@@ -884,8 +882,10 @@ static int ehci_hub_control (
884882
ehci_readl(ehci, status_reg));
885883
}
886884

887-
if (!(temp & (PORT_RESUME|PORT_RESET)))
885+
if (!(temp & (PORT_RESUME|PORT_RESET))) {
888886
ehci->reset_done[wIndex] = 0;
887+
clear_bit(wIndex, &ehci->resuming_ports);
888+
}
889889

890890
/* transfer dedicated ports to the companion hc */
891891
if ((temp & PORT_CONNECT) &&
@@ -920,6 +920,7 @@ static int ehci_hub_control (
920920
status |= USB_PORT_STAT_SUSPEND;
921921
} else if (test_bit(wIndex, &ehci->suspended_ports)) {
922922
clear_bit(wIndex, &ehci->suspended_ports);
923+
clear_bit(wIndex, &ehci->resuming_ports);
923924
ehci->reset_done[wIndex] = 0;
924925
if (temp & PORT_PE)
925926
set_bit(wIndex, &ehci->port_c_suspend);

drivers/usb/host/ehci-tegra.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ static int tegra_ehci_hub_control(
224224
temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
225225
/* start resume signalling */
226226
ehci_writel(ehci, temp | PORT_RESUME, status_reg);
227+
set_bit(wIndex-1, &ehci->resuming_ports);
227228

228229
spin_unlock_irqrestore(&ehci->lock, flags);
229230
msleep(20);
@@ -236,6 +237,7 @@ static int tegra_ehci_hub_control(
236237
pr_err("%s: timeout waiting for SUSPEND\n", __func__);
237238

238239
ehci->reset_done[wIndex-1] = 0;
240+
clear_bit(wIndex-1, &ehci->resuming_ports);
239241

240242
tegra->port_resuming = 1;
241243
goto done;

drivers/usb/host/ehci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ struct ehci_hcd { /* one per controller */
117117
the change-suspend feature turned on */
118118
unsigned long suspended_ports; /* which ports are
119119
suspended */
120+
unsigned long resuming_ports; /* which ports have
121+
started to resume */
120122

121123
/* per-HC memory pools (could be per-bus, but ...) */
122124
struct dma_pool *qh_pool; /* qh per active urb */

0 commit comments

Comments
 (0)