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-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB fixes from Greg KH:
"Here is a large chunk of USB driver fixes for 7.0-rc4. Included in
here are:

- usb gadget reverts due to reported issues, and then a follow-on fix
to hopefully resolve the reported overall problem

- xhci driver fixes

- dwc3 driver fixes

- usb core "killable" bulk message api addition to fix a usbtmc
driver bug where userspace could hang the driver for forever

- small USB driver fixes for reported issues

- new usb device quirks

All except the last USB device quirk change have been in linux-next
with no reported issues. That one came in too late, and is 'obviously
correct' :)"

* tag 'usb-7.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (35 commits)
USB: ezcap401 needs USB_QUIRK_NO_BOS to function on 10gbs usb speed
usb: roles: get usb role switch from parent only for usb-b-connector
Revert "tcpm: allow looking for role_sw device in the main node"
usb: gadget: f_ncm: Fix net_device lifecycle with device_move
Revert "usb: gadget: u_ether: add gether_opts for config caching"
Revert "usb: gadget: u_ether: use <linux/hex.h> header file"
Revert "usb: gadget: u_ether: Add auto-cleanup helper for freeing net_device"
Revert "usb: gadget: f_ncm: align net_device lifecycle with bind/unbind"
Revert "usb: legacy: ncm: Fix NPE in gncm_bind"
Revert "usb: gadget: f_ncm: Fix atomic context locking issue"
usb: typec: altmode/displayport: set displayport signaling rate in configure message
usb: dwc3: pci: add support for the Intel Nova Lake -H
usb/core/quirks: Add Huawei ME906S-device to wakeup quirk
usb: gadget: uvc: fix interval_duration calculation
xhci: Fix NULL pointer dereference when reading portli debugfs files
usb: xhci: Prevent interrupt storm on host controller error (HCE)
usb: xhci: Fix memory leak in xhci_disable_slot()
usb: class: cdc-wdm: fix reordering issue in read code path
usb: renesas_usbhs: fix use-after-free in ISR during device removal
usb: cdc-acm: Restore CAP_BRK functionnality to CH343
...

