Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'usb-7.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB/Thunderbolt fixes from Greg KH:
"Here are a bunch of USB and Thunderbolt fixes (most all are USB) for
7.0-rc7. More than I normally like this late in the release cycle,
partly due to my recent travels, and partly due to people banging away
on the USB gadget interfaces and apis more than normal (big shoutout
to Android for getting the vendors to actually work upstream on this,
that's a huge win overall for everyone here)

Included in here are:
- Small thunderbolt fix
- new USB serial driver ids added
- typec driver fixes
- gadget driver fixes for some disconnect issues
- other usb gadget driver fixes for reported problems with binding
and unbinding devices as happens when a gadget device connects /
disconnects from a system it is plugged into (or it switches device
mode at a user's request, these things are complex little
beasts...)
- usb offload fixes (where USB audio tunnels through the controller
while the main CPU is asleep) for when EMP spikes hit the system
causing disconnects to happen (as often happens with static
electricity in the winter months). This has been much reported by
at least one vendor, and resolves the issues they have been seeing
with this codepath. Can't wait for the "formal methods are the
answer!" people to try to model that one properly...
- Other small usb driver fixes for issues reported.

All of these have been in linux-next this week, and before, with no
reported issues, and I've personally been stressing these harder than
normal on my systems here with no problems"

* tag 'usb-7.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (39 commits)
usb: gadget: f_hid: move list and spinlock inits from bind to alloc
usb: host: xhci-sideband: delegate offload_usage tracking to class drivers
usb: core: use dedicated spinlock for offload state
usb: cdns3: gadget: fix state inconsistency on gadget init failure
usb: dwc3: imx8mp: fix memory leak on probe failure path
usb: gadget: f_uac1_legacy: validate control request size
usb: ulpi: fix double free in ulpi_register_interface() error path
usb: misc: usbio: Fix URB memory leak on submit failure
USB: core: add NO_LPM quirk for Razer Kiyo Pro webcam
usb: cdns3: gadget: fix NULL pointer dereference in ep_queue
usb: core: phy: avoid double use of 'usb3-phy'
USB: serial: option: add MeiG Smart SRM825WN
usb: gadget: f_rndis: Fix net_device lifecycle with device_move
usb: gadget: f_subset: Fix net_device lifecycle with device_move
usb: gadget: f_eem: Fix net_device lifecycle with device_move
usb: gadget: f_ecm: Fix net_device lifecycle with device_move
usb: gadget: u_ncm: Add kernel-doc comments for struct f_ncm_opts
usb: gadget: f_rndis: Protect RNDIS options with mutex
usb: gadget: f_subset: Fix unbalanced refcnt in geth_free
dt-bindings: connector: add pd-disable dependency
...

+507 -277
+1
Documentation/devicetree/bindings/connector/usb-connector.yaml
··· 301 301 maxItems: 4 302 302 303 303 dependencies: 304 + pd-disable: [typec-power-opmode] 304 305 sink-vdos-v1: [ sink-vdos ] 305 306 sink-vdos: [ sink-vdos-v1 ] 306 307
+1 -1
drivers/thunderbolt/nhi.c
··· 1020 1020 * If power rails are sustainable for wakeup from S4 this 1021 1021 * property is set by the BIOS. 1022 1022 */ 1023 - if (device_property_read_u8(&pdev->dev, "WAKE_SUPPORTED", &val)) 1023 + if (!device_property_read_u8(&pdev->dev, "WAKE_SUPPORTED", &val)) 1024 1024 return !!val; 1025 1025 1026 1026 return true;
+4
drivers/usb/cdns3/cdns3-gadget.c
··· 2589 2589 struct cdns3_request *priv_req; 2590 2590 int ret = 0; 2591 2591 2592 + if (!ep->desc) 2593 + return -ESHUTDOWN; 2594 + 2592 2595 request->actual = 0; 2593 2596 request->status = -EINPROGRESS; 2594 2597 priv_req = to_cdns3_request(request); ··· 3431 3428 ret = cdns3_gadget_start(cdns); 3432 3429 if (ret) { 3433 3430 pm_runtime_put_sync(cdns->dev); 3431 + cdns_drd_gadget_off(cdns); 3434 3432 return ret; 3435 3433 } 3436 3434
+9
drivers/usb/class/cdc-acm.c
··· 1225 1225 if (!data_interface || !control_interface) 1226 1226 return -ENODEV; 1227 1227 goto skip_normal_probe; 1228 + } else if (quirks == NO_UNION_12) { 1229 + data_interface = usb_ifnum_to_if(usb_dev, 2); 1230 + control_interface = usb_ifnum_to_if(usb_dev, 1); 1231 + if (!data_interface || !control_interface) 1232 + return -ENODEV; 1233 + goto skip_normal_probe; 1228 1234 } 1229 1235 1230 1236 /* normal probing*/ ··· 1753 1747 }, 1754 1748 { USB_DEVICE(0x045b, 0x024D), /* Renesas R-Car E3 USB Download mode */ 1755 1749 .driver_info = DISABLE_ECHO, /* Don't echo banner */ 1750 + }, 1751 + { USB_DEVICE(0x04b8, 0x0d12), /* EPSON HMD Com&Sens */ 1752 + .driver_info = NO_UNION_12, /* union descriptor is garbage */ 1756 1753 }, 1757 1754 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ 1758 1755 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
+1
drivers/usb/class/cdc-acm.h
··· 114 114 #define SEND_ZERO_PACKET BIT(6) 115 115 #define DISABLE_ECHO BIT(7) 116 116 #define MISSING_CAP_BRK BIT(8) 117 + #define NO_UNION_12 BIT(9)
+3
drivers/usb/class/usbtmc.c
··· 254 254 list_del(&file_data->file_elem); 255 255 256 256 spin_unlock_irq(&file_data->data->dev_lock); 257 + 258 + /* flush anchored URBs */ 259 + usbtmc_draw_down(file_data); 257 260 mutex_unlock(&file_data->data->io_mutex); 258 261 259 262 kref_put(&file_data->data->kref, usbtmc_delete);
+2 -3
drivers/usb/common/ulpi.c
··· 331 331 ulpi->ops = ops; 332 332 333 333 ret = ulpi_register(dev, ulpi); 334 - if (ret) { 335 - kfree(ulpi); 334 + if (ret) 336 335 return ERR_PTR(ret); 337 - } 336 + 338 337 339 338 return ulpi; 340 339 }
+14 -9
drivers/usb/core/driver.c
··· 1415 1415 int status = 0; 1416 1416 int i = 0, n = 0; 1417 1417 struct usb_interface *intf; 1418 + bool offload_active = false; 1418 1419 1419 1420 if (udev->state == USB_STATE_NOTATTACHED || 1420 1421 udev->state == USB_STATE_SUSPENDED) 1421 1422 goto done; 1422 1423 1424 + usb_offload_set_pm_locked(udev, true); 1423 1425 if (msg.event == PM_EVENT_SUSPEND && usb_offload_check(udev)) { 1424 1426 dev_dbg(&udev->dev, "device offloaded, skip suspend.\n"); 1425 - udev->offload_at_suspend = 1; 1427 + offload_active = true; 1426 1428 } 1427 1429 1428 1430 /* Suspend all the interfaces and then udev itself */ ··· 1438 1436 * interrupt urbs, allowing interrupt events to be 1439 1437 * handled during system suspend. 1440 1438 */ 1441 - if (udev->offload_at_suspend && 1442 - intf->needs_remote_wakeup) { 1439 + if (offload_active && intf->needs_remote_wakeup) { 1443 1440 dev_dbg(&intf->dev, 1444 1441 "device offloaded, skip suspend.\n"); 1445 1442 continue; ··· 1453 1452 } 1454 1453 } 1455 1454 if (status == 0) { 1456 - if (!udev->offload_at_suspend) 1455 + if (!offload_active) 1457 1456 status = usb_suspend_device(udev, msg); 1458 1457 1459 1458 /* ··· 1499 1498 */ 1500 1499 } else { 1501 1500 udev->can_submit = 0; 1502 - if (!udev->offload_at_suspend) { 1501 + if (!offload_active) { 1503 1502 for (i = 0; i < 16; ++i) { 1504 1503 usb_hcd_flush_endpoint(udev, udev->ep_out[i]); 1505 1504 usb_hcd_flush_endpoint(udev, udev->ep_in[i]); ··· 1508 1507 } 1509 1508 1510 1509 done: 1510 + if (status != 0) 1511 + usb_offload_set_pm_locked(udev, false); 1511 1512 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); 1512 1513 return status; 1513 1514 } ··· 1539 1536 int status = 0; 1540 1537 int i; 1541 1538 struct usb_interface *intf; 1539 + bool offload_active = false; 1542 1540 1543 1541 if (udev->state == USB_STATE_NOTATTACHED) { 1544 1542 status = -ENODEV; 1545 1543 goto done; 1546 1544 } 1547 1545 udev->can_submit = 1; 1546 + if (msg.event == PM_EVENT_RESUME) 1547 + offload_active = usb_offload_check(udev); 1548 1548 1549 1549 /* Resume the device */ 1550 1550 if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) { 1551 - if (!udev->offload_at_suspend) 1551 + if (!offload_active) 1552 1552 status = usb_resume_device(udev, msg); 1553 1553 else 1554 1554 dev_dbg(&udev->dev, ··· 1568 1562 * pending interrupt urbs, allowing interrupt events 1569 1563 * to be handled during system suspend. 1570 1564 */ 1571 - if (udev->offload_at_suspend && 1572 - intf->needs_remote_wakeup) { 1565 + if (offload_active && intf->needs_remote_wakeup) { 1573 1566 dev_dbg(&intf->dev, 1574 1567 "device offloaded, skip resume.\n"); 1575 1568 continue; ··· 1577 1572 udev->reset_resume); 1578 1573 } 1579 1574 } 1580 - udev->offload_at_suspend = 0; 1581 1575 usb_mark_last_busy(udev); 1582 1576 1583 1577 done: 1584 1578 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); 1579 + usb_offload_set_pm_locked(udev, false); 1585 1580 if (!status) 1586 1581 udev->reset_resume = 0; 1587 1582 return status;
+1 -1
drivers/usb/core/hcd.c
··· 2403 2403 if (hcd->rh_registered) { 2404 2404 pm_wakeup_event(&hcd->self.root_hub->dev, 0); 2405 2405 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); 2406 - queue_work(pm_wq, &hcd->wakeup_work); 2406 + queue_work(system_freezable_wq, &hcd->wakeup_work); 2407 2407 } 2408 2408 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 2409 2409 }
+59 -43
drivers/usb/core/offload.c
··· 25 25 */ 26 26 int usb_offload_get(struct usb_device *udev) 27 27 { 28 - int ret; 28 + int ret = 0; 29 29 30 - usb_lock_device(udev); 31 - if (udev->state == USB_STATE_NOTATTACHED) { 32 - usb_unlock_device(udev); 30 + if (!usb_get_dev(udev)) 33 31 return -ENODEV; 32 + 33 + if (pm_runtime_get_if_active(&udev->dev) != 1) { 34 + ret = -EBUSY; 35 + goto err_rpm; 34 36 } 35 37 36 - if (udev->state == USB_STATE_SUSPENDED || 37 - udev->offload_at_suspend) { 38 - usb_unlock_device(udev); 39 - return -EBUSY; 40 - } 38 + spin_lock(&udev->offload_lock); 41 39 42 - /* 43 - * offload_usage could only be modified when the device is active, since 44 - * it will alter the suspend flow of the device. 45 - */ 46 - ret = usb_autoresume_device(udev); 47 - if (ret < 0) { 48 - usb_unlock_device(udev); 49 - return ret; 40 + if (udev->offload_pm_locked) { 41 + ret = -EAGAIN; 42 + goto err; 50 43 } 51 44 52 45 udev->offload_usage++; 53 - usb_autosuspend_device(udev); 54 - usb_unlock_device(udev); 46 + 47 + err: 48 + spin_unlock(&udev->offload_lock); 49 + pm_runtime_put_autosuspend(&udev->dev); 50 + err_rpm: 51 + usb_put_dev(udev); 55 52 56 53 return ret; 57 54 } ··· 66 69 */ 67 70 int usb_offload_put(struct usb_device *udev) 68 71 { 69 - int ret; 72 + int ret = 0; 70 73 71 - usb_lock_device(udev); 72 - if (udev->state == USB_STATE_NOTATTACHED) { 73 - usb_unlock_device(udev); 74 + if (!usb_get_dev(udev)) 74 75 return -ENODEV; 76 + 77 + if (pm_runtime_get_if_active(&udev->dev) != 1) { 78 + ret = -EBUSY; 79 + goto err_rpm; 75 80 } 76 81 77 - if (udev->state == USB_STATE_SUSPENDED || 78 - udev->offload_at_suspend) { 79 - usb_unlock_device(udev); 80 - return -EBUSY; 81 - } 82 + spin_lock(&udev->offload_lock); 82 83 83 - /* 84 - * offload_usage could only be modified when the device is active, since 85 - * it will alter the suspend flow of the device. 86 - */ 87 - ret = usb_autoresume_device(udev); 88 - if (ret < 0) { 89 - usb_unlock_device(udev); 90 - return ret; 84 + if (udev->offload_pm_locked) { 85 + ret = -EAGAIN; 86 + goto err; 91 87 } 92 88 93 89 /* Drop the count when it wasn't 0, ignore the operation otherwise. */ 94 90 if (udev->offload_usage) 95 91 udev->offload_usage--; 96 - usb_autosuspend_device(udev); 97 - usb_unlock_device(udev); 92 + 93 + err: 94 + spin_unlock(&udev->offload_lock); 95 + pm_runtime_put_autosuspend(&udev->dev); 96 + err_rpm: 97 + usb_put_dev(udev); 98 98 99 99 return ret; 100 100 } ··· 106 112 * management. 107 113 * 108 114 * The caller must hold @udev's device lock. In addition, the caller should 109 - * ensure downstream usb devices are all either suspended or marked as 110 - * "offload_at_suspend" to ensure the correctness of the return value. 115 + * ensure the device itself and the downstream usb devices are all marked as 116 + * "offload_pm_locked" to ensure the correctness of the return value. 111 117 * 112 118 * Returns true on any offload activity, false otherwise. 113 119 */ 114 120 bool usb_offload_check(struct usb_device *udev) __must_hold(&udev->dev->mutex) 115 121 { 116 122 struct usb_device *child; 117 - bool active; 123 + bool active = false; 118 124 int port1; 125 + 126 + if (udev->offload_usage) 127 + return true; 119 128 120 129 usb_hub_for_each_child(udev, port1, child) { 121 130 usb_lock_device(child); 122 131 active = usb_offload_check(child); 123 132 usb_unlock_device(child); 133 + 124 134 if (active) 125 - return true; 135 + break; 126 136 } 127 137 128 - return !!udev->offload_usage; 138 + return active; 129 139 } 130 140 EXPORT_SYMBOL_GPL(usb_offload_check); 141 + 142 + /** 143 + * usb_offload_set_pm_locked - set the PM lock state of a USB device 144 + * @udev: the USB device to modify 145 + * @locked: the new lock state 146 + * 147 + * Setting @locked to true prevents offload_usage from being modified. This 148 + * ensures that offload activities cannot be started or stopped during critical 149 + * power management transitions, maintaining a stable state for the duration 150 + * of the transition. 151 + */ 152 + void usb_offload_set_pm_locked(struct usb_device *udev, bool locked) 153 + { 154 + spin_lock(&udev->offload_lock); 155 + udev->offload_pm_locked = locked; 156 + spin_unlock(&udev->offload_lock); 157 + } 158 + EXPORT_SYMBOL_GPL(usb_offload_set_pm_locked);
+11 -1
drivers/usb/core/phy.c
··· 114 114 struct usb_phy_roothub *usb_phy_roothub_alloc_usb3_phy(struct device *dev) 115 115 { 116 116 struct usb_phy_roothub *phy_roothub; 117 - int num_phys; 117 + int num_phys, usb2_phy_index; 118 118 119 119 if (!IS_ENABLED(CONFIG_GENERIC_PHY)) 120 120 return NULL; ··· 122 122 num_phys = of_count_phandle_with_args(dev->of_node, "phys", 123 123 "#phy-cells"); 124 124 if (num_phys <= 0) 125 + return NULL; 126 + 127 + /* 128 + * If 'usb2-phy' is not present, usb_phy_roothub_alloc() added 129 + * all PHYs to the primary HCD's phy_roothub already, so skip 130 + * adding 'usb3-phy' here to avoid double use of that. 131 + */ 132 + usb2_phy_index = of_property_match_string(dev->of_node, "phy-names", 133 + "usb2-phy"); 134 + if (usb2_phy_index < 0) 125 135 return NULL; 126 136 127 137 phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL);
+3
drivers/usb/core/quirks.c
··· 401 401 402 402 /* Silicon Motion Flash Drive */ 403 403 { USB_DEVICE(0x090c, 0x1000), .driver_info = USB_QUIRK_DELAY_INIT }, 404 + { USB_DEVICE(0x090c, 0x2000), .driver_info = USB_QUIRK_DELAY_INIT }, 404 405 405 406 /* Sound Devices USBPre2 */ 406 407 { USB_DEVICE(0x0926, 0x0202), .driver_info = ··· 493 492 /* Razer - Razer Blade Keyboard */ 494 493 { USB_DEVICE(0x1532, 0x0116), .driver_info = 495 494 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, 495 + /* Razer - Razer Kiyo Pro Webcam */ 496 + { USB_DEVICE(0x1532, 0x0e05), .driver_info = USB_QUIRK_NO_LPM }, 496 497 497 498 /* Lenovo ThinkPad OneLink+ Dock twin hub controllers (VIA Labs VL812) */ 498 499 { USB_DEVICE(0x17ef, 0x1018), .driver_info = USB_QUIRK_RESET_RESUME },
+1
drivers/usb/core/usb.c
··· 671 671 set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); 672 672 dev->state = USB_STATE_ATTACHED; 673 673 dev->lpm_disable_count = 1; 674 + spin_lock_init(&dev->offload_lock); 674 675 dev->offload_usage = 0; 675 676 atomic_set(&dev->urbnum, 0); 676 677
+2
drivers/usb/dwc2/gadget.c
··· 4607 4607 /* Exit clock gating when driver is stopped. */ 4608 4608 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && 4609 4609 hsotg->bus_suspended && !hsotg->params.no_clock_gating) { 4610 + spin_lock_irqsave(&hsotg->lock, flags); 4610 4611 dwc2_gadget_exit_clock_gating(hsotg, 0); 4612 + spin_unlock_irqrestore(&hsotg->lock, flags); 4611 4613 } 4612 4614 4613 4615 /* all endpoints should be shutdown */
+3 -2
drivers/usb/dwc3/dwc3-google.c
··· 385 385 "google,usb-cfg-csr", 386 386 ARRAY_SIZE(args), args); 387 387 if (IS_ERR(google->usb_cfg_regmap)) { 388 - return dev_err_probe(dev, PTR_ERR(google->usb_cfg_regmap), 389 - "invalid usb cfg csr\n"); 388 + ret = dev_err_probe(dev, PTR_ERR(google->usb_cfg_regmap), 389 + "invalid usb cfg csr\n"); 390 + goto err_deinit_pdom; 390 391 } 391 392 392 393 google->host_cfg_offset = args[0];
+1 -1
drivers/usb/dwc3/dwc3-imx8mp.c
··· 263 263 dwc3 = platform_get_drvdata(dwc3_imx->dwc3_pdev); 264 264 if (!dwc3) { 265 265 err = dev_err_probe(dev, -EPROBE_DEFER, "failed to get dwc3 platform data\n"); 266 - goto depopulate; 266 + goto put_dwc3; 267 267 } 268 268 269 269 dwc3->glue_ops = &dwc3_imx_glue_ops;
+23 -12
drivers/usb/gadget/function/f_ecm.c
··· 681 681 struct usb_ep *ep; 682 682 683 683 struct f_ecm_opts *ecm_opts; 684 + struct net_device *net __free(detach_gadget) = NULL; 684 685 struct usb_request *request __free(free_usb_request) = NULL; 685 686 686 687 if (!can_support_ecm(cdev->gadget)) ··· 689 688 690 689 ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst); 691 690 692 - mutex_lock(&ecm_opts->lock); 691 + scoped_guard(mutex, &ecm_opts->lock) 692 + if (ecm_opts->bind_count == 0 && !ecm_opts->bound) { 693 + if (!device_is_registered(&ecm_opts->net->dev)) { 694 + gether_set_gadget(ecm_opts->net, cdev->gadget); 695 + status = gether_register_netdev(ecm_opts->net); 696 + } else 697 + status = gether_attach_gadget(ecm_opts->net, cdev->gadget); 693 698 694 - gether_set_gadget(ecm_opts->net, cdev->gadget); 695 - 696 - if (!ecm_opts->bound) { 697 - status = gether_register_netdev(ecm_opts->net); 698 - ecm_opts->bound = true; 699 - } 700 - 701 - mutex_unlock(&ecm_opts->lock); 702 - if (status) 703 - return status; 699 + if (status) 700 + return status; 701 + net = ecm_opts->net; 702 + } 704 703 705 704 ecm_string_defs[1].s = ecm->ethaddr; 706 705 ··· 791 790 792 791 ecm->notify_req = no_free_ptr(request); 793 792 793 + ecm_opts->bind_count++; 794 + retain_and_null_ptr(net); 795 + 794 796 DBG(cdev, "CDC Ethernet: IN/%s OUT/%s NOTIFY/%s\n", 795 797 ecm->port.in_ep->name, ecm->port.out_ep->name, 796 798 ecm->notify->name); ··· 840 836 struct f_ecm_opts *opts; 841 837 842 838 opts = container_of(f, struct f_ecm_opts, func_inst); 843 - if (opts->bound) 839 + if (device_is_registered(&opts->net->dev)) 844 840 gether_cleanup(netdev_priv(opts->net)); 845 841 else 846 842 free_netdev(opts->net); ··· 910 906 static void ecm_unbind(struct usb_configuration *c, struct usb_function *f) 911 907 { 912 908 struct f_ecm *ecm = func_to_ecm(f); 909 + struct f_ecm_opts *ecm_opts; 913 910 914 911 DBG(c->cdev, "ecm unbind\n"); 912 + 913 + ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst); 915 914 916 915 usb_free_all_descriptors(f); 917 916 ··· 925 918 926 919 kfree(ecm->notify_req->buf); 927 920 usb_ep_free_request(ecm->notify, ecm->notify_req); 921 + 922 + ecm_opts->bind_count--; 923 + if (ecm_opts->bind_count == 0 && !ecm_opts->bound) 924 + gether_detach_gadget(ecm_opts->net); 928 925 } 929 926 930 927 static struct usb_function *ecm_alloc(struct usb_function_instance *fi)
+31 -28
drivers/usb/gadget/function/f_eem.c
··· 7 7 * Copyright (C) 2009 EF Johnson Technologies 8 8 */ 9 9 10 + #include <linux/cleanup.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/module.h> 12 13 #include <linux/device.h> ··· 252 251 struct usb_ep *ep; 253 252 254 253 struct f_eem_opts *eem_opts; 254 + struct net_device *net __free(detach_gadget) = NULL; 255 255 256 256 eem_opts = container_of(f->fi, struct f_eem_opts, func_inst); 257 - /* 258 - * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 259 - * configurations are bound in sequence with list_for_each_entry, 260 - * in each configuration its functions are bound in sequence 261 - * with list_for_each_entry, so we assume no race condition 262 - * with regard to eem_opts->bound access 263 - */ 264 - if (!eem_opts->bound) { 265 - mutex_lock(&eem_opts->lock); 266 - gether_set_gadget(eem_opts->net, cdev->gadget); 267 - status = gether_register_netdev(eem_opts->net); 268 - mutex_unlock(&eem_opts->lock); 269 - if (status) 270 - return status; 271 - eem_opts->bound = true; 272 - } 257 + 258 + scoped_guard(mutex, &eem_opts->lock) 259 + if (eem_opts->bind_count == 0 && !eem_opts->bound) { 260 + if (!device_is_registered(&eem_opts->net->dev)) { 261 + gether_set_gadget(eem_opts->net, cdev->gadget); 262 + status = gether_register_netdev(eem_opts->net); 263 + } else 264 + status = gether_attach_gadget(eem_opts->net, cdev->gadget); 265 + 266 + if (status) 267 + return status; 268 + net = eem_opts->net; 269 + } 273 270 274 271 us = usb_gstrings_attach(cdev, eem_strings, 275 272 ARRAY_SIZE(eem_string_defs)); ··· 278 279 /* allocate instance-specific interface IDs */ 279 280 status = usb_interface_id(c, f); 280 281 if (status < 0) 281 - goto fail; 282 + return status; 282 283 eem->ctrl_id = status; 283 284 eem_intf.bInterfaceNumber = status; 284 - 285 - status = -ENODEV; 286 285 287 286 /* allocate instance-specific endpoints */ 288 287 ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_in_desc); 289 288 if (!ep) 290 - goto fail; 289 + return -ENODEV; 291 290 eem->port.in_ep = ep; 292 291 293 292 ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_out_desc); 294 293 if (!ep) 295 - goto fail; 294 + return -ENODEV; 296 295 eem->port.out_ep = ep; 297 296 298 297 /* support all relevant hardware speeds... we expect that when ··· 306 309 status = usb_assign_descriptors(f, eem_fs_function, eem_hs_function, 307 310 eem_ss_function, eem_ss_function); 308 311 if (status) 309 - goto fail; 312 + return status; 313 + 314 + eem_opts->bind_count++; 315 + retain_and_null_ptr(net); 310 316 311 317 DBG(cdev, "CDC Ethernet (EEM): IN/%s OUT/%s\n", 312 318 eem->port.in_ep->name, eem->port.out_ep->name); 313 319 return 0; 314 - 315 - fail: 316 - ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 317 - 318 - return status; 319 320 } 320 321 321 322 static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req) ··· 592 597 struct f_eem_opts *opts; 593 598 594 599 opts = container_of(f, struct f_eem_opts, func_inst); 595 - if (opts->bound) 600 + if (device_is_registered(&opts->net->dev)) 596 601 gether_cleanup(netdev_priv(opts->net)); 597 602 else 598 603 free_netdev(opts->net); ··· 635 640 636 641 static void eem_unbind(struct usb_configuration *c, struct usb_function *f) 637 642 { 643 + struct f_eem_opts *opts; 644 + 638 645 DBG(c->cdev, "eem unbind\n"); 639 646 647 + opts = container_of(f->fi, struct f_eem_opts, func_inst); 648 + 640 649 usb_free_all_descriptors(f); 650 + 651 + opts->bind_count--; 652 + if (opts->bind_count == 0 && !opts->bound) 653 + gether_detach_gadget(opts->net); 641 654 } 642 655 643 656 static struct usb_function *eem_alloc(struct usb_function_instance *fi)
+10 -9
drivers/usb/gadget/function/f_hid.c
··· 1262 1262 if (status) 1263 1263 goto fail; 1264 1264 1265 - spin_lock_init(&hidg->write_spinlock); 1266 1265 hidg->write_pending = 1; 1267 1266 hidg->req = NULL; 1268 - spin_lock_init(&hidg->read_spinlock); 1269 - spin_lock_init(&hidg->get_report_spinlock); 1270 - init_waitqueue_head(&hidg->write_queue); 1271 - init_waitqueue_head(&hidg->read_queue); 1272 - init_waitqueue_head(&hidg->get_queue); 1273 - init_waitqueue_head(&hidg->get_id_queue); 1274 - INIT_LIST_HEAD(&hidg->completed_out_req); 1275 - INIT_LIST_HEAD(&hidg->report_list); 1276 1267 1277 1268 INIT_WORK(&hidg->work, get_report_workqueue_handler); 1278 1269 hidg->workqueue = alloc_workqueue("report_work", ··· 1598 1607 opts = container_of(fi, struct f_hid_opts, func_inst); 1599 1608 1600 1609 mutex_lock(&opts->lock); 1610 + 1611 + spin_lock_init(&hidg->write_spinlock); 1612 + spin_lock_init(&hidg->read_spinlock); 1613 + spin_lock_init(&hidg->get_report_spinlock); 1614 + init_waitqueue_head(&hidg->write_queue); 1615 + init_waitqueue_head(&hidg->read_queue); 1616 + init_waitqueue_head(&hidg->get_queue); 1617 + init_waitqueue_head(&hidg->get_id_queue); 1618 + INIT_LIST_HEAD(&hidg->completed_out_req); 1619 + INIT_LIST_HEAD(&hidg->report_list); 1601 1620 1602 1621 device_initialize(&hidg->dev); 1603 1622 hidg->dev.release = hidg_release;
+30 -19
drivers/usb/gadget/function/f_rndis.c
··· 11 11 12 12 /* #define VERBOSE_DEBUG */ 13 13 14 + #include <linux/cleanup.h> 14 15 #include <linux/slab.h> 15 16 #include <linux/kernel.h> 16 17 #include <linux/module.h> ··· 666 665 667 666 struct f_rndis_opts *rndis_opts; 668 667 struct usb_os_desc_table *os_desc_table __free(kfree) = NULL; 668 + struct net_device *net __free(detach_gadget) = NULL; 669 669 struct usb_request *request __free(free_usb_request) = NULL; 670 670 671 671 if (!can_support_rndis(c)) ··· 680 678 return -ENOMEM; 681 679 } 682 680 683 - rndis_iad_descriptor.bFunctionClass = rndis_opts->class; 684 - rndis_iad_descriptor.bFunctionSubClass = rndis_opts->subclass; 685 - rndis_iad_descriptor.bFunctionProtocol = rndis_opts->protocol; 681 + scoped_guard(mutex, &rndis_opts->lock) { 682 + rndis_iad_descriptor.bFunctionClass = rndis_opts->class; 683 + rndis_iad_descriptor.bFunctionSubClass = rndis_opts->subclass; 684 + rndis_iad_descriptor.bFunctionProtocol = rndis_opts->protocol; 686 685 687 - /* 688 - * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 689 - * configurations are bound in sequence with list_for_each_entry, 690 - * in each configuration its functions are bound in sequence 691 - * with list_for_each_entry, so we assume no race condition 692 - * with regard to rndis_opts->bound access 693 - */ 694 - if (!rndis_opts->bound) { 695 - gether_set_gadget(rndis_opts->net, cdev->gadget); 696 - status = gether_register_netdev(rndis_opts->net); 697 - if (status) 698 - return status; 699 - rndis_opts->bound = true; 686 + if (rndis_opts->bind_count == 0 && !rndis_opts->borrowed_net) { 687 + if (!device_is_registered(&rndis_opts->net->dev)) { 688 + gether_set_gadget(rndis_opts->net, cdev->gadget); 689 + status = gether_register_netdev(rndis_opts->net); 690 + } else 691 + status = gether_attach_gadget(rndis_opts->net, cdev->gadget); 692 + 693 + if (status) 694 + return status; 695 + net = rndis_opts->net; 696 + } 700 697 } 701 698 702 699 us = usb_gstrings_attach(cdev, rndis_strings, ··· 794 793 } 795 794 rndis->notify_req = no_free_ptr(request); 796 795 796 + rndis_opts->bind_count++; 797 + retain_and_null_ptr(net); 798 + 797 799 /* NOTE: all that is done without knowing or caring about 798 800 * the network link ... which is unavailable to this code 799 801 * until we're activated via set_alt(). ··· 813 809 struct f_rndis_opts *opts; 814 810 815 811 opts = container_of(f, struct f_rndis_opts, func_inst); 816 - if (opts->bound) 812 + if (device_is_registered(&opts->net->dev)) 817 813 gether_cleanup(netdev_priv(opts->net)); 818 814 else 819 815 free_netdev(opts->net); 820 - opts->borrowed_net = opts->bound = true; 816 + opts->borrowed_net = true; 821 817 opts->net = net; 822 818 } 823 819 EXPORT_SYMBOL_GPL(rndis_borrow_net); ··· 875 871 876 872 opts = container_of(f, struct f_rndis_opts, func_inst); 877 873 if (!opts->borrowed_net) { 878 - if (opts->bound) 874 + if (device_is_registered(&opts->net->dev)) 879 875 gether_cleanup(netdev_priv(opts->net)); 880 876 else 881 877 free_netdev(opts->net); ··· 944 940 static void rndis_unbind(struct usb_configuration *c, struct usb_function *f) 945 941 { 946 942 struct f_rndis *rndis = func_to_rndis(f); 943 + struct f_rndis_opts *rndis_opts; 944 + 945 + rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); 947 946 948 947 kfree(f->os_desc_table); 949 948 f->os_desc_n = 0; ··· 954 947 955 948 kfree(rndis->notify_req->buf); 956 949 usb_ep_free_request(rndis->notify, rndis->notify_req); 950 + 951 + rndis_opts->bind_count--; 952 + if (rndis_opts->bind_count == 0 && !rndis_opts->borrowed_net) 953 + gether_detach_gadget(rndis_opts->net); 957 954 } 958 955 959 956 static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
+35 -28
drivers/usb/gadget/function/f_subset.c
··· 6 6 * Copyright (C) 2008 Nokia Corporation 7 7 */ 8 8 9 + #include <linux/cleanup.h> 9 10 #include <linux/slab.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/module.h> ··· 299 298 struct usb_ep *ep; 300 299 301 300 struct f_gether_opts *gether_opts; 301 + struct net_device *net __free(detach_gadget) = NULL; 302 302 303 303 gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); 304 304 305 - /* 306 - * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 307 - * configurations are bound in sequence with list_for_each_entry, 308 - * in each configuration its functions are bound in sequence 309 - * with list_for_each_entry, so we assume no race condition 310 - * with regard to gether_opts->bound access 311 - */ 312 - if (!gether_opts->bound) { 313 - mutex_lock(&gether_opts->lock); 314 - gether_set_gadget(gether_opts->net, cdev->gadget); 315 - status = gether_register_netdev(gether_opts->net); 316 - mutex_unlock(&gether_opts->lock); 317 - if (status) 318 - return status; 319 - gether_opts->bound = true; 320 - } 305 + scoped_guard(mutex, &gether_opts->lock) 306 + if (gether_opts->bind_count == 0 && !gether_opts->bound) { 307 + if (!device_is_registered(&gether_opts->net->dev)) { 308 + gether_set_gadget(gether_opts->net, cdev->gadget); 309 + status = gether_register_netdev(gether_opts->net); 310 + } else 311 + status = gether_attach_gadget(gether_opts->net, cdev->gadget); 312 + 313 + if (status) 314 + return status; 315 + net = gether_opts->net; 316 + } 321 317 322 318 us = usb_gstrings_attach(cdev, geth_strings, 323 319 ARRAY_SIZE(geth_string_defs)); ··· 327 329 /* allocate instance-specific interface IDs */ 328 330 status = usb_interface_id(c, f); 329 331 if (status < 0) 330 - goto fail; 332 + return status; 331 333 subset_data_intf.bInterfaceNumber = status; 332 - 333 - status = -ENODEV; 334 334 335 335 /* allocate instance-specific endpoints */ 336 336 ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_in_desc); 337 337 if (!ep) 338 - goto fail; 338 + return -ENODEV; 339 339 geth->port.in_ep = ep; 340 340 341 341 ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_out_desc); 342 342 if (!ep) 343 - goto fail; 343 + return -ENODEV; 344 344 geth->port.out_ep = ep; 345 345 346 346 /* support all relevant hardware speeds... we expect that when ··· 356 360 status = usb_assign_descriptors(f, fs_eth_function, hs_eth_function, 357 361 ss_eth_function, ss_eth_function); 358 362 if (status) 359 - goto fail; 363 + return status; 360 364 361 365 /* NOTE: all that is done without knowing or caring about 362 366 * the network link ... which is unavailable to this code 363 367 * until we're activated via set_alt(). 364 368 */ 365 369 370 + gether_opts->bind_count++; 371 + retain_and_null_ptr(net); 372 + 366 373 DBG(cdev, "CDC Subset: IN/%s OUT/%s\n", 367 374 geth->port.in_ep->name, geth->port.out_ep->name); 368 375 return 0; 369 - 370 - fail: 371 - ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 372 - 373 - return status; 374 376 } 375 377 376 378 static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) ··· 411 417 struct f_gether_opts *opts; 412 418 413 419 opts = container_of(f, struct f_gether_opts, func_inst); 414 - if (opts->bound) 420 + if (device_is_registered(&opts->net->dev)) 415 421 gether_cleanup(netdev_priv(opts->net)); 416 422 else 417 423 free_netdev(opts->net); ··· 443 449 static void geth_free(struct usb_function *f) 444 450 { 445 451 struct f_gether *eth; 452 + struct f_gether_opts *opts; 453 + 454 + opts = container_of(f->fi, struct f_gether_opts, func_inst); 446 455 447 456 eth = func_to_geth(f); 457 + scoped_guard(mutex, &opts->lock) 458 + opts->refcnt--; 448 459 kfree(eth); 449 460 } 450 461 451 462 static void geth_unbind(struct usb_configuration *c, struct usb_function *f) 452 463 { 464 + struct f_gether_opts *opts; 465 + 466 + opts = container_of(f->fi, struct f_gether_opts, func_inst); 467 + 453 468 geth_string_defs[0].id = 0; 454 469 usb_free_all_descriptors(f); 470 + 471 + opts->bind_count--; 472 + if (opts->bind_count == 0 && !opts->bound) 473 + gether_detach_gadget(opts->net); 455 474 } 456 475 457 476 static struct usb_function *geth_alloc(struct usb_function_instance *fi)
+37 -10
drivers/usb/gadget/function/f_uac1_legacy.c
··· 360 360 static void f_audio_complete(struct usb_ep *ep, struct usb_request *req) 361 361 { 362 362 struct f_audio *audio = req->context; 363 - int status = req->status; 364 - u32 data = 0; 365 363 struct usb_ep *out_ep = audio->out_ep; 366 364 367 - switch (status) { 368 - 369 - case 0: /* normal completion? */ 370 - if (ep == out_ep) 365 + switch (req->status) { 366 + case 0: 367 + if (ep == out_ep) { 371 368 f_audio_out_ep_complete(ep, req); 372 - else if (audio->set_con) { 373 - memcpy(&data, req->buf, req->length); 374 - audio->set_con->set(audio->set_con, audio->set_cmd, 375 - le16_to_cpu(data)); 369 + } else if (audio->set_con) { 370 + struct usb_audio_control *con = audio->set_con; 371 + u8 type = con->type; 372 + u32 data; 373 + bool valid_request = false; 374 + 375 + switch (type) { 376 + case UAC_FU_MUTE: { 377 + u8 value; 378 + 379 + if (req->actual == sizeof(value)) { 380 + memcpy(&value, req->buf, sizeof(value)); 381 + data = value; 382 + valid_request = true; 383 + } 384 + break; 385 + } 386 + case UAC_FU_VOLUME: { 387 + __le16 value; 388 + 389 + if (req->actual == sizeof(value)) { 390 + memcpy(&value, req->buf, sizeof(value)); 391 + data = le16_to_cpu(value); 392 + valid_request = true; 393 + } 394 + break; 395 + } 396 + } 397 + 398 + if (valid_request) 399 + con->set(con, audio->set_cmd, data); 400 + else 401 + usb_ep_set_halt(ep); 402 + 376 403 audio->set_con = NULL; 377 404 } 378 405 break;
+36 -3
drivers/usb/gadget/function/f_uvc.c
··· 413 413 { 414 414 int ret; 415 415 416 + guard(mutex)(&uvc->lock); 417 + if (uvc->func_unbound) { 418 + dev_dbg(&uvc->vdev.dev, "skipping function deactivate (unbound)\n"); 419 + return; 420 + } 421 + 416 422 if ((ret = usb_function_deactivate(&uvc->func)) < 0) 417 423 uvcg_info(&uvc->func, "UVC disconnect failed with %d\n", ret); 418 424 } ··· 437 431 438 432 static DEVICE_ATTR_RO(function_name); 439 433 434 + static void uvc_vdev_release(struct video_device *vdev) 435 + { 436 + struct uvc_device *uvc = video_get_drvdata(vdev); 437 + 438 + /* Signal uvc_function_unbind() that the video device has been released */ 439 + if (uvc->vdev_release_done) 440 + complete(uvc->vdev_release_done); 441 + } 442 + 440 443 static int 441 444 uvc_register_video(struct uvc_device *uvc) 442 445 { ··· 458 443 uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev; 459 444 uvc->vdev.fops = &uvc_v4l2_fops; 460 445 uvc->vdev.ioctl_ops = &uvc_v4l2_ioctl_ops; 461 - uvc->vdev.release = video_device_release_empty; 446 + uvc->vdev.release = uvc_vdev_release; 462 447 uvc->vdev.vfl_dir = VFL_DIR_TX; 463 448 uvc->vdev.lock = &uvc->video.mutex; 464 449 uvc->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; ··· 674 659 int ret = -EINVAL; 675 660 676 661 uvcg_info(f, "%s()\n", __func__); 662 + scoped_guard(mutex, &uvc->lock) 663 + uvc->func_unbound = false; 677 664 678 665 opts = fi_to_f_uvc_opts(f->fi); 679 666 /* Sanity check the streaming endpoint module parameters. */ ··· 1005 988 static void uvc_function_unbind(struct usb_configuration *c, 1006 989 struct usb_function *f) 1007 990 { 991 + DECLARE_COMPLETION_ONSTACK(vdev_release_done); 1008 992 struct usb_composite_dev *cdev = c->cdev; 1009 993 struct uvc_device *uvc = to_uvc(f); 1010 994 struct uvc_video *video = &uvc->video; 1011 995 long wait_ret = 1; 996 + bool connected; 1012 997 1013 998 uvcg_info(f, "%s()\n", __func__); 999 + scoped_guard(mutex, &uvc->lock) { 1000 + uvc->func_unbound = true; 1001 + uvc->vdev_release_done = &vdev_release_done; 1002 + connected = uvc->func_connected; 1003 + } 1014 1004 1015 1005 kthread_cancel_work_sync(&video->hw_submit); 1016 1006 ··· 1030 1006 * though the video device removal uevent. Allow some time for the 1031 1007 * application to close out before things get deleted. 1032 1008 */ 1033 - if (uvc->func_connected) { 1009 + if (connected) { 1034 1010 uvcg_dbg(f, "waiting for clean disconnect\n"); 1035 1011 wait_ret = wait_event_interruptible_timeout(uvc->func_connected_queue, 1036 1012 uvc->func_connected == false, msecs_to_jiffies(500)); ··· 1041 1017 video_unregister_device(&uvc->vdev); 1042 1018 v4l2_device_unregister(&uvc->v4l2_dev); 1043 1019 1044 - if (uvc->func_connected) { 1020 + scoped_guard(mutex, &uvc->lock) 1021 + connected = uvc->func_connected; 1022 + 1023 + if (connected) { 1045 1024 /* 1046 1025 * Wait for the release to occur to ensure there are no longer any 1047 1026 * pending operations that may cause panics when resources are cleaned ··· 1055 1028 uvc->func_connected == false, msecs_to_jiffies(1000)); 1056 1029 uvcg_dbg(f, "done waiting for release with ret: %ld\n", wait_ret); 1057 1030 } 1031 + 1032 + /* Wait for the video device to be released */ 1033 + wait_for_completion(&vdev_release_done); 1034 + uvc->vdev_release_done = NULL; 1058 1035 1059 1036 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 1060 1037 kfree(uvc->control_buf); ··· 1078 1047 return ERR_PTR(-ENOMEM); 1079 1048 1080 1049 mutex_init(&uvc->video.mutex); 1050 + mutex_init(&uvc->lock); 1051 + uvc->func_unbound = true; 1081 1052 uvc->state = UVC_STATE_DISCONNECTED; 1082 1053 init_waitqueue_head(&uvc->func_connected_queue); 1083 1054 opts = fi_to_f_uvc_opts(fi);
+15 -6
drivers/usb/gadget/function/u_ecm.h
··· 15 15 16 16 #include <linux/usb/composite.h> 17 17 18 + /** 19 + * struct f_ecm_opts - ECM function options 20 + * @func_inst: USB function instance. 21 + * @net: The net_device associated with the ECM function. 22 + * @bound: True if the net_device is shared and pre-registered during the 23 + * legacy composite driver's bind phase (e.g., multi.c). If false, 24 + * the ECM function will register the net_device during its own 25 + * bind phase. 26 + * @bind_count: Tracks the number of configurations the ECM function is 27 + * bound to, preventing double-registration of the @net device. 28 + * @lock: Protects the data from concurrent access by configfs read/write 29 + * and create symlink/remove symlink operations. 30 + * @refcnt: Reference counter for the function instance. 31 + */ 18 32 struct f_ecm_opts { 19 33 struct usb_function_instance func_inst; 20 34 struct net_device *net; 21 35 bool bound; 36 + int bind_count; 22 37 23 - /* 24 - * Read/write access to configfs attributes is handled by configfs. 25 - * 26 - * This is to protect the data from concurrent access by read/write 27 - * and create symlink/remove symlink. 28 - */ 29 38 struct mutex lock; 30 39 int refcnt; 31 40 };
+15 -6
drivers/usb/gadget/function/u_eem.h
··· 15 15 16 16 #include <linux/usb/composite.h> 17 17 18 + /** 19 + * struct f_eem_opts - EEM function options 20 + * @func_inst: USB function instance. 21 + * @net: The net_device associated with the EEM function. 22 + * @bound: True if the net_device is shared and pre-registered during the 23 + * legacy composite driver's bind phase (e.g., multi.c). If false, 24 + * the EEM function will register the net_device during its own 25 + * bind phase. 26 + * @bind_count: Tracks the number of configurations the EEM function is 27 + * bound to, preventing double-registration of the @net device. 28 + * @lock: Protects the data from concurrent access by configfs read/write 29 + * and create symlink/remove symlink operations. 30 + * @refcnt: Reference counter for the function instance. 31 + */ 18 32 struct f_eem_opts { 19 33 struct usb_function_instance func_inst; 20 34 struct net_device *net; 21 35 bool bound; 36 + int bind_count; 22 37 23 - /* 24 - * Read/write access to configfs attributes is handled by configfs. 25 - * 26 - * This is to protect the data from concurrent access by read/write 27 - * and create symlink/remove symlink. 28 - */ 29 38 struct mutex lock; 30 39 int refcnt; 31 40 };
+9 -7
drivers/usb/gadget/function/u_ether.c
··· 113 113 114 114 strscpy(p->driver, "g_ether", sizeof(p->driver)); 115 115 strscpy(p->version, UETH__VERSION, sizeof(p->version)); 116 - strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); 117 - strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); 116 + if (dev->gadget) { 117 + strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); 118 + strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); 119 + } 118 120 } 119 121 120 122 /* REVISIT can also support: ··· 1225 1223 1226 1224 DBG(dev, "%s\n", __func__); 1227 1225 1226 + spin_lock(&dev->lock); 1227 + dev->port_usb = NULL; 1228 + link->is_suspend = false; 1229 + spin_unlock(&dev->lock); 1230 + 1228 1231 netif_stop_queue(dev->net); 1229 1232 netif_carrier_off(dev->net); 1230 1233 ··· 1267 1260 dev->header_len = 0; 1268 1261 dev->unwrap = NULL; 1269 1262 dev->wrap = NULL; 1270 - 1271 - spin_lock(&dev->lock); 1272 - dev->port_usb = NULL; 1273 - link->is_suspend = false; 1274 - spin_unlock(&dev->lock); 1275 1263 } 1276 1264 EXPORT_SYMBOL_GPL(gether_disconnect); 1277 1265
+15 -7
drivers/usb/gadget/function/u_gether.h
··· 15 15 16 16 #include <linux/usb/composite.h> 17 17 18 + /** 19 + * struct f_gether_opts - subset function options 20 + * @func_inst: USB function instance. 21 + * @net: The net_device associated with the subset function. 22 + * @bound: True if the net_device is shared and pre-registered during the 23 + * legacy composite driver's bind phase (e.g., multi.c). If false, 24 + * the subset function will register the net_device during its own 25 + * bind phase. 26 + * @bind_count: Tracks the number of configurations the subset function is 27 + * bound to, preventing double-registration of the @net device. 28 + * @lock: Protects the data from concurrent access by configfs read/write 29 + * and create symlink/remove symlink operations. 30 + * @refcnt: Reference counter for the function instance. 31 + */ 18 32 struct f_gether_opts { 19 33 struct usb_function_instance func_inst; 20 34 struct net_device *net; 21 35 bool bound; 22 - 23 - /* 24 - * Read/write access to configfs attributes is handled by configfs. 25 - * 26 - * This is to protect the data from concurrent access by read/write 27 - * and create symlink/remove symlink. 28 - */ 36 + int bind_count; 29 37 struct mutex lock; 30 38 int refcnt; 31 39 };
+15 -6
drivers/usb/gadget/function/u_ncm.h
··· 15 15 16 16 #include <linux/usb/composite.h> 17 17 18 + /** 19 + * struct f_ncm_opts - NCM function options 20 + * @func_inst: USB function instance. 21 + * @net: The net_device associated with the NCM function. 22 + * @bind_count: Tracks the number of configurations the NCM function is 23 + * bound to, preventing double-registration of the @net device. 24 + * @ncm_interf_group: ConfigFS group for NCM interface. 25 + * @ncm_os_desc: USB OS descriptor for NCM. 26 + * @ncm_ext_compat_id: Extended compatibility ID. 27 + * @lock: Protects the data from concurrent access by configfs read/write 28 + * and create symlink/remove symlink operations. 29 + * @refcnt: Reference counter for the function instance. 30 + * @max_segment_size: Maximum segment size. 31 + */ 18 32 struct f_ncm_opts { 19 33 struct usb_function_instance func_inst; 20 34 struct net_device *net; ··· 37 23 struct config_group *ncm_interf_group; 38 24 struct usb_os_desc ncm_os_desc; 39 25 char ncm_ext_compat_id[16]; 40 - /* 41 - * Read/write access to configfs attributes is handled by configfs. 42 - * 43 - * This is to protect the data from concurrent access by read/write 44 - * and create symlink/remove symlink. 45 - */ 26 + 46 27 struct mutex lock; 47 28 int refcnt; 48 29
+23 -8
drivers/usb/gadget/function/u_rndis.h
··· 15 15 16 16 #include <linux/usb/composite.h> 17 17 18 + /** 19 + * struct f_rndis_opts - RNDIS function options 20 + * @func_inst: USB function instance. 21 + * @vendor_id: Vendor ID. 22 + * @manufacturer: Manufacturer string. 23 + * @net: The net_device associated with the RNDIS function. 24 + * @bind_count: Tracks the number of configurations the RNDIS function is 25 + * bound to, preventing double-registration of the @net device. 26 + * @borrowed_net: True if the net_device is shared and pre-registered during 27 + * the legacy composite driver's bind phase (e.g., multi.c). 28 + * If false, the RNDIS function will register the net_device 29 + * during its own bind phase. 30 + * @rndis_interf_group: ConfigFS group for RNDIS interface. 31 + * @rndis_os_desc: USB OS descriptor for RNDIS. 32 + * @rndis_ext_compat_id: Extended compatibility ID. 33 + * @class: USB class. 34 + * @subclass: USB subclass. 35 + * @protocol: USB protocol. 36 + * @lock: Protects the data from concurrent access by configfs read/write 37 + * and create symlink/remove symlink operations. 38 + * @refcnt: Reference counter for the function instance. 39 + */ 18 40 struct f_rndis_opts { 19 41 struct usb_function_instance func_inst; 20 42 u32 vendor_id; 21 43 const char *manufacturer; 22 44 struct net_device *net; 23 - bool bound; 45 + int bind_count; 24 46 bool borrowed_net; 25 47 26 48 struct config_group *rndis_interf_group; ··· 52 30 u8 class; 53 31 u8 subclass; 54 32 u8 protocol; 55 - 56 - /* 57 - * Read/write access to configfs attributes is handled by configfs. 58 - * 59 - * This is to protect the data from concurrent access by read/write 60 - * and create symlink/remove symlink. 61 - */ 62 33 struct mutex lock; 63 34 int refcnt; 64 35 };
+3
drivers/usb/gadget/function/uvc.h
··· 155 155 enum uvc_state state; 156 156 struct usb_function func; 157 157 struct uvc_video video; 158 + struct completion *vdev_release_done; 159 + struct mutex lock; /* protects func_unbound and func_connected */ 160 + bool func_unbound; 158 161 bool func_connected; 159 162 wait_queue_head_t func_connected_queue; 160 163
+4 -1
drivers/usb/gadget/function/uvc_v4l2.c
··· 574 574 if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST) 575 575 return -EINVAL; 576 576 577 + guard(mutex)(&uvc->lock); 578 + 577 579 if (sub->type == UVC_EVENT_SETUP && uvc->func_connected) 578 580 return -EBUSY; 579 581 ··· 597 595 uvc_function_disconnect(uvc); 598 596 uvcg_video_disable(&uvc->video); 599 597 uvcg_free_buffers(&uvc->video.queue); 600 - uvc->func_connected = false; 598 + scoped_guard(mutex, &uvc->lock) 599 + uvc->func_connected = false; 601 600 wake_up_interruptible(&uvc->func_connected_queue); 602 601 } 603 602
+26 -16
drivers/usb/gadget/udc/dummy_hcd.c
··· 462 462 463 463 /* Report reset and disconnect events to the driver */ 464 464 if (dum->ints_enabled && (disconnect || reset)) { 465 - stop_activity(dum); 466 465 ++dum->callback_usage; 466 + /* 467 + * stop_activity() can drop dum->lock, so it must 468 + * not come between the dum->ints_enabled test 469 + * and the ++dum->callback_usage. 470 + */ 471 + stop_activity(dum); 467 472 spin_unlock(&dum->lock); 468 473 if (reset) 469 474 usb_gadget_udc_reset(&dum->gadget, dum->driver); ··· 913 908 spin_lock_irqsave(&dum->lock, flags); 914 909 dum->pullup = (value != 0); 915 910 set_link_state(dum_hcd); 916 - if (value == 0) { 917 - /* 918 - * Emulate synchronize_irq(): wait for callbacks to finish. 919 - * This seems to be the best place to emulate the call to 920 - * synchronize_irq() that's in usb_gadget_remove_driver(). 921 - * Doing it in dummy_udc_stop() would be too late since it 922 - * is called after the unbind callback and unbind shouldn't 923 - * be invoked until all the other callbacks are finished. 924 - */ 925 - while (dum->callback_usage > 0) { 926 - spin_unlock_irqrestore(&dum->lock, flags); 927 - usleep_range(1000, 2000); 928 - spin_lock_irqsave(&dum->lock, flags); 929 - } 930 - } 931 911 spin_unlock_irqrestore(&dum->lock, flags); 932 912 933 913 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd)); ··· 935 945 936 946 spin_lock_irq(&dum->lock); 937 947 dum->ints_enabled = enable; 948 + if (!enable) { 949 + /* 950 + * Emulate synchronize_irq(): wait for callbacks to finish. 951 + * This has to happen after emulated interrupts are disabled 952 + * (dum->ints_enabled is clear) and before the unbind callback, 953 + * just like the call to synchronize_irq() in 954 + * gadget/udc/core:gadget_unbind_driver(). 955 + */ 956 + while (dum->callback_usage > 0) { 957 + spin_unlock_irq(&dum->lock); 958 + usleep_range(1000, 2000); 959 + spin_lock_irq(&dum->lock); 960 + } 961 + } 938 962 spin_unlock_irq(&dum->lock); 939 963 } 940 964 ··· 1538 1534 /* rescan to continue with any other queued i/o */ 1539 1535 if (rescan) 1540 1536 goto top; 1537 + 1538 + /* request not fully transferred; stop iterating to 1539 + * preserve data ordering across queued requests. 1540 + */ 1541 + if (req->req.actual < req->req.length) 1542 + break; 1541 1543 } 1542 1544 return sent; 1543 1545 }
+2 -2
drivers/usb/host/ehci-brcm.c
··· 31 31 int res; 32 32 33 33 /* Wait for next microframe (every 125 usecs) */ 34 - res = readl_relaxed_poll_timeout(&ehci->regs->frame_index, val, 35 - val != frame_idx, 1, 130); 34 + res = readl_relaxed_poll_timeout_atomic(&ehci->regs->frame_index, 35 + val, val != frame_idx, 1, 130); 36 36 if (res) 37 37 ehci_err(ehci, "Error waiting for SOF\n"); 38 38 udelay(delay);
+3 -15
drivers/usb/host/xhci-sideband.c
··· 93 93 static void 94 94 __xhci_sideband_remove_interrupter(struct xhci_sideband *sb) 95 95 { 96 - struct usb_device *udev; 97 - 98 96 lockdep_assert_held(&sb->mutex); 99 97 100 98 if (!sb->ir) ··· 100 102 101 103 xhci_remove_secondary_interrupter(xhci_to_hcd(sb->xhci), sb->ir); 102 104 sb->ir = NULL; 103 - udev = sb->vdev->udev; 104 - 105 - if (udev->state != USB_STATE_NOTATTACHED) 106 - usb_offload_put(udev); 107 105 } 108 106 109 107 /* sideband api functions */ ··· 285 291 * Allow other drivers, such as usb controller driver, to check if there are 286 292 * any sideband activity on the host controller. This information could be used 287 293 * for power management or other forms of resource management. The caller should 288 - * ensure downstream usb devices are all either suspended or marked as 289 - * "offload_at_suspend" to ensure the correctness of the return value. 294 + * ensure downstream usb devices are all marked as "offload_pm_locked" to ensure 295 + * the correctness of the return value. 290 296 * 291 297 * Returns true on any active sideband existence, false otherwise. 292 298 */ ··· 322 328 xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, 323 329 bool ip_autoclear, u32 imod_interval, int intr_num) 324 330 { 325 - int ret = 0; 326 - struct usb_device *udev; 327 - 328 331 if (!sb || !sb->xhci) 329 332 return -ENODEV; 330 333 ··· 339 348 if (!sb->ir) 340 349 return -ENOMEM; 341 350 342 - udev = sb->vdev->udev; 343 - ret = usb_offload_get(udev); 344 - 345 351 sb->ir->ip_autoclear = ip_autoclear; 346 352 347 - return ret; 353 + return 0; 348 354 } 349 355 EXPORT_SYMBOL_GPL(xhci_sideband_create_interrupter); 350 356
+5 -2
drivers/usb/misc/usbio.c
··· 614 614 usb_fill_bulk_urb(usbio->urb, udev, usbio->rx_pipe, usbio->rxbuf, 615 615 usbio->rxbuf_len, usbio_bulk_recv, usbio); 616 616 ret = usb_submit_urb(usbio->urb, GFP_KERNEL); 617 - if (ret) 618 - return dev_err_probe(dev, ret, "Submitting usb urb\n"); 617 + if (ret) { 618 + dev_err_probe(dev, ret, "Submitting usb urb\n"); 619 + goto err_free_urb; 620 + } 619 621 620 622 mutex_lock(&usbio->ctrl_mutex); 621 623 ··· 665 663 err_unlock: 666 664 mutex_unlock(&usbio->ctrl_mutex); 667 665 usb_kill_urb(usbio->urb); 666 + err_free_urb: 668 667 usb_free_urb(usbio->urb); 669 668 670 669 return ret;
+3
drivers/usb/serial/io_edgeport.c
··· 73 73 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_22I) }, 74 74 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_412_4) }, 75 75 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_COMPATIBLE) }, 76 + { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_BLACKBOX_IC135A) }, 76 77 { } 77 78 }; 78 79 ··· 122 121 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8R) }, 123 122 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8RR) }, 124 123 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_412_8) }, 124 + { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_BLACKBOX_IC135A) }, 125 125 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0202) }, 126 126 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0203) }, 127 127 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0310) }, ··· 472 470 case ION_DEVICE_ID_EDGEPORT_2_DIN: 473 471 case ION_DEVICE_ID_EDGEPORT_4_DIN: 474 472 case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU: 473 + case ION_DEVICE_ID_BLACKBOX_IC135A: 475 474 product_info->IsRS232 = 1; 476 475 break; 477 476
+1
drivers/usb/serial/io_usbvend.h
··· 211 211 212 212 // 213 213 // Definitions for other product IDs 214 + #define ION_DEVICE_ID_BLACKBOX_IC135A 0x0801 // OEM device (rebranded Edgeport/4) 214 215 #define ION_DEVICE_ID_MT4X56USB 0x1403 // OEM device 215 216 #define ION_DEVICE_ID_E5805A 0x1A01 // OEM device (rebranded Edgeport/4) 216 217
+4
drivers/usb/serial/option.c
··· 2441 2441 { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d22, 0xff, 0xff, 0x30) }, /* MeiG Smart SRM815 and SRM825L */ 2442 2442 { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d22, 0xff, 0xff, 0x40) }, /* MeiG Smart SRM825L */ 2443 2443 { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d22, 0xff, 0xff, 0x60) }, /* MeiG Smart SRM825L */ 2444 + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d38, 0xff, 0xff, 0x30) }, /* MeiG Smart SRM825WN (Diag) */ 2445 + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d38, 0xff, 0xff, 0x40) }, /* MeiG Smart SRM825WN (AT) */ 2446 + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d38, 0xff, 0xff, 0x60) }, /* MeiG Smart SRM825WN (NMEA) */ 2444 2447 { USB_DEVICE_INTERFACE_CLASS(0x2df3, 0x9d03, 0xff) }, /* LongSung M5710 */ 2445 2448 { USB_DEVICE_INTERFACE_CLASS(0x305a, 0x1404, 0xff) }, /* GosunCn GM500 RNDIS */ 2446 2449 { USB_DEVICE_INTERFACE_CLASS(0x305a, 0x1405, 0xff) }, /* GosunCn GM500 MBIM */ ··· 2464 2461 { USB_DEVICE_INTERFACE_CLASS(0x33f8, 0x0302, 0xff) }, /* Rolling RW101R-GL (laptop MBIM) */ 2465 2462 { USB_DEVICE_INTERFACE_CLASS(0x33f8, 0x0802, 0xff), /* Rolling RW350-GL (laptop MBIM) */ 2466 2463 .driver_info = RSVD(5) }, 2464 + { USB_DEVICE_INTERFACE_CLASS(0x33f8, 0x1003, 0xff) }, /* Rolling RW135R-GL (laptop MBIM) */ 2467 2465 { USB_DEVICE_AND_INTERFACE_INFO(0x3731, 0x0100, 0xff, 0xff, 0x30) }, /* NetPrisma LCUK54-WWD for Global */ 2468 2466 { USB_DEVICE_AND_INTERFACE_INFO(0x3731, 0x0100, 0xff, 0x00, 0x40) }, 2469 2467 { USB_DEVICE_AND_INTERFACE_INFO(0x3731, 0x0100, 0xff, 0xff, 0x40) },
+22 -22
drivers/usb/typec/altmodes/thunderbolt.c
··· 39 39 40 40 static int tbt_enter_mode(struct tbt_altmode *tbt) 41 41 { 42 - struct typec_altmode *plug = tbt->plug[TYPEC_PLUG_SOP_P]; 43 - u32 vdo; 44 - 45 - vdo = tbt->alt->vdo & (TBT_VENDOR_SPECIFIC_B0 | TBT_VENDOR_SPECIFIC_B1); 46 - vdo |= tbt->alt->vdo & TBT_INTEL_SPECIFIC_B0; 47 - vdo |= TBT_MODE; 48 - 49 - if (plug) { 50 - if (typec_cable_is_active(tbt->cable)) 51 - vdo |= TBT_ENTER_MODE_ACTIVE_CABLE; 52 - 53 - vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_SPEED(plug->vdo)); 54 - vdo |= plug->vdo & TBT_CABLE_ROUNDED; 55 - vdo |= plug->vdo & TBT_CABLE_OPTICAL; 56 - vdo |= plug->vdo & TBT_CABLE_RETIMER; 57 - vdo |= plug->vdo & TBT_CABLE_LINK_TRAINING; 58 - } else { 59 - vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_USB3_PASSIVE); 60 - } 61 - 62 - tbt->enter_vdo = vdo; 63 - return typec_altmode_enter(tbt->alt, &vdo); 42 + return typec_altmode_enter(tbt->alt, &tbt->enter_vdo); 64 43 } 65 44 66 45 static void tbt_altmode_work(struct work_struct *work) ··· 316 337 { 317 338 struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 318 339 struct typec_altmode *plug; 340 + u32 vdo; 319 341 320 342 if (tbt->cable) 321 343 return true; ··· 343 363 344 364 tbt->plug[i] = plug; 345 365 } 366 + 367 + vdo = tbt->alt->vdo & (TBT_VENDOR_SPECIFIC_B0 | TBT_VENDOR_SPECIFIC_B1); 368 + vdo |= tbt->alt->vdo & TBT_INTEL_SPECIFIC_B0; 369 + vdo |= TBT_MODE; 370 + plug = tbt->plug[TYPEC_PLUG_SOP_P]; 371 + 372 + if (plug) { 373 + if (typec_cable_is_active(tbt->cable)) 374 + vdo |= TBT_ENTER_MODE_ACTIVE_CABLE; 375 + 376 + vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_SPEED(plug->vdo)); 377 + vdo |= plug->vdo & TBT_CABLE_ROUNDED; 378 + vdo |= plug->vdo & TBT_CABLE_OPTICAL; 379 + vdo |= plug->vdo & TBT_CABLE_RETIMER; 380 + vdo |= plug->vdo & TBT_CABLE_LINK_TRAINING; 381 + } else { 382 + vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_USB3_PASSIVE); 383 + } 384 + 385 + tbt->enter_vdo = vdo; 346 386 347 387 return true; 348 388 }
-4
drivers/usb/typec/class.c
··· 686 686 687 687 alt->adev.dev.bus = &typec_bus; 688 688 689 - /* Plug alt modes need a class to generate udev events. */ 690 - if (is_typec_plug(parent)) 691 - alt->adev.dev.class = &typec_class; 692 - 693 689 ret = device_register(&alt->adev.dev); 694 690 if (ret) { 695 691 dev_err(parent, "failed to register alternate mode (%d)\n",
+7 -2
drivers/usb/typec/ucsi/ucsi.c
··· 43 43 if (cci & UCSI_CCI_BUSY) 44 44 return; 45 45 46 - if (UCSI_CCI_CONNECTOR(cci)) 47 - ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci)); 46 + if (UCSI_CCI_CONNECTOR(cci)) { 47 + if (UCSI_CCI_CONNECTOR(cci) <= ucsi->cap.num_connectors) 48 + ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci)); 49 + else 50 + dev_err(ucsi->dev, "bogus connector number in CCI: %lu\n", 51 + UCSI_CCI_CONNECTOR(cci)); 52 + } 48 53 49 54 if (cci & UCSI_CCI_ACK_COMPLETE && 50 55 test_and_clear_bit(ACK_PENDING, &ucsi->flags))
+8 -2
include/linux/usb.h
··· 21 21 #include <linux/completion.h> /* for struct completion */ 22 22 #include <linux/sched.h> /* for current && schedule_timeout */ 23 23 #include <linux/mutex.h> /* for struct mutex */ 24 + #include <linux/spinlock.h> /* for spinlock_t */ 24 25 #include <linux/pm_runtime.h> /* for runtime PM */ 25 26 26 27 struct usb_device; ··· 637 636 * @do_remote_wakeup: remote wakeup should be enabled 638 637 * @reset_resume: needs reset instead of resume 639 638 * @port_is_suspended: the upstream port is suspended (L2 or U3) 640 - * @offload_at_suspend: offload activities during suspend is enabled. 639 + * @offload_pm_locked: prevents offload_usage changes during PM transitions. 641 640 * @offload_usage: number of offload activities happening on this usb device. 641 + * @offload_lock: protects offload_usage and offload_pm_locked 642 642 * @slot_id: Slot ID assigned by xHCI 643 643 * @l1_params: best effor service latency for USB2 L1 LPM state, and L1 timeout. 644 644 * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout. ··· 728 726 unsigned do_remote_wakeup:1; 729 727 unsigned reset_resume:1; 730 728 unsigned port_is_suspended:1; 731 - unsigned offload_at_suspend:1; 729 + unsigned offload_pm_locked:1; 732 730 int offload_usage; 731 + spinlock_t offload_lock; 733 732 enum usb_link_tunnel_mode tunnel_mode; 734 733 struct device_link *usb4_link; 735 734 ··· 852 849 int usb_offload_get(struct usb_device *udev); 853 850 int usb_offload_put(struct usb_device *udev); 854 851 bool usb_offload_check(struct usb_device *udev); 852 + void usb_offload_set_pm_locked(struct usb_device *udev, bool locked); 855 853 #else 856 854 857 855 static inline int usb_offload_get(struct usb_device *udev) ··· 861 857 { return 0; } 862 858 static inline bool usb_offload_check(struct usb_device *udev) 863 859 { return false; } 860 + static inline void usb_offload_set_pm_locked(struct usb_device *udev, bool locked) 861 + { } 864 862 #endif 865 863 866 864 extern int usb_disable_lpm(struct usb_device *udev);
+9 -1
sound/usb/qcom/qc_audio_offload.c
··· 699 699 uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, 700 700 PAGE_SIZE); 701 701 xhci_sideband_remove_interrupter(uadev[dev->chip->card->number].sb); 702 + usb_offload_put(dev->udev); 702 703 } 703 704 } 704 705 ··· 1183 1182 dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); 1184 1183 er_pa = 0; 1185 1184 1185 + ret = usb_offload_get(subs->dev); 1186 + if (ret < 0) 1187 + goto exit; 1188 + 1186 1189 /* event ring */ 1187 1190 ret = xhci_sideband_create_interrupter(uadev[card_num].sb, 1, false, 1188 1191 0, uaudio_qdev->data->intr_num); 1189 1192 if (ret < 0) { 1190 1193 dev_err(&subs->dev->dev, "failed to fetch interrupter\n"); 1191 - goto exit; 1194 + goto put_offload; 1192 1195 } 1193 1196 1194 1197 sgt = xhci_sideband_get_event_buffer(uadev[card_num].sb); ··· 1224 1219 mem_info->dma = 0; 1225 1220 remove_interrupter: 1226 1221 xhci_sideband_remove_interrupter(uadev[card_num].sb); 1222 + put_offload: 1223 + usb_offload_put(subs->dev); 1227 1224 exit: 1228 1225 return ret; 1229 1226 } ··· 1489 1482 uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE); 1490 1483 free_sec_ring: 1491 1484 xhci_sideband_remove_interrupter(uadev[card_num].sb); 1485 + usb_offload_put(subs->dev); 1492 1486 drop_sync_ep: 1493 1487 if (subs->sync_endpoint) { 1494 1488 uaudio_iommu_unmap(MEM_XFER_RING,