Skip to content

Commit 2c248f9

Browse files
committed
Merge tag 'usb-5.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB fixes from Greg KH: "Here are some small USB fixes that have been in linux-next this past week for 5.3-rc7 They fix the usual xhci, syzbot reports, and other small issues that have come up last week. All have been in linux-next with no reported issues" * tag 'usb-5.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: USB: cdc-wdm: fix race between write and disconnect due to flag abuse usb: host: xhci: rcar: Fix typo in compatible string matching usb: host: xhci-tegra: Set DMA mask correctly USB: storage: ums-realtek: Whitelist auto-delink support USB: storage: ums-realtek: Update module parameter description for auto_delink_en usb: host: ohci: fix a race condition between shutdown and irq usb: hcd: use managed device resources typec: tcpm: fix a typo in the comparison of pdo_max_voltage usb-storage: Add new JMS567 revision to unusual_devs usb: chipidea: udc: don't do hardware access if gadget has stopped usbtmc: more sanity checking for packet size usb: udc: lpc32xx: silence fall-through warning
2 parents 345464f + 1426bd2 commit 2c248f9

File tree

11 files changed

+82
-47
lines changed

11 files changed

+82
-47
lines changed

drivers/usb/chipidea/udc.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,6 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
709709
struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget);
710710
unsigned long flags;
711711

712-
spin_lock_irqsave(&ci->lock, flags);
713-
ci->gadget.speed = USB_SPEED_UNKNOWN;
714-
ci->remote_wakeup = 0;
715-
ci->suspended = 0;
716-
spin_unlock_irqrestore(&ci->lock, flags);
717-
718712
/* flush all endpoints */
719713
gadget_for_each_ep(ep, gadget) {
720714
usb_ep_fifo_flush(ep);
@@ -732,6 +726,12 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
732726
ci->status = NULL;
733727
}
734728

729+
spin_lock_irqsave(&ci->lock, flags);
730+
ci->gadget.speed = USB_SPEED_UNKNOWN;
731+
ci->remote_wakeup = 0;
732+
ci->suspended = 0;
733+
spin_unlock_irqrestore(&ci->lock, flags);
734+
735735
return 0;
736736
}
737737

@@ -1303,6 +1303,10 @@ static int ep_disable(struct usb_ep *ep)
13031303
return -EBUSY;
13041304

13051305
spin_lock_irqsave(hwep->lock, flags);
1306+
if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) {
1307+
spin_unlock_irqrestore(hwep->lock, flags);
1308+
return 0;
1309+
}
13061310

13071311
/* only internal SW should disable ctrl endpts */
13081312

@@ -1392,6 +1396,10 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
13921396
return -EINVAL;
13931397

13941398
spin_lock_irqsave(hwep->lock, flags);
1399+
if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) {
1400+
spin_unlock_irqrestore(hwep->lock, flags);
1401+
return 0;
1402+
}
13951403
retval = _ep_queue(ep, req, gfp_flags);
13961404
spin_unlock_irqrestore(hwep->lock, flags);
13971405
return retval;
@@ -1415,8 +1423,8 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
14151423
return -EINVAL;
14161424

14171425
spin_lock_irqsave(hwep->lock, flags);
1418-
1419-
hw_ep_flush(hwep->ci, hwep->num, hwep->dir);
1426+
if (hwep->ci->gadget.speed != USB_SPEED_UNKNOWN)
1427+
hw_ep_flush(hwep->ci, hwep->num, hwep->dir);
14201428

14211429
list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) {
14221430
dma_pool_free(hwep->td_pool, node->ptr, node->dma);
@@ -1487,6 +1495,10 @@ static void ep_fifo_flush(struct usb_ep *ep)
14871495
}
14881496

14891497
spin_lock_irqsave(hwep->lock, flags);
1498+
if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) {
1499+
spin_unlock_irqrestore(hwep->lock, flags);
1500+
return;
1501+
}
14901502