+329 -368
+3
Documentation/admin-guide/kernel-parameters.txt
··· 8196 8196 p = USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT 8197 8197 (Reduce timeout of the SET_ADDRESS 8198 8198 request from 5000 ms to 500 ms); 8199 + q = USB_QUIRK_FORCE_ONE_CONFIG (Device 8200 + claims zero configurations, 8201 + forcing to 1); 8199 8202 Example: quirks=0781:5580:bk,0a5c:5834:gij 8200 8203 8201 8204 usbhid.mousepoll=
+5
drivers/usb/class/cdc-acm.c
··· 1379 1379 acm->ctrl_caps = h.usb_cdc_acm_descriptor->bmCapabilities; 1380 1380 if (quirks & NO_CAP_LINE) 1381 1381 acm->ctrl_caps &= ~USB_CDC_CAP_LINE; 1382 + if (quirks & MISSING_CAP_BRK) 1383 + acm->ctrl_caps |= USB_CDC_CAP_BRK; 1382 1384 acm->ctrlsize = ctrlsize; 1383 1385 acm->readsize = readsize; 1384 1386 acm->rx_buflimit = num_rx_buf; ··· 2003 2001 { USB_DEVICE(0x32a7, 0x0000), 2004 2002 .driver_info = IGNORE_DEVICE, 2005 2003 }, 2004 + 2005 + /* CH343 supports CAP_BRK, but doesn't advertise it */ 2006 + { USB_DEVICE(0x1a86, 0x55d3), .driver_info = MISSING_CAP_BRK, }, 2006 2007 2007 2008 /* control interfaces without any protocol set */ 2008 2009 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
+1
drivers/usb/class/cdc-acm.h
··· 113 113 #define CLEAR_HALT_CONDITIONS BIT(5) 114 114 #define SEND_ZERO_PACKET BIT(6) 115 115 #define DISABLE_ECHO BIT(7) 116 + #define MISSING_CAP_BRK BIT(8)
+3 -1
drivers/usb/class/cdc-wdm.c
··· 225 225 /* we may already be in overflow */ 226 226 if (!test_bit(WDM_OVERFLOW, &desc->flags)) { 227 227 memmove(desc->ubuf + desc->length, desc->inbuf, length); 228 - desc->length += length; 228 + smp_wmb(); /* against wdm_read() */ 229 + WRITE_ONCE(desc->length, desc->length + length); 229 230 } 230 231 } 231 232 skip_error: ··· 534 533 return -ERESTARTSYS; 535 534 536 535 cntr = READ_ONCE(desc->length); 536 + smp_rmb(); /* against wdm_in_callback() */ 537 537 if (cntr == 0) { 538 538 desc->read = 0; 539 539 retry:
+3 -3
drivers/usb/class/usbtmc.c
··· 727 727 buffer[1] = data->bTag; 728 728 buffer[2] = ~data->bTag; 729 729 730 - retval = usb_bulk_msg(data->usb_dev, 730 + retval = usb_bulk_msg_killable(data->usb_dev, 731 731 usb_sndbulkpipe(data->usb_dev, 732 732 data->bulk_out), 733 733 buffer, USBTMC_HEADER_SIZE, ··· 1347 1347 buffer[11] = 0; /* Reserved */ 1348 1348 1349 1349 /* Send bulk URB */ 1350 - retval = usb_bulk_msg(data->usb_dev, 1350 + retval = usb_bulk_msg_killable(data->usb_dev, 1351 1351 usb_sndbulkpipe(data->usb_dev, 1352 1352 data->bulk_out), 1353 1353 buffer, USBTMC_HEADER_SIZE, ··· 1419 1419 actual = 0; 1420 1420 1421 1421 /* Send bulk URB */ 1422 - retval = usb_bulk_msg(data->usb_dev, 1422 + retval = usb_bulk_msg_killable(data->usb_dev, 1423 1423 usb_rcvbulkpipe(data->usb_dev, 1424 1424 data->bulk_in), 1425 1425 buffer, bufsize, &actual,
+5 -1
drivers/usb/core/config.c
··· 927 927 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG; 928 928 } 929 929 930 - if (ncfg < 1) { 930 + if (ncfg < 1 && dev->quirks & USB_QUIRK_FORCE_ONE_CONFIG) { 931 + dev_info(ddev, "Device claims zero configurations, forcing to 1\n"); 932 + dev->descriptor.bNumConfigurations = 1; 933 + ncfg = 1; 934 + } else if (ncfg < 1) { 931 935 dev_err(ddev, "no configurations\n"); 932 936 return -EINVAL; 933 937 }
+79 -21
drivers/usb/core/message.c
··· 42 42 43 43 44 44 /* 45 - * Starts urb and waits for completion or timeout. Note that this call 46 - * is NOT interruptible. Many device driver i/o requests should be 47 - * interruptible and therefore these drivers should implement their 48 - * own interruptible routines. 45 + * Starts urb and waits for completion or timeout. 46 + * Whether or not the wait is killable depends on the flag passed in. 47 + * For example, compare usb_bulk_msg() and usb_bulk_msg_killable(). 48 + * 49 + * For non-killable waits, we enforce a maximum limit on the timeout value. 49 50 */ 50 - static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) 51 + static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length, 52 + bool killable) 51 53 { 52 54 struct api_context ctx; 53 55 unsigned long expire; 54 56 int retval; 57 + long rc; 55 58 56 59 init_completion(&ctx.done); 57 60 urb->context = &ctx; ··· 63 60 if (unlikely(retval)) 64 61 goto out; 65 62 66 - expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; 67 - if (!wait_for_completion_timeout(&ctx.done, expire)) { 63 + if (!killable && (timeout <= 0 || timeout > USB_MAX_SYNCHRONOUS_TIMEOUT)) 64 + timeout = USB_MAX_SYNCHRONOUS_TIMEOUT; 65 + expire = (timeout > 0) ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; 66 + if (killable) 67 + rc = wait_for_completion_killable_timeout(&ctx.done, expire); 68 + else 69 + rc = wait_for_completion_timeout(&ctx.done, expire); 70 + if (rc <= 0) { 68 71 usb_kill_urb(urb); 69 - retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status); 72 + if (ctx.status != -ENOENT) 73 + retval = ctx.status; 74 + else if (rc == 0) 75 + retval = -ETIMEDOUT; 76 + else 77 + retval = rc; 70 78 71 79 dev_dbg(&urb->dev->dev, 72 - "%s timed out on ep%d%s len=%u/%u\n", 80 + "%s timed out or killed on ep%d%s len=%u/%u\n", 73 81 current->comm, 74 82 usb_endpoint_num(&urb->ep->desc), 75 83 usb_urb_dir_in(urb) ? "in" : "out", ··· 114 100 usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data, 115 101 len, usb_api_blocking_completion, NULL); 116 102 117 - retv = usb_start_wait_urb(urb, timeout, &length); 103 + retv = usb_start_wait_urb(urb, timeout, &length, false); 118 104 if (retv < 0) 119 105 return retv; 120 106 else ··· 131 117 * @index: USB message index value 132 118 * @data: pointer to the data to send 133 119 * @size: length in bytes of the data to send 134 - * @timeout: time in msecs to wait for the message to complete before timing 135 - * out (if 0 the wait is forever) 120 + * @timeout: time in msecs to wait for the message to complete before timing out 136 121 * 137 122 * Context: task context, might sleep. 138 123 * ··· 186 173 * @index: USB message index value 187 174 * @driver_data: pointer to the data to send 188 175 * @size: length in bytes of the data to send 189 - * @timeout: time in msecs to wait for the message to complete before timing 190 - * out (if 0 the wait is forever) 176 + * @timeout: time in msecs to wait for the message to complete before timing out 191 177 * @memflags: the flags for memory allocation for buffers 192 178 * 193 179 * Context: !in_interrupt () ··· 244 232 * @index: USB message index value 245 233 * @driver_data: pointer to the data to be filled in by the message 246 234 * @size: length in bytes of the data to be received 247 - * @timeout: time in msecs to wait for the message to complete before timing 248 - * out (if 0 the wait is forever) 235 + * @timeout: time in msecs to wait for the message to complete before timing out 249 236 * @memflags: the flags for memory allocation for buffers 250 237 * 251 238 * Context: !in_interrupt () ··· 315 304 * @len: length in bytes of the data to send 316 305 * @actual_length: pointer to a location to put the actual length transferred 317 306 * in bytes 318 - * @timeout: time in msecs to wait for the message to complete before 319 - * timing out (if 0 the wait is forever) 307 + * @timeout: time in msecs to wait for the message to complete before timing out 320 308 * 321 309 * Context: task context, might sleep. 322 310 * ··· 347 337 * @len: length in bytes of the data to send 348 338 * @actual_length: pointer to a location to put the actual length transferred 349 339 * in bytes 350 - * @timeout: time in msecs to wait for the message to complete before 351 - * timing out (if 0 the wait is forever) 340 + * @timeout: time in msecs to wait for the message to complete before timing out 352 341 * 353 342 * Context: task context, might sleep. 354 343 * ··· 394 385 usb_fill_bulk_urb(urb, usb_dev, pipe, data, len, 395 386 usb_api_blocking_completion, NULL); 396 387 397 - return usb_start_wait_urb(urb, timeout, actual_length); 388 + return usb_start_wait_urb(urb, timeout, actual_length, false); 398 389 } 399 390 EXPORT_SYMBOL_GPL(usb_bulk_msg); 391 + 392 + /** 393 + * usb_bulk_msg_killable - Builds a bulk urb, sends it off and waits for completion in a killable state 394 + * @usb_dev: pointer to the usb device to send the message to 395 + * @pipe: endpoint "pipe" to send the message to 396 + * @data: pointer to the data to send 397 + * @len: length in bytes of the data to send 398 + * @actual_length: pointer to a location to put the actual length transferred 399 + * in bytes 400 + * @timeout: time in msecs to wait for the message to complete before 401 + * timing out (if <= 0, the wait is as long as possible) 402 + * 403 + * Context: task context, might sleep. 404 + * 405 + * This function is just like usb_blk_msg(), except that it waits in a 406 + * killable state and there is no limit on the timeout length. 407 + * 408 + * Return: 409 + * If successful, 0. Otherwise a negative error number. The number of actual 410 + * bytes transferred will be stored in the @actual_length parameter. 411 + * 412 + */ 413 + int usb_bulk_msg_killable(struct usb_device *usb_dev, unsigned int pipe, 414 + void *data, int len, int *actual_length, int timeout) 415 + { 416 + struct urb *urb; 417 + struct usb_host_endpoint *ep; 418 + 419 + ep = usb_pipe_endpoint(usb_dev, pipe); 420 + if (!ep || len < 0) 421 + return -EINVAL; 422 + 423 + urb = usb_alloc_urb(0, GFP_KERNEL); 424 + if (!urb) 425 + return -ENOMEM; 426 + 427 + if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 428 + USB_ENDPOINT_XFER_INT) { 429 + pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30); 430 + usb_fill_int_urb(urb, usb_dev, pipe, data, len, 431 + usb_api_blocking_completion, NULL, 432 + ep->desc.bInterval); 433 + } else 434 + usb_fill_bulk_urb(urb, usb_dev, pipe, data, len, 435 + usb_api_blocking_completion, NULL); 436 + 437 + return usb_start_wait_urb(urb, timeout, actual_length, true); 438 + } 439 + EXPORT_SYMBOL_GPL(usb_bulk_msg_killable); 400 440 401 441 /*-------------------------------------------------------------------*/ 402 442
+1 -7
drivers/usb/core/phy.c
··· 200 200 list_for_each_entry(roothub_entry, head, list) { 201 201 err = phy_set_mode(roothub_entry->phy, mode); 202 202 if (err) 203 - goto err_out; 203 + return err; 204 204 } 205 205 206 206 return 0; 207 - 208 - err_out: 209 - list_for_each_entry_continue_reverse(roothub_entry, head, list) 210 - phy_power_off(roothub_entry->phy); 211 - 212 - return err; 213 207 } 214 208 EXPORT_SYMBOL_GPL(usb_phy_roothub_set_mode); 215 209
+21
drivers/usb/core/quirks.c
··· 140 140 case 'p': 141 141 flags |= USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT; 142 142 break; 143 + case 'q': 144 + flags |= USB_QUIRK_FORCE_ONE_CONFIG; 143 145 /* Ignore unrecognized flag characters */ 144 146 } 145 147 } ··· 208 206 209 207 /* HP v222w 16GB Mini USB Drive */ 210 208 { USB_DEVICE(0x03f0, 0x3f40), .driver_info = USB_QUIRK_DELAY_INIT }, 209 + 210 + /* Huawei 4G LTE module ME906S */ 211 + { USB_DEVICE(0x03f0, 0xa31d), .driver_info = 212 + USB_QUIRK_DISCONNECT_SUSPEND }, 211 213 212 214 /* Creative SB Audigy 2 NX */ 213 215 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME }, ··· 382 376 /* SanDisk Extreme 55AE */ 383 377 { USB_DEVICE(0x0781, 0x55ae), .driver_info = USB_QUIRK_NO_LPM }, 384 378 379 + /* Avermedia Live Gamer Ultra 2.1 (GC553G2) - BOS descriptor fetch hangs at SuperSpeed Plus */ 380 + { USB_DEVICE(0x07ca, 0x2553), .driver_info = USB_QUIRK_NO_BOS }, 381 + 385 382 /* Realforce 87U Keyboard */ 386 383 { USB_DEVICE(0x0853, 0x011b), .driver_info = USB_QUIRK_NO_LPM }, 387 384 ··· 444 435 /* ASUS Base Station(T100) */ 445 436 { USB_DEVICE(0x0b05, 0x17e0), .driver_info = 446 437 USB_QUIRK_IGNORE_REMOTE_WAKEUP }, 438 + 439 + /* ASUS TUF 4K PRO - BOS descriptor fetch hangs at SuperSpeed Plus */ 440 + { USB_DEVICE(0x0b05, 0x1ab9), .driver_info = USB_QUIRK_NO_BOS }, 447 441 448 442 /* Realtek Semiconductor Corp. Mass Storage Device (Multicard Reader)*/ 449 443 { USB_DEVICE(0x0bda, 0x0151), .driver_info = USB_QUIRK_CONFIG_INTF_STRINGS }, ··· 576 564 577 565 { USB_DEVICE(0x2386, 0x350e), .driver_info = USB_QUIRK_NO_LPM }, 578 566 567 + /* UGREEN 35871 - BOS descriptor fetch hangs at SuperSpeed Plus */ 568 + { USB_DEVICE(0x2b89, 0x5871), .driver_info = USB_QUIRK_NO_BOS }, 569 + 579 570 /* APTIV AUTOMOTIVE HUB */ 580 571 { USB_DEVICE(0x2c48, 0x0132), .driver_info = 581 572 USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT }, ··· 589 574 /* Alcor Link AK9563 SC Reader used in 2022 Lenovo ThinkPads */ 590 575 { USB_DEVICE(0x2ce3, 0x9563), .driver_info = USB_QUIRK_NO_LPM }, 591 576 577 + /* ezcap401 - BOS descriptor fetch hangs at SuperSpeed Plus */ 578 + { USB_DEVICE(0x32ed, 0x0401), .driver_info = USB_QUIRK_NO_BOS }, 579 + 592 580 /* DELL USB GEN2 */ 593 581 { USB_DEVICE(0x413c, 0xb062), .driver_info = USB_QUIRK_NO_LPM | USB_QUIRK_RESET_RESUME }, 594 582 595 583 /* VCOM device */ 596 584 { USB_DEVICE(0x4296, 0x7570), .driver_info = USB_QUIRK_CONFIG_INTF_STRINGS }, 585 + 586 + /* Noji-MCS SmartCard Reader */ 587 + { USB_DEVICE(0x5131, 0x2007), .driver_info = USB_QUIRK_FORCE_ONE_CONFIG }, 597 588 598 589 /* INTEL VALUE SSD */ 599 590 { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
+2
drivers/usb/dwc3/dwc3-pci.c
··· 56 56 #define PCI_DEVICE_ID_INTEL_CNPH 0xa36e 57 57 #define PCI_DEVICE_ID_INTEL_CNPV 0xa3b0 58 58 #define PCI_DEVICE_ID_INTEL_RPL 0xa70e 59 + #define PCI_DEVICE_ID_INTEL_NVLH 0xd37f 59 60 #define PCI_DEVICE_ID_INTEL_PTLH 0xe332 60 61 #define PCI_DEVICE_ID_INTEL_PTLH_PCH 0xe37e 61 62 #define PCI_DEVICE_ID_INTEL_PTLU 0xe432 ··· 448 447 { PCI_DEVICE_DATA(INTEL, CNPH, &dwc3_pci_intel_swnode) }, 449 448 { PCI_DEVICE_DATA(INTEL, CNPV, &dwc3_pci_intel_swnode) }, 450 449 { PCI_DEVICE_DATA(INTEL, RPL, &dwc3_pci_intel_swnode) }, 450 + { PCI_DEVICE_DATA(INTEL, NVLH, &dwc3_pci_intel_swnode) }, 451 451 { PCI_DEVICE_DATA(INTEL, PTLH, &dwc3_pci_intel_swnode) }, 452 452 { PCI_DEVICE_DATA(INTEL, PTLH_PCH, &dwc3_pci_intel_swnode) }, 453 453 { PCI_DEVICE_DATA(INTEL, PTLU, &dwc3_pci_intel_swnode) },
+4
drivers/usb/gadget/function/f_hid.c
··· 1207 1207 if (!hidg->interval_user_set) { 1208 1208 hidg_fs_in_ep_desc.bInterval = 10; 1209 1209 hidg_hs_in_ep_desc.bInterval = 4; 1210 + hidg_ss_in_ep_desc.bInterval = 4; 1210 1211 } else { 1211 1212 hidg_fs_in_ep_desc.bInterval = hidg->interval; 1212 1213 hidg_hs_in_ep_desc.bInterval = hidg->interval; 1214 + hidg_ss_in_ep_desc.bInterval = hidg->interval; 1213 1215 } 1214 1216 1215 1217 hidg_ss_out_comp_desc.wBytesPerInterval = ··· 1241 1239 if (!hidg->interval_user_set) { 1242 1240 hidg_fs_out_ep_desc.bInterval = 10; 1243 1241 hidg_hs_out_ep_desc.bInterval = 4; 1242 + hidg_ss_out_ep_desc.bInterval = 4; 1244 1243 } else { 1245 1244 hidg_fs_out_ep_desc.bInterval = hidg->interval; 1246 1245 hidg_hs_out_ep_desc.bInterval = hidg->interval; 1246 + hidg_ss_out_ep_desc.bInterval = hidg->interval; 1247 1247 } 1248 1248 status = usb_assign_descriptors(f, 1249 1249 hidg_fs_descriptors_intout,
+10 -2
drivers/usb/gadget/function/f_mass_storage.c
··· 180 180 #include <linux/kthread.h> 181 181 #include <linux/sched/signal.h> 182 182 #include <linux/limits.h> 183 + #include <linux/overflow.h> 183 184 #include <linux/pagemap.h> 184 185 #include <linux/rwsem.h> 185 186 #include <linux/slab.h> ··· 1854 1853 int cmnd_size, enum data_direction data_dir, 1855 1854 unsigned int mask, int needs_medium, const char *name) 1856 1855 { 1857 - if (common->curlun) 1858 - common->data_size_from_cmnd <<= common->curlun->blkbits; 1856 + if (common->curlun) { 1857 + if (check_shl_overflow(common->data_size_from_cmnd, 1858 + common->curlun->blkbits, 1859 + &common->data_size_from_cmnd)) { 1860 + common->phase_error = 1; 1861 + return -EINVAL; 1862 + } 1863 + } 1864 + 1859 1865 return check_command(common, cmnd_size, data_dir, 1860 1866 mask, needs_medium, name); 1861 1867 }
+79 -65
drivers/usb/gadget/function/f_ncm.c
··· 83 83 return container_of(f, struct f_ncm, port.func); 84 84 } 85 85 86 - static inline struct f_ncm_opts *func_to_ncm_opts(struct usb_function *f) 87 - { 88 - return container_of(f->fi, struct f_ncm_opts, func_inst); 89 - } 90 - 91 86 /*-------------------------------------------------------------------------*/ 92 87 93 88 /* ··· 859 864 static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 860 865 { 861 866 struct f_ncm *ncm = func_to_ncm(f); 862 - struct f_ncm_opts *opts = func_to_ncm_opts(f); 863 867 struct usb_composite_dev *cdev = f->config->cdev; 864 868 865 869 /* Control interface has only altsetting 0 */ ··· 881 887 if (alt > 1) 882 888 goto fail; 883 889 884 - scoped_guard(mutex, &opts->lock) 885 - if (opts->net) { 886 - DBG(cdev, "reset ncm\n"); 887 - opts->net = NULL; 888 - gether_disconnect(&ncm->port); 889 - ncm_reset_values(ncm); 890 - } 890 + if (ncm->netdev) { 891 + DBG(cdev, "reset ncm\n"); 892 + ncm->netdev = NULL; 893 + gether_disconnect(&ncm->port); 894 + ncm_reset_values(ncm); 895 + } 891 896 892 897 /* 893 898 * CDC Network only sends data in non-default altsettings. ··· 919 926 net = gether_connect(&ncm->port); 920 927 if (IS_ERR(net)) 921 928 return PTR_ERR(net); 922 - scoped_guard(mutex, &opts->lock) 923 - opts->net = net; 929 + ncm->netdev = net; 924 930 } 925 931 926 932 spin_lock(&ncm->lock); ··· 1366 1374 static void ncm_disable(struct usb_function *f) 1367 1375 { 1368 1376 struct f_ncm *ncm = func_to_ncm(f); 1369 - struct f_ncm_opts *opts = func_to_ncm_opts(f); 1370 1377 struct usb_composite_dev *cdev = f->config->cdev; 1371 1378 1372 1379 DBG(cdev, "ncm deactivated\n"); 1373 1380 1374 - scoped_guard(mutex, &opts->lock) 1375 - if (opts->net) { 1376 - opts->net = NULL; 1377 - gether_disconnect(&ncm->port); 1378 - } 1381 + if (ncm->netdev) { 1382 + ncm->netdev = NULL; 1383 + gether_disconnect(&ncm->port); 1384 + } 1379 1385 1380 1386 if (ncm->notify->enabled) { 1381 1387 usb_ep_disable(ncm->notify); ··· 1433 1443 { 1434 1444 struct usb_composite_dev *cdev = c->cdev; 1435 1445 struct f_ncm *ncm = func_to_ncm(f); 1436 - struct f_ncm_opts *ncm_opts = func_to_ncm_opts(f); 1437 1446 struct usb_string *us; 1438 1447 int status = 0; 1439 1448 struct usb_ep *ep; 1449 + struct f_ncm_opts *ncm_opts; 1440 1450 1441 1451 struct usb_os_desc_table *os_desc_table __free(kfree) = NULL; 1442 - struct net_device *netdev __free(free_gether_netdev) = NULL; 1452 + struct net_device *net __free(detach_gadget) = NULL; 1443 1453 struct usb_request *request __free(free_usb_request) = NULL; 1444 1454 1445 1455 if (!can_support_ecm(cdev->gadget)) 1446 1456 return -EINVAL; 1457 + 1458 + ncm_opts = container_of(f->fi, struct f_ncm_opts, func_inst); 1447 1459 1448 1460 if (cdev->use_os_string) { 1449 1461 os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL); ··· 1453 1461 return -ENOMEM; 1454 1462 } 1455 1463 1456 - netdev = gether_setup_default(); 1457 - if (IS_ERR(netdev)) 1458 - return -ENOMEM; 1464 + scoped_guard(mutex, &ncm_opts->lock) 1465 + if (ncm_opts->bind_count == 0) { 1466 + if (!device_is_registered(&ncm_opts->net->dev)) { 1467 + ncm_opts->net->mtu = (ncm_opts->max_segment_size - ETH_HLEN); 1468 + gether_set_gadget(ncm_opts->net, cdev->gadget); 1469 + status = gether_register_netdev(ncm_opts->net); 1470 + } else 1471 + status = gether_attach_gadget(ncm_opts->net, cdev->gadget); 1459 1472 1460 - scoped_guard(mutex, &ncm_opts->lock) { 1461 - gether_apply_opts(netdev, &ncm_opts->net_opts); 1462 - netdev->mtu = ncm_opts->max_segment_size - ETH_HLEN; 1463 - } 1473 + if (status) 1474 + return status; 1475 + net = ncm_opts->net; 1476 + } 1464 1477 1465 - gether_set_gadget(netdev, cdev->gadget); 1466 - status = gether_register_netdev(netdev); 1467 - if (status) 1468 - return status; 1469 - 1470 - /* export host's Ethernet address in CDC format */ 1471 - status = gether_get_host_addr_cdc(netdev, ncm->ethaddr, 1472 - sizeof(ncm->ethaddr)); 1473 - if (status < 12) 1474 - return -EINVAL; 1475 - ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; 1478 + ncm_string_defs[1].s = ncm->ethaddr; 1476 1479 1477 1480 us = usb_gstrings_attach(cdev, ncm_strings, 1478 1481 ARRAY_SIZE(ncm_string_defs)); ··· 1565 1578 f->os_desc_n = 1; 1566 1579 } 1567 1580 ncm->notify_req = no_free_ptr(request); 1568 - ncm->netdev = no_free_ptr(netdev); 1569 - ncm->port.ioport = netdev_priv(ncm->netdev); 1581 + 1582 + ncm_opts->bind_count++; 1583 + retain_and_null_ptr(net); 1570 1584 1571 1585 DBG(cdev, "CDC Network: IN/%s OUT/%s NOTIFY/%s\n", 1572 1586 ncm->port.in_ep->name, ncm->port.out_ep->name, ··· 1582 1594 } 1583 1595 1584 1596 /* f_ncm_item_ops */ 1585 - USB_ETHER_OPTS_ITEM(ncm); 1597 + USB_ETHERNET_CONFIGFS_ITEM(ncm); 1586 1598 1587 1599 /* f_ncm_opts_dev_addr */ 1588 - USB_ETHER_OPTS_ATTR_DEV_ADDR(ncm); 1600 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm); 1589 1601 1590 1602 /* f_ncm_opts_host_addr */ 1591 - USB_ETHER_OPTS_ATTR_HOST_ADDR(ncm); 1603 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm); 1592 1604 1593 1605 /* f_ncm_opts_qmult */ 1594 - USB_ETHER_OPTS_ATTR_QMULT(ncm); 1606 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm); 1595 1607 1596 1608 /* f_ncm_opts_ifname */ 1597 - USB_ETHER_OPTS_ATTR_IFNAME(ncm); 1609 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm); 1598 1610 1599 1611 static ssize_t ncm_opts_max_segment_size_show(struct config_item *item, 1600 1612 char *page) ··· 1660 1672 struct f_ncm_opts *opts; 1661 1673 1662 1674 opts = container_of(f, struct f_ncm_opts, func_inst); 1675 + if (device_is_registered(&opts->net->dev)) 1676 + gether_cleanup(netdev_priv(opts->net)); 1677 + else 1678 + free_netdev(opts->net); 1663 1679 kfree(opts->ncm_interf_group); 1664 1680 kfree(opts); 1665 1681 } 1666 1682 1667 1683 static struct usb_function_instance *ncm_alloc_inst(void) 1668 1684 { 1669 - struct usb_function_instance *ret; 1685 + struct f_ncm_opts *opts; 1670 1686 struct usb_os_desc *descs[1]; 1671 1687 char *names[1]; 1672 1688 struct config_group *ncm_interf_group; 1673 1689 1674 - struct f_ncm_opts *opts __free(kfree) = kzalloc_obj(*opts); 1690 + opts = kzalloc_obj(*opts); 1675 1691 if (!opts) 1676 1692 return ERR_PTR(-ENOMEM); 1677 - 1678 - opts->net = NULL; 1679 1693 opts->ncm_os_desc.ext_compat_id = opts->ncm_ext_compat_id; 1680 - gether_setup_opts_default(&opts->net_opts, "usb"); 1681 1694 1682 1695 mutex_init(&opts->lock); 1683 1696 opts->func_inst.free_func_inst = ncm_free_inst; 1697 + opts->net = gether_setup_default(); 1698 + if (IS_ERR(opts->net)) { 1699 + struct net_device *net = opts->net; 1700 + kfree(opts); 1701 + return ERR_CAST(net); 1702 + } 1684 1703 opts->max_segment_size = ETH_FRAME_LEN; 1685 1704 INIT_LIST_HEAD(&opts->ncm_os_desc.ext_prop); 1686 1705 ··· 1698 1703 ncm_interf_group = 1699 1704 usb_os_desc_prepare_interf_dir(&opts->func_inst.group, 1, descs, 1700 1705 names, THIS_MODULE); 1701 - if (IS_ERR(ncm_interf_group)) 1706 + if (IS_ERR(ncm_interf_group)) { 1707 + ncm_free_inst(&opts->func_inst); 1702 1708 return ERR_CAST(ncm_interf_group); 1709 + } 1703 1710 opts->ncm_interf_group = ncm_interf_group; 1704 1711 1705 - ret = &opts->func_inst; 1706 - retain_and_null_ptr(opts); 1707 - return ret; 1712 + return &opts->func_inst; 1708 1713 } 1709 1714 1710 1715 static void ncm_free(struct usb_function *f) 1711 1716 { 1712 - struct f_ncm_opts *opts = func_to_ncm_opts(f); 1717 + struct f_ncm *ncm; 1718 + struct f_ncm_opts *opts; 1713 1719 1714 - scoped_guard(mutex, &opts->lock) 1715 - opts->refcnt--; 1716 - kfree(func_to_ncm(f)); 1720 + ncm = func_to_ncm(f); 1721 + opts = container_of(f->fi, struct f_ncm_opts, func_inst); 1722 + kfree(ncm); 1723 + mutex_lock(&opts->lock); 1724 + opts->refcnt--; 1725 + mutex_unlock(&opts->lock); 1717 1726 } 1718 1727 1719 1728 static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) 1720 1729 { 1721 1730 struct f_ncm *ncm = func_to_ncm(f); 1731 + struct f_ncm_opts *ncm_opts; 1722 1732 1723 1733 DBG(c->cdev, "ncm unbind\n"); 1734 + 1735 + ncm_opts = container_of(f->fi, struct f_ncm_opts, func_inst); 1724 1736 1725 1737 hrtimer_cancel(&ncm->task_timer); 1726 1738 ··· 1745 1743 kfree(ncm->notify_req->buf); 1746 1744 usb_ep_free_request(ncm->notify, ncm->notify_req); 1747 1745 1748 - ncm->port.ioport = NULL; 1749 - gether_cleanup(netdev_priv(ncm->netdev)); 1746 + ncm_opts->bind_count--; 1747 + if (ncm_opts->bind_count == 0) 1748 + gether_detach_gadget(ncm_opts->net); 1750 1749 } 1751 1750 1752 1751 static struct usb_function *ncm_alloc(struct usb_function_instance *fi) 1753 1752 { 1754 1753 struct f_ncm *ncm; 1755 1754 struct f_ncm_opts *opts; 1755 + int status; 1756 1756 1757 1757 /* allocate and initialize one new instance */ 1758 1758 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); ··· 1762 1758 return ERR_PTR(-ENOMEM); 1763 1759 1764 1760 opts = container_of(fi, struct f_ncm_opts, func_inst); 1761 + mutex_lock(&opts->lock); 1762 + opts->refcnt++; 1765 1763 1766 - scoped_guard(mutex, &opts->lock) 1767 - opts->refcnt++; 1764 + /* export host's Ethernet address in CDC format */ 1765 + status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, 1766 + sizeof(ncm->ethaddr)); 1767 + if (status < 12) { /* strlen("01234567890a") */ 1768 + kfree(ncm); 1769 + mutex_unlock(&opts->lock); 1770 + return ERR_PTR(-EINVAL); 1771 + } 1768 1772 1769 1773 spin_lock_init(&ncm->lock); 1770 1774 ncm_reset_values(ncm); 1775 + ncm->port.ioport = netdev_priv(opts->net); 1776 + mutex_unlock(&opts->lock); 1771 1777 ncm->port.is_fixed = true; 1772 1778 ncm->port.supports_multi_frame = true; 1773 1779
+14
drivers/usb/gadget/function/f_tcm.c
··· 1222 1222 se_cmd = &cmd->se_cmd; 1223 1223 tpg = cmd->fu->tpg; 1224 1224 tv_nexus = tpg->tpg_nexus; 1225 + if (!tv_nexus) { 1226 + struct usb_gadget *gadget = fuas_to_gadget(cmd->fu); 1227 + 1228 + dev_err(&gadget->dev, "Missing nexus, ignoring command\n"); 1229 + return; 1230 + } 1231 + 1225 1232 dir = get_cmd_dir(cmd->cmd_buf); 1226 1233 if (dir < 0) 1227 1234 goto out; ··· 1490 1483 se_cmd = &cmd->se_cmd; 1491 1484 tpg = cmd->fu->tpg; 1492 1485 tv_nexus = tpg->tpg_nexus; 1486 + if (!tv_nexus) { 1487 + struct usb_gadget *gadget = fuas_to_gadget(cmd->fu); 1488 + 1489 + dev_err(&gadget->dev, "Missing nexus, ignoring command\n"); 1490 + return; 1491 + } 1492 + 1493 1493 dir = get_cmd_dir(cmd->cmd_buf); 1494 1494 if (dir < 0) 1495 1495 goto out;
+22 -45
drivers/usb/gadget/function/u_ether.c
··· 897 897 } 898 898 EXPORT_SYMBOL_GPL(gether_set_gadget); 899 899 900 + int gether_attach_gadget(struct net_device *net, struct usb_gadget *g) 901 + { 902 + int ret; 903 + 904 + ret = device_move(&net->dev, &g->dev, DPM_ORDER_DEV_AFTER_PARENT); 905 + if (ret) 906 + return ret; 907 + 908 + gether_set_gadget(net, g); 909 + return 0; 910 + } 911 + EXPORT_SYMBOL_GPL(gether_attach_gadget); 912 + 913 + void gether_detach_gadget(struct net_device *net) 914 + { 915 + struct eth_dev *dev = netdev_priv(net); 916 + 917 + device_move(&net->dev, NULL, DPM_ORDER_NONE); 918 + dev->gadget = NULL; 919 + } 920 + EXPORT_SYMBOL_GPL(gether_detach_gadget); 921 + 900 922 int gether_set_dev_addr(struct net_device *net, const char *dev_addr) 901 923 { 902 924 struct eth_dev *dev; ··· 1062 1040 } 1063 1041 EXPORT_SYMBOL_GPL(gether_set_ifname); 1064 1042 1065 - void gether_setup_opts_default(struct gether_opts *opts, const char *name) 1066 - { 1067 - opts->qmult = QMULT_DEFAULT; 1068 - snprintf(opts->name, sizeof(opts->name), "%s%%d", name); 1069 - eth_random_addr(opts->dev_mac); 1070 - opts->addr_assign_type = NET_ADDR_RANDOM; 1071 - eth_random_addr(opts->host_mac); 1072 - } 1073 - EXPORT_SYMBOL_GPL(gether_setup_opts_default); 1074 - 1075 - void gether_apply_opts(struct net_device *net, struct gether_opts *opts) 1076 - { 1077 - struct eth_dev *dev = netdev_priv(net); 1078 - 1079 - dev->qmult = opts->qmult; 1080 - 1081 - if (opts->ifname_set) { 1082 - strscpy(net->name, opts->name, sizeof(net->name)); 1083 - dev->ifname_set = true; 1084 - } 1085 - 1086 - memcpy(dev->host_mac, opts->host_mac, sizeof(dev->host_mac)); 1087 - 1088 - if (opts->addr_assign_type == NET_ADDR_SET) { 1089 - memcpy(dev->dev_mac, opts->dev_mac, sizeof(dev->dev_mac)); 1090 - net->addr_assign_type = opts->addr_assign_type; 1091 - } 1092 - } 1093 - EXPORT_SYMBOL_GPL(gether_apply_opts); 1094 - 1095 1043 void gether_suspend(struct gether *link) 1096 1044 { 1097 1045 struct eth_dev *dev = link->ioport; ··· 1117 1125 free_netdev(dev->net); 1118 1126 } 1119 1127 EXPORT_SYMBOL_GPL(gether_cleanup); 1120 - 1121 - void gether_unregister_free_netdev(struct net_device *net) 1122 - { 1123 - if (!net) 1124 - return; 1125 - 1126 - struct eth_dev *dev = netdev_priv(net); 1127 - 1128 - if (net->reg_state == NETREG_REGISTERED) { 1129 - unregister_netdev(net); 1130 - flush_work(&dev->work); 1131 - } 1132 - free_netdev(net); 1133 - } 1134 - EXPORT_SYMBOL_GPL(gether_unregister_free_netdev); 1135 1128 1136 1129 /** 1137 1130 * gether_connect - notify network layer that USB link is active
+26 -30
drivers/usb/gadget/function/u_ether.h
··· 38 38 39 39 struct eth_dev; 40 40 41 - /** 42 - * struct gether_opts - Options for Ethernet gadget function instances 43 - * @name: Pattern for the network interface name (e.g., "usb%d"). 44 - * Used to generate the net device name. 45 - * @qmult: Queue length multiplier for high/super speed. 46 - * @host_mac: The MAC address to be used by the host side. 47 - * @dev_mac: The MAC address to be used by the device side. 48 - * @ifname_set: True if the interface name pattern has been set by userspace. 49 - * @addr_assign_type: The method used for assigning the device MAC address 50 - * (e.g., NET_ADDR_RANDOM, NET_ADDR_SET). 51 - * 52 - * This structure caches network-related settings provided through configfs 53 - * before the net_device is fully instantiated. This allows for early 54 - * configuration while deferring net_device allocation until the function 55 - * is bound. 56 - */ 57 - struct gether_opts { 58 - char name[IFNAMSIZ]; 59 - unsigned int qmult; 60 - u8 host_mac[ETH_ALEN]; 61 - u8 dev_mac[ETH_ALEN]; 62 - bool ifname_set; 63 - unsigned char addr_assign_type; 64 - }; 65 - 66 41 /* 67 42 * This represents the USB side of an "ethernet" link, managed by a USB 68 43 * function which provides control and (maybe) framing. Two functions ··· 151 176 void gether_set_gadget(struct net_device *net, struct usb_gadget *g); 152 177 153 178 /** 179 + * gether_attach_gadget - Reparent net_device to the gadget device. 180 + * @net: The network device to reparent. 181 + * @g: The target USB gadget device to parent to. 182 + * 183 + * This function moves the network device to be a child of the USB gadget 184 + * device in the device hierarchy. This is typically done when the function 185 + * is bound to a configuration. 186 + * 187 + * Returns 0 on success, or a negative error code on failure. 188 + */ 189 + int gether_attach_gadget(struct net_device *net, struct usb_gadget *g); 190 + 191 + /** 192 + * gether_detach_gadget - Detach net_device from its gadget parent. 193 + * @net: The network device to detach. 194 + * 195 + * This function moves the network device to be a child of the virtual 196 + * devices parent, effectively detaching it from the USB gadget device 197 + * hierarchy. This is typically done when the function is unbound 198 + * from a configuration but the instance is not yet freed. 199 + */ 200 + void gether_detach_gadget(struct net_device *net); 201 + 202 + DEFINE_FREE(detach_gadget, struct net_device *, if (_T) gether_detach_gadget(_T)) 203 + 204 + /** 154 205 * gether_set_dev_addr - initialize an ethernet-over-usb link with eth address 155 206 * @net: device representing this link 156 207 * @dev_addr: eth address of this device ··· 284 283 int gether_set_ifname(struct net_device *net, const char *name, int len); 285 284 286 285 void gether_cleanup(struct eth_dev *dev); 287 - void gether_unregister_free_netdev(struct net_device *net); 288 - DEFINE_FREE(free_gether_netdev, struct net_device *, gether_unregister_free_netdev(_T)); 289 - 290 - void gether_setup_opts_default(struct gether_opts *opts, const char *name); 291 - void gether_apply_opts(struct net_device *net, struct gether_opts *opts); 292 286 293 287 void gether_suspend(struct gether *link); 294 288 void gether_resume(struct gether *link);
-177
drivers/usb/gadget/function/u_ether_configfs.h
··· 13 13 #ifndef __U_ETHER_CONFIGFS_H 14 14 #define __U_ETHER_CONFIGFS_H 15 15 16 - #include <linux/cleanup.h> 17 - #include <linux/hex.h> 18 - #include <linux/if_ether.h> 19 - #include <linux/mutex.h> 20 - #include <linux/netdevice.h> 21 - #include <linux/rtnetlink.h> 22 - 23 16 #define USB_ETHERNET_CONFIGFS_ITEM(_f_) \ 24 17 static void _f_##_attr_release(struct config_item *item) \ 25 18 { \ ··· 196 203 } \ 197 204 \ 198 205 CONFIGFS_ATTR(_f_##_opts_, _n_) 199 - 200 - #define USB_ETHER_OPTS_ITEM(_f_) \ 201 - static void _f_##_attr_release(struct config_item *item) \ 202 - { \ 203 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 204 - \ 205 - usb_put_function_instance(&opts->func_inst); \ 206 - } \ 207 - \ 208 - static struct configfs_item_operations _f_##_item_ops = { \ 209 - .release = _f_##_attr_release, \ 210 - } 211 - 212 - #define USB_ETHER_OPTS_ATTR_DEV_ADDR(_f_) \ 213 - static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \ 214 - char *page) \ 215 - { \ 216 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 217 - \ 218 - guard(mutex)(&opts->lock); \ 219 - return sysfs_emit(page, "%pM\n", opts->net_opts.dev_mac); \ 220 - } \ 221 - \ 222 - static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \ 223 - const char *page, size_t len) \ 224 - { \ 225 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 226 - u8 new_addr[ETH_ALEN]; \ 227 - const char *p = page; \ 228 - \ 229 - guard(mutex)(&opts->lock); \ 230 - if (opts->refcnt) \ 231 - return -EBUSY; \ 232 - \ 233 - for (int i = 0; i < ETH_ALEN; i++) { \ 234 - unsigned char num; \ 235 - if ((*p == '.') || (*p == ':')) \ 236 - p++; \ 237 - num = hex_to_bin(*p++) << 4; \ 238 - num |= hex_to_bin(*p++); \ 239 - new_addr[i] = num; \ 240 - } \ 241 - if (!is_valid_ether_addr(new_addr)) \ 242 - return -EINVAL; \ 243 - memcpy(opts->net_opts.dev_mac, new_addr, ETH_ALEN); \ 244 - opts->net_opts.addr_assign_type = NET_ADDR_SET; \ 245 - return len; \ 246 - } \ 247 - \ 248 - CONFIGFS_ATTR(_f_##_opts_, dev_addr) 249 - 250 - #define USB_ETHER_OPTS_ATTR_HOST_ADDR(_f_) \ 251 - static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \ 252 - char *page) \ 253 - { \ 254 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 255 - \ 256 - guard(mutex)(&opts->lock); \ 257 - return sysfs_emit(page, "%pM\n", opts->net_opts.host_mac); \ 258 - } \ 259 - \ 260 - static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \ 261 - const char *page, size_t len) \ 262 - { \ 263 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 264 - u8 new_addr[ETH_ALEN]; \ 265 - const char *p = page; \ 266 - \ 267 - guard(mutex)(&opts->lock); \ 268 - if (opts->refcnt) \ 269 - return -EBUSY; \ 270 - \ 271 - for (int i = 0; i < ETH_ALEN; i++) { \ 272 - unsigned char num; \ 273 - if ((*p == '.') || (*p == ':')) \ 274 - p++; \ 275 - num = hex_to_bin(*p++) << 4; \ 276 - num |= hex_to_bin(*p++); \ 277 - new_addr[i] = num; \ 278 - } \ 279 - if (!is_valid_ether_addr(new_addr)) \ 280 - return -EINVAL; \ 281 - memcpy(opts->net_opts.host_mac, new_addr, ETH_ALEN); \ 282 - return len; \ 283 - } \ 284 - \ 285 - CONFIGFS_ATTR(_f_##_opts_, host_addr) 286 - 287 - #define USB_ETHER_OPTS_ATTR_QMULT(_f_) \ 288 - static ssize_t _f_##_opts_qmult_show(struct config_item *item, \ 289 - char *page) \ 290 - { \ 291 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 292 - \ 293 - guard(mutex)(&opts->lock); \ 294 - return sysfs_emit(page, "%u\n", opts->net_opts.qmult); \ 295 - } \ 296 - \ 297 - static ssize_t _f_##_opts_qmult_store(struct config_item *item, \ 298 - const char *page, size_t len) \ 299 - { \ 300 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 301 - u32 val; \ 302 - int ret; \ 303 - \ 304 - guard(mutex)(&opts->lock); \ 305 - if (opts->refcnt) \ 306 - return -EBUSY; \ 307 - \ 308 - ret = kstrtou32(page, 0, &val); \ 309 - if (ret) \ 310 - return ret; \ 311 - \ 312 - opts->net_opts.qmult = val; \ 313 - return len; \ 314 - } \ 315 - \ 316 - CONFIGFS_ATTR(_f_##_opts_, qmult) 317 - 318 - #define USB_ETHER_OPTS_ATTR_IFNAME(_f_) \ 319 - static ssize_t _f_##_opts_ifname_show(struct config_item *item, \ 320 - char *page) \ 321 - { \ 322 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 323 - const char *name; \ 324 - \ 325 - guard(mutex)(&opts->lock); \ 326 - rtnl_lock(); \ 327 - if (opts->net_opts.ifname_set) \ 328 - name = opts->net_opts.name; \ 329 - else if (opts->net) \ 330 - name = netdev_name(opts->net); \ 331 - else \ 332 - name = "(inactive net_device)"; \ 333 - rtnl_unlock(); \ 334 - return sysfs_emit(page, "%s\n", name); \ 335 - } \ 336 - \ 337 - static ssize_t _f_##_opts_ifname_store(struct config_item *item, \ 338 - const char *page, size_t len) \ 339 - { \ 340 - struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 341 - char tmp[IFNAMSIZ]; \ 342 - const char *p; \ 343 - size_t c_len = len; \ 344 - \ 345 - if (c_len > 0 && page[c_len - 1] == '\n') \ 346 - c_len--; \ 347 - \ 348 - if (c_len >= sizeof(tmp)) \ 349 - return -E2BIG; \ 350 - \ 351 - strscpy(tmp, page, c_len + 1); \ 352 - if (!dev_valid_name(tmp)) \ 353 - return -EINVAL; \ 354 - \ 355 - /* Require exactly one %d */ \ 356 - p = strchr(tmp, '%'); \ 357 - if (!p || p[1] != 'd' || strchr(p + 2, '%')) \ 358 - return -EINVAL; \ 359 - \ 360 - guard(mutex)(&opts->lock); \ 361 - if (opts->refcnt) \ 362 - return -EBUSY; \ 363 - strscpy(opts->net_opts.name, tmp, sizeof(opts->net_opts.name)); \ 364 - opts->net_opts.ifname_set = true; \ 365 - return len; \ 366 - } \ 367 - \ 368 - CONFIGFS_ATTR(_f_##_opts_, ifname) 369 206 370 207 #endif /* __U_ETHER_CONFIGFS_H */
+1 -3
drivers/usb/gadget/function/u_ncm.h
··· 15 15 16 16 #include <linux/usb/composite.h> 17 17 18 - #include "u_ether.h" 19 - 20 18 struct f_ncm_opts { 21 19 struct usb_function_instance func_inst; 22 20 struct net_device *net; 21 + int bind_count; 23 22 24 - struct gether_opts net_opts; 25 23 struct config_group *ncm_interf_group; 26 24 struct usb_os_desc ncm_os_desc; 27 25 char ncm_ext_compat_id[16];
+1 -1
drivers/usb/gadget/function/uvc_video.c
··· 513 513 return; 514 514 } 515 515 516 - interval_duration = 2 << (video->ep->desc->bInterval - 1); 516 + interval_duration = 1 << (video->ep->desc->bInterval - 1); 517 517 if (cdev->gadget->speed < USB_SPEED_HIGH) 518 518 interval_duration *= 10000; 519 519 else
+9 -1
drivers/usb/host/xhci-debugfs.c
··· 386 386 static int xhci_portli_show(struct seq_file *s, void *unused) 387 387 { 388 388 struct xhci_port *port = s->private; 389 - struct xhci_hcd *xhci = hcd_to_xhci(port->rhub->hcd); 389 + struct xhci_hcd *xhci; 390 390 u32 portli; 391 391 392 392 portli = readl(&port->port_reg->portli); 393 + 394 + /* port without protocol capability isn't added to a roothub */ 395 + if (!port->rhub) { 396 + seq_printf(s, "0x%08x\n", portli); 397 + return 0; 398 + } 399 + 400 + xhci = hcd_to_xhci(port->rhub->hcd); 393 401 394 402 /* PORTLI fields are valid if port is a USB3 or eUSB2V2 port */ 395 403 if (port->rhub == &xhci->usb3_rhub)
+1
drivers/usb/host/xhci-ring.c
··· 3195 3195 3196 3196 if (status & STS_HCE) { 3197 3197 xhci_warn(xhci, "WARNING: Host Controller Error\n"); 3198 + xhci_halt(xhci); 3198 3199 goto out; 3199 3200 } 3200 3201
+2 -2
drivers/usb/host/xhci.c
··· 4146 4146 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || 4147 4147 (xhci->xhc_state & XHCI_STATE_HALTED)) { 4148 4148 spin_unlock_irqrestore(&xhci->lock, flags); 4149 - kfree(command); 4149 + xhci_free_command(xhci, command); 4150 4150 return -ENODEV; 4151 4151 } 4152 4152 ··· 4154 4154 slot_id); 4155 4155 if (ret) { 4156 4156 spin_unlock_irqrestore(&xhci->lock, flags); 4157 - kfree(command); 4157 + xhci_free_command(xhci, command); 4158 4158 return ret; 4159 4159 } 4160 4160 xhci_ring_cmd_db(xhci);
+4 -2
drivers/usb/image/mdc800.c
··· 707 707 if (signal_pending (current)) 708 708 { 709 709 mutex_unlock(&mdc800->io_lock); 710 - return -EINTR; 710 + return len == left ? -EINTR : len-left; 711 711 } 712 712 713 713 sts=left > (mdc800->out_count-mdc800->out_ptr)?mdc800->out_count-mdc800->out_ptr:left; ··· 730 730 mutex_unlock(&mdc800->io_lock); 731 731 return len-left; 732 732 } 733 - wait_event_timeout(mdc800->download_wait, 733 + retval = wait_event_timeout(mdc800->download_wait, 734 734 mdc800->downloaded, 735 735 msecs_to_jiffies(TO_DOWNLOAD_GET_READY)); 736 + if (!retval) 737 + usb_kill_urb(mdc800->download_urb); 736 738 mdc800->downloaded = 0; 737 739 if (mdc800->download_urb->status != 0) 738 740 {
+1 -1
drivers/usb/misc/uss720.c
··· 736 736 ret = get_1284_register(pp, 0, &reg, GFP_KERNEL); 737 737 dev_dbg(&intf->dev, "reg: %7ph\n", priv->reg); 738 738 if (ret < 0) 739 - return ret; 739 + goto probe_abort; 740 740 741 741 ret = usb_find_last_int_in_endpoint(interface, &epd); 742 742 if (!ret) {
+1 -1
drivers/usb/misc/yurex.c
··· 272 272 dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt, 273 273 dev, 1); 274 274 dev->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 275 + dev->bbu = -1; 275 276 if (usb_submit_urb(dev->urb, GFP_KERNEL)) { 276 277 retval = -EIO; 277 278 dev_err(&interface->dev, "Could not submitting URB\n"); ··· 281 280 282 281 /* save our data pointer in this interface device */ 283 282 usb_set_intfdata(interface, dev); 284 - dev->bbu = -1; 285 283 286 284 /* we can register the device now, as it is ready */ 287 285 retval = usb_register_dev(interface, &yurex_class);
+9
drivers/usb/renesas_usbhs/common.c
··· 815 815 816 816 usbhs_platform_call(priv, hardware_exit, pdev); 817 817 reset_control_assert(priv->rsts); 818 + 819 + /* 820 + * Explicitly free the IRQ to ensure the interrupt handler is 821 + * disabled and synchronized before freeing resources. 822 + * devm_free_irq() calls free_irq() which waits for any running 823 + * ISR to complete, preventing UAF. 824 + */ 825 + devm_free_irq(&pdev->dev, priv->irq, priv); 826 + 818 827 usbhs_mod_remove(priv); 819 828 usbhs_fifo_remove(priv); 820 829 usbhs_pipe_remove(priv);
+6 -1
drivers/usb/roles/class.c
··· 139 139 static struct usb_role_switch * 140 140 usb_role_switch_is_parent(struct fwnode_handle *fwnode) 141 141 { 142 - struct fwnode_handle *parent = fwnode_get_parent(fwnode); 142 + struct fwnode_handle *parent; 143 143 struct device *dev; 144 + 145 + if (!fwnode_device_is_compatible(fwnode, "usb-b-connector")) 146 + return NULL; 147 + 148 + parent = fwnode_get_parent(fwnode); 144 149 145 150 if (!fwnode_property_present(parent, "usb-role-switch")) { 146 151 fwnode_handle_put(parent);
+6 -1
drivers/usb/typec/altmodes/displayport.c
··· 100 100 { 101 101 u8 pin_assign = 0; 102 102 u32 conf; 103 + u32 signal; 103 104 104 105 /* DP Signalling */ 105 - conf = (dp->data.conf & DP_CONF_SIGNALLING_MASK) >> DP_CONF_SIGNALLING_SHIFT; 106 + signal = DP_CAP_DP_SIGNALLING(dp->port->vdo) & DP_CAP_DP_SIGNALLING(dp->alt->vdo); 107 + if (dp->plug_prime) 108 + signal &= DP_CAP_DP_SIGNALLING(dp->plug_prime->vdo); 109 + 110 + conf = signal << DP_CONF_SIGNALLING_SHIFT; 106 111 107 112 switch (con) { 108 113 case DP_STATUS_CON_DISABLED:
+1 -1
drivers/usb/typec/tcpm/tcpm.c
··· 7890 7890 port->partner_desc.identity = &port->partner_ident; 7891 7891 7892 7892 port->role_sw = fwnode_usb_role_switch_get(tcpc->fwnode); 7893 - if (IS_ERR_OR_NULL(port->role_sw)) 7893 + if (!port->role_sw) 7894 7894 port->role_sw = usb_role_switch_get(port->dev); 7895 7895 if (IS_ERR(port->role_sw)) { 7896 7896 err = PTR_ERR(port->role_sw);
+6 -2
include/linux/usb.h
··· 1862 1862 * SYNCHRONOUS CALL SUPPORT * 1863 1863 *-------------------------------------------------------------------*/ 1864 1864 1865 + /* Maximum value allowed for timeout in synchronous routines below */ 1866 + #define USB_MAX_SYNCHRONOUS_TIMEOUT 60000 /* ms */ 1867 + 1865 1868 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe, 1866 1869 __u8 request, __u8 requesttype, __u16 value, __u16 index, 1867 1870 void *data, __u16 size, int timeout); 1868 1871 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe, 1869 1872 void *data, int len, int *actual_length, int timeout); 1870 1873 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 1871 - void *data, int len, int *actual_length, 1872 - int timeout); 1874 + void *data, int len, int *actual_length, int timeout); 1875 + extern int usb_bulk_msg_killable(struct usb_device *usb_dev, unsigned int pipe, 1876 + void *data, int len, int *actual_length, int timeout); 1873 1877 1874 1878 /* wrappers around usb_control_msg() for the most common standard requests */ 1875 1879 int usb_control_msg_send(struct usb_device *dev, __u8 endpoint, __u8 request,
+3
include/linux/usb/quirks.h
··· 78 78 /* skip BOS descriptor request */ 79 79 #define USB_QUIRK_NO_BOS BIT(17) 80 80 81 + /* Device claims zero configurations, forcing to 1 */ 82 + #define USB_QUIRK_FORCE_ONE_CONFIG BIT(18) 83 + 81 84 #endif /* __LINUX_USB_QUIRKS_H */