14911503
hw_ep_flush(hwep->ci, hwep->num, hwep->dir);
14921504

@@ -1559,6 +1571,10 @@ static int ci_udc_wakeup(struct usb_gadget *_gadget)
15591571
int ret = 0;
15601572

15611573
spin_lock_irqsave(&ci->lock, flags);
1574+
if (ci->gadget.speed == USB_SPEED_UNKNOWN) {
1575+
spin_unlock_irqrestore(&ci->lock, flags);
1576+
return 0;
1577+
}
15621578
if (!ci->remote_wakeup) {
15631579
ret = -EOPNOTSUPP;
15641580
goto out;

drivers/usb/class/cdc-wdm.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,20 @@ static int wdm_flush(struct file *file, fl_owner_t id)
587587
{
588588
struct wdm_device *desc = file->private_data;
589589

590-
wait_event(desc->wait, !test_bit(WDM_IN_USE, &desc->flags));
590+
wait_event(desc->wait,
591+
/*
592+
* needs both flags. We cannot do with one
593+
* because resetting it would cause a race
594+
* with write() yet we need to signal
595+
* a disconnect
596+
*/
597+
!test_bit(WDM_IN_USE, &desc->flags) ||
598+
test_bit(WDM_DISCONNECTING, &desc->flags));
591599

592600
/* cannot dereference desc->intf if WDM_DISCONNECTING */
593-
if (desc->werr < 0 && !test_bit(WDM_DISCONNECTING, &desc->flags))
601+
if (test_bit(WDM_DISCONNECTING, &desc->flags))
602+
return -ENODEV;
603+
if (desc->werr < 0)
594604
dev_err(&desc->intf->dev, "Error in flush path: %d\n",
595605
desc->werr);
596606

@@ -974,8 +984,6 @@ static void wdm_disconnect(struct usb_interface *intf)
974984
spin_lock_irqsave(&desc->iuspin, flags);
975985
set_bit(WDM_DISCONNECTING, &desc->flags);
976986
set_bit(WDM_READ, &desc->flags);
977-
/* to terminate pending flushes */
978-
clear_bit(WDM_IN_USE, &desc->flags);
979987
spin_unlock_irqrestore(&desc->iuspin, flags);
980988
wake_up_all(&desc->wait);
981989
mutex_lock(&desc->rlock);

drivers/usb/class/usbtmc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,8 +2362,11 @@ static int usbtmc_probe(struct usb_interface *intf,
23622362
goto err_put;
23632363
}
23642364

2365+
retcode = -EINVAL;
23652366
data->bulk_in = bulk_in->bEndpointAddress;
23662367
data->wMaxPacketSize = usb_endpoint_maxp(bulk_in);
2368+
if (!data->wMaxPacketSize)
2369+
goto err_put;
23672370
dev_dbg(&intf->dev, "Found bulk in endpoint at %u\n", data->bulk_in);
23682371

23692372
data->bulk_out = bulk_out->bEndpointAddress;

drivers/usb/core/hcd-pci.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,18 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
216216
/* EHCI, OHCI */
217217
hcd->rsrc_start = pci_resource_start(dev, 0);
218218
hcd->rsrc_len = pci_resource_len(dev, 0);
219-
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
220-
driver->description)) {
219+
if (!devm_request_mem_region(&dev->dev, hcd->rsrc_start,
220+
hcd->rsrc_len, driver->description)) {
221221
dev_dbg(&dev->dev, "controller already in use\n");
222222
retval = -EBUSY;
223223
goto put_hcd;
224224
}
225-
hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
225+
hcd->regs = devm_ioremap_nocache(&dev->dev, hcd->rsrc_start,
226+
hcd->rsrc_len);
226227
if (hcd->regs == NULL) {
227228
dev_dbg(&dev->dev, "error mapping memory\n");
228229
retval = -EFAULT;
229-
goto release_mem_region;
230+
goto put_hcd;
230231
}
231232

232233
} else {
@@ -240,8 +241,8 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
240241

241242
hcd->rsrc_start = pci_resource_start(dev, region);
242243
hcd->rsrc_len = pci_resource_len(dev, region);
243-
if (request_region(hcd->rsrc_start, hcd->rsrc_len,
244-
driver->description))
244+
if (devm_request_region(&dev->dev, hcd->rsrc_start,
245+
hcd->rsrc_len, driver->description))
245246
break;
246247
}
247248
if (region == PCI_ROM_RESOURCE) {
@@ -275,20 +276,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
275276
}
276277

277278
if (retval != 0)
278-
goto unmap_registers;
279+
goto put_hcd;
279280
device_wakeup_enable(hcd->self.controller);
280281

281282
if (pci_dev_run_wake(dev))
282283
pm_runtime_put_noidle(&dev->dev);
283284
return retval;
284285

285-
unmap_registers:
286-
if (driver->flags & HCD_MEMORY) {
287-
iounmap(hcd->regs);
288-
release_mem_region:
289-
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
290-
} else
291-
release_region(hcd->rsrc_start, hcd->rsrc_len);
292286
put_hcd:
293287
usb_put_hcd(hcd);
294288
disable_pci:
@@ -347,14 +341,6 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
347341
dev_set_drvdata(&dev->dev, NULL);
348342
up_read(&companions_rwsem);
349343
}
350-
351-
if (hcd->driver->flags & HCD_MEMORY) {
352-
iounmap(hcd->regs);
353-
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
354-
} else {
355-
release_region(hcd->rsrc_start, hcd->rsrc_len);
356-
}
357-
358344
usb_put_hcd(hcd);
359345
pci_disable_device(dev);
360346
}

drivers/usb/gadget/udc/lpc32xx_udc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ static void udc_handle_ep0_setup(struct lpc32xx_udc *udc)
22652265
default:
22662266
break;
22672267
}
2268-
2268+
break;
22692269

22702270
case USB_REQ_SET_ADDRESS:
22712271
if (reqtype == (USB_TYPE_STANDARD | USB_RECIP_DEVICE)) {

drivers/usb/host/ohci-hcd.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
419419
* other cases where the next software may expect clean state from the
420420
* "firmware". this is bus-neutral, unlike shutdown() methods.
421421
*/
422-
static void
423-
ohci_shutdown (struct usb_hcd *hcd)
422+
static void _ohci_shutdown(struct usb_hcd *hcd)
424423
{
425424
struct ohci_hcd *ohci;
426425

@@ -436,6 +435,16 @@ ohci_shutdown (struct usb_hcd *hcd)
436435
ohci->rh_state = OHCI_RH_HALTED;
437436
}
438437

438+
static void ohci_shutdown(struct usb_hcd *hcd)
439+
{
440+
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
441+
unsigned long flags;
442+
443+
spin_lock_irqsave(&ohci->lock, flags);
444+
_ohci_shutdown(hcd);
445+
spin_unlock_irqrestore(&ohci->lock, flags);
446+
}
447+
439448
/*-------------------------------------------------------------------------*
440449
* HC functions
441450
*-------------------------------------------------------------------------*/
@@ -760,7 +769,7 @@ static void io_watchdog_func(struct timer_list *t)
760769
died:
761770
usb_hc_died(ohci_to_hcd(ohci));
762771
ohci_dump(ohci);
763-
ohci_shutdown(ohci_to_hcd(ohci));
772+
_ohci_shutdown(ohci_to_hcd(ohci));
764773
goto done;
765774
} else {
766775
/* No write back because the done queue was empty */

drivers/usb/host/xhci-rcar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int xhci_rcar_is_gen2(struct device *dev)
104104
return of_device_is_compatible(node, "renesas,xhci-r8a7790") ||
105105
of_device_is_compatible(node, "renesas,xhci-r8a7791") ||
106106
of_device_is_compatible(node, "renesas,xhci-r8a7793") ||
107-
of_device_is_compatible(node, "renensas,rcar-gen2-xhci");
107+
of_device_is_compatible(node, "renesas,rcar-gen2-xhci");
108108
}
109109

110110
static int xhci_rcar_is_gen3(struct device *dev)

drivers/usb/host/xhci-tegra.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,16 @@ static int tegra_xusb_probe(struct platform_device *pdev)
11941194

11951195
tegra_xusb_config(tegra, regs);
11961196

1197+
/*
1198+
* The XUSB Falcon microcontroller can only address 40 bits, so set
1199+
* the DMA mask accordingly.
1200+
*/
1201+
err = dma_set_mask_and_coherent(tegra->dev, DMA_BIT_MASK(40));
1202+
if (err < 0) {
1203+
dev_err(&pdev->dev, "failed to set DMA mask: %d\n", err);
1204+
goto put_rpm;
1205+
}
1206+
11971207
err = tegra_xusb_load_firmware(tegra);
11981208
if (err < 0) {
11991209
dev_err(&pdev->dev, "failed to load firmware: %d\n", err);

drivers/usb/storage/realtek_cr.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ MODULE_LICENSE("GPL");
3838

3939
static int auto_delink_en = 1;
4040
module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
41-
MODULE_PARM_DESC(auto_delink_en, "enable auto delink");
41+
MODULE_PARM_DESC(auto_delink_en, "auto delink mode (0=firmware, 1=software [default])");
4242

4343
#ifdef CONFIG_REALTEK_AUTOPM
4444
static int ss_en = 1;
@@ -996,12 +996,15 @@ static int init_realtek_cr(struct us_data *us)
996996
goto INIT_FAIL;
997997
}
998998

999-
if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) ||
1000-
CHECK_FW_VER(chip, 0x5901))
1001-
SET_AUTO_DELINK(chip);
1002-
if (STATUS_LEN(chip) == 16) {
1003-
if (SUPPORT_AUTO_DELINK(chip))
999+
if (CHECK_PID(chip, 0x0138) || CHECK_PID(chip, 0x0158) ||
1000+
CHECK_PID(chip, 0x0159)) {
1001+
if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) ||
1002+
CHECK_FW_VER(chip, 0x5901))
10041003
SET_AUTO_DELINK(chip);
1004+
if (STATUS_LEN(chip) == 16) {
1005+
if (SUPPORT_AUTO_DELINK(chip))
1006+
SET_AUTO_DELINK(chip);
1007+
}
10051008
}
10061009
#ifdef CONFIG_REALTEK_AUTOPM
10071010
if (ss_en)

drivers/usb/storage/unusual_devs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201,
21002100
US_FL_IGNORE_RESIDUE ),
21012101

21022102
/* Reported by Michael Büsch <[email protected]> */
2103-
UNUSUAL_DEV( 0x152d, 0x0567, 0x0114, 0x0116,
2103+
UNUSUAL_DEV( 0x152d, 0x0567, 0x0114, 0x0117,
21042104
"JMicron",
21052105
"USB to ATA/ATAPI Bridge",
21062106
USB_SC_DEVICE, USB_PR_DEVICE, NULL,

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ static enum pdo_err tcpm_caps_err(struct tcpm_port *port, const u32 *pdo,
14461446
else if ((pdo_min_voltage(pdo[i]) ==
14471447
pdo_min_voltage(pdo[i - 1])) &&
14481448
(pdo_max_voltage(pdo[i]) ==
1449-
pdo_min_voltage(pdo[i - 1])))
1449+
pdo_max_voltage(pdo[i - 1])))
14501450
return PDO_ERR_DUPE_PDO;
14511451
break;
14521452
/*

0 commit comments

Comments
 (0)