History

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

Pull USB fixes from Greg KH: "Let's try this again... Here are some USB fixes for 5.9-rc3. This differs from the previous pull request for this release in that the usb gadget patch now does not break some systems, and actually does what it was intended to do. Many thanks to Marek Szyprowski for quickly noticing and testing the patch from Andy Shevchenko to resolve this issue. Additionally, some more new USB quirks have been added to get some new devices to work properly based on user reports. Other than that, the patches are all here, and they contain: - usb gadget driver fixes - xhci driver fixes - typec fixes - new quirks and ids - fixes for USB patches that went into 5.9-rc1. All of these have been tested in linux-next with no reported issues" * tag 'usb-5.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (33 commits) usb: storage: Add unusual_uas entry for Sony PSZ drives USB: Ignore UAS for JMicron JMS567 ATA/ATAPI Bridge usb: host: ohci-exynos: Fix error handling in exynos_ohci_probe() USB: gadget: u_f: Unbreak offset calculation in VLAs USB: quirks: Ignore duplicate endpoint on Sound Devices MixPre-D usb: typec: tcpm: Fix Fix source hard reset response for TDA 2.3.1.1 and TDA 2.3.1.2 failures USB: PHY: JZ4770: Fix static checker warning. USB: gadget: f_ncm: add bounds checks to ncm_unwrap_ntb() USB: gadget: u_f: add overflow checks to VLA macros xhci: Always restore EP_SOFT_CLEAR_TOGGLE even if ep reset failed xhci: Do warm-reset when both CAS and XDEV_RESUME are set usb: host: xhci: fix ep context print mismatch in debugfs usb: uas: Add quirk for PNY Pro Elite tools: usb: move to tools buildsystem USB: Fix device driver race USB: Also match device drivers using the ->match vfunc usb: host: xhci-tegra: fix tegra_xusb_get_phy() usb: host: xhci-tegra: otg usb2/usb3 port init usb: hcd: Fix use after free in usb_hcd_pci_remove() usb: typec: ucsi: Hold con->lock for the entire duration of ucsi_register_port() ...

Linus Torvalds committed 6 years ago

Commit 6f0306d2 parents 42df60f 20934c026 files · +423 −169Browse files

Unified · Split

26 files
  1. drivers/usb/class/cdc-acm.c +10 −12
  2. drivers/usb/core/driver.c +38 −2
  3. drivers/usb/core/generic.c +3 −2
  4. drivers/usb/core/hcd-pci.c +4 −1
  5. drivers/usb/core/quirks.c +7 −0
  6. drivers/usb/dwc3/gadget.c +89 −18
  7. drivers/usb/gadget/function/f_ncm.c +69 −12
  8. drivers/usb/gadget/function/f_tcm.c +4 −3
  9. drivers/usb/gadget/u_f.h +27 −11
  10. drivers/usb/host/ohci-exynos.c +2 −3
  11. drivers/usb/host/xhci-debugfs.c +4 −4
  12. drivers/usb/host/xhci-hub.c +10 −9
  13. drivers/usb/host/xhci-pci-renesas.c +1 −18
  14. drivers/usb/host/xhci-tegra.c +3 −1
  15. drivers/usb/host/xhci.c +2 −1
  16. drivers/usb/misc/lvstest.c +1 −1
  17. drivers/usb/misc/yurex.c +1 −1
  18. drivers/usb/phy/phy-jz4770.c +1 −0
  19. drivers/usb/storage/unusual_devs.h +1 −1
  20. drivers/usb/storage/unusual_uas.h +14 −0
  21. drivers/usb/typec/tcpm/tcpm.c +25 −3
  22. drivers/usb/typec/ucsi/displayport.c +1 −8
  23. drivers/usb/typec/ucsi/ucsi.c +53 −50
  24. drivers/usb/usbip/stub_dev.c +6 −0
  25. tools/usb/Build +2 −0
  26. tools/usb/Makefile +45 −8
drivers/usb/class/cdc-acm.c+10−12
@@ -378,21 +378,19 @@ static void acm_ctrl_irq(struct urb *urb) · 377 unmodified lines
378378 if (current_size < expected_size) {
379379 /* notification is transmitted fragmented, reassemble */
380380 if (acm->nb_size < expected_size) {
381− if (acm->nb_size) {
382− kfree(acm->notification_buffer);
383− acm->nb_size = 0;
384− }
381+ u8 *new_buffer;
385382 alloc_size = roundup_pow_of_two(expected_size);
386− /*
387− * kmalloc ensures a valid notification_buffer after a
388− * use of kfree in case the previous allocation was too
389− * small. Final freeing is done on disconnect.
390− */
391− acm->notification_buffer =
392− kmalloc(alloc_size, GFP_ATOMIC);
393− if (!acm->notification_buffer)
383+ /* Final freeing is done on disconnect. */
384+ new_buffer = krealloc(acm->notification_buffer,
385+ alloc_size, GFP_ATOMIC);
386+ if (!new_buffer) {
387+ acm->nb_index = 0;
394388 goto exit;
389+ }
390+
391+ acm->notification_buffer = new_buffer;
395392 acm->nb_size = alloc_size;
393+ dr = (struct usb_cdc_notification *)acm->notification_buffer;
396394 }
397395
398396 copy_size = min(current_size,
drivers/usb/core/driver.c+38−2
@@ -905,6 +905,35 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) · 904 unmodified lines
905905 return 0;
906906 }
907907
908+static bool is_dev_usb_generic_driver(struct device *dev)
909+{
910+ struct usb_device_driver *udd = dev->driver ?
911+ to_usb_device_driver(dev->driver) : NULL;
912+
913+ return udd == &usb_generic_driver;
914+}
915+
916+static int __usb_bus_reprobe_drivers(struct device *dev, void *data)
917+{
918+ struct usb_device_driver *new_udriver = data;
919+ struct usb_device *udev;
920+ int ret;
921+
922+ if (!is_dev_usb_generic_driver(dev))
923+ return 0;
924+
925+ udev = to_usb_device(dev);
926+ if (usb_device_match_id(udev, new_udriver->id_table) == NULL &&
927+ (!new_udriver->match || new_udriver->match(udev) != 0))
928+ return 0;
929+
930+ ret = device_reprobe(dev);
931+ if (ret && ret != -EPROBE_DEFER)
932+ dev_err(dev, "Failed to reprobe device (error %d)\n", ret);
933+
934+ return 0;
935+}
936+
908937 /**
909938 * usb_register_device_driver - register a USB device (not interface) driver
910939 * @new_udriver: USB operations for the device driver
@@ -934,13 +963,20 @@ int usb_register_device_driver(struct usb_device_driver *new_udriver, · 23 unmodified lines
934963
935964 retval = driver_register(&new_udriver->drvwrap.driver);
936965
937− if (!retval)
966+ if (!retval) {
938967 pr_info("%s: registered new device driver %s\n",
939968 usbcore_name, new_udriver->name);
940− else
969+ /*
970+ * Check whether any device could be better served with
971+ * this new driver
972+ */
973+ bus_for_each_dev(&usb_bus_type, NULL, new_udriver,
974+ __usb_bus_reprobe_drivers);
975+ } else {
941976 printk(KERN_ERR "%s: error %d registering device "
942977 " driver %s\n",
943978 usbcore_name, retval, new_udriver->name);
979+ }
944980
945981 return retval;
946982 }
drivers/usb/core/generic.c+3−2
@@ -205,8 +205,9 @@ static int __check_usb_generic(struct device_driver *drv, void *data) · 204 unmodified lines
205205 udrv = to_usb_device_driver(drv);
206206 if (udrv == &usb_generic_driver)
207207 return 0;
208−
209− return usb_device_match_id(udev, udrv->id_table) != NULL;
208+ if (usb_device_match_id(udev, udrv->id_table) != NULL)
209+ return 1;
210+ return (udrv->match && udrv->match(udev));
210211 }
211212
212213 static bool usb_generic_driver_match(struct usb_device *udev)
drivers/usb/core/hcd-pci.c+4−1
@@ -315,11 +315,14 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); · 314 unmodified lines
315315 void usb_hcd_pci_remove(struct pci_dev *dev)
316316 {
317317 struct usb_hcd *hcd;
318+ int hcd_driver_flags;
318319
319320 hcd = pci_get_drvdata(dev);
320321 if (!hcd)
321322 return;
322323
324+ hcd_driver_flags = hcd->driver->flags;
325+
323326 if (pci_dev_run_wake(dev))
324327 pm_runtime_get_noresume(&dev->dev);
325328
@@ -347,7 +350,7 @@ void usb_hcd_pci_remove(struct pci_dev *dev) · 21 unmodified lines
347350 up_read(&companions_rwsem);
348351 }
349352 usb_put_hcd(hcd);
350− if ((hcd->driver->flags & HCD_MASK) < HCD_USB3)
353+ if ((hcd_driver_flags & HCD_MASK) < HCD_USB3)
351354 pci_free_irq_vectors(dev);
352355 pci_disable_device(dev);
353356 }
drivers/usb/core/quirks.c+7−0
@@ -370,6 +370,10 @@ static const struct usb_device_id usb_quirk_list[] = { · 369 unmodified lines
370370 { USB_DEVICE(0x0926, 0x0202), .driver_info =
371371 USB_QUIRK_ENDPOINT_IGNORE },
372372
373+ /* Sound Devices MixPre-D */
374+ { USB_DEVICE(0x0926, 0x0208), .driver_info =
375+ USB_QUIRK_ENDPOINT_IGNORE },
376+
373377 /* Keytouch QWERTY Panel keyboard */
374378 { USB_DEVICE(0x0926, 0x3333), .driver_info =
375379 USB_QUIRK_CONFIG_INTF_STRINGS },
@@ -465,6 +469,8 @@ static const struct usb_device_id usb_quirk_list[] = { · 89 unmodified lines
465469
466470 { USB_DEVICE(0x2386, 0x3119), .driver_info = USB_QUIRK_NO_LPM },
467471
472+ { USB_DEVICE(0x2386, 0x350e), .driver_info = USB_QUIRK_NO_LPM },
473+
468474 /* DJI CineSSD */
469475 { USB_DEVICE(0x2ca3, 0x0031), .driver_info = USB_QUIRK_NO_LPM },
470476
@@ -509,6 +515,7 @@ static const struct usb_device_id usb_amd_resume_quirk_list[] = { · 38 unmodified lines
509515 */
510516 static const struct usb_device_id usb_endpoint_ignore[] = {
511517 { USB_DEVICE_INTERFACE_NUMBER(0x0926, 0x0202, 1), .driver_info = 0x85 },
518+ { USB_DEVICE_INTERFACE_NUMBER(0x0926, 0x0208, 1), .driver_info = 0x85 },
512519 { }
513520 };
514521
drivers/usb/dwc3/gadget.c+89−18
@@ -1054,27 +1054,25 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, · 1053 unmodified lines
10541054 * dwc3_prepare_one_trb - setup one TRB from one request
10551055 * @dep: endpoint for which this request is prepared
10561056 * @req: dwc3_request pointer
1057+ * @trb_length: buffer size of the TRB
10571058 * @chain: should this TRB be chained to the next?
10581059 * @node: only for isochronous endpoints. First TRB needs different type.
10591060 */
10601061 static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
1061− struct dwc3_request *req, unsigned chain, unsigned node)
1062+ struct dwc3_request *req, unsigned int trb_length,
1063+ unsigned chain, unsigned node)
10621064 {
10631065 struct dwc3_trb *trb;
1064− unsigned int length;
10651066 dma_addr_t dma;
10661067 unsigned stream_id = req->request.stream_id;
10671068 unsigned short_not_ok = req->request.short_not_ok;
10681069 unsigned no_interrupt = req->request.no_interrupt;
10691070 unsigned is_last = req->request.is_last;
10701071
1071− if (req->request.num_sgs > 0) {
1072− length = sg_dma_len(req->start_sg);
1072+ if (req->request.num_sgs > 0)
10731073 dma = sg_dma_address(req->start_sg);
1074− } else {
1075− length = req->request.length;
1074+ else
10761075 dma = req->request.dma;
1077− }
10781076
10791077 trb = &dep->trb_pool[dep->trb_enqueue];
10801078
@@ -1086,7 +1084,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, · 5 unmodified lines
10861084
10871085 req->num_trbs++;
10881086
1089− __dwc3_prepare_one_trb(dep, trb, dma, length, chain, node,
1087+ __dwc3_prepare_one_trb(dep, trb, dma, trb_length, chain, node,
10901088 stream_id, short_not_ok, no_interrupt, is_last);
10911089 }
10921090
@@ -1096,16 +1094,27 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, · 3 unmodified lines
10961094 struct scatterlist *sg = req->start_sg;
10971095 struct scatterlist *s;
10981096 int i;
1099−
1097+ unsigned int length = req->request.length;
11001098 unsigned int remaining = req->request.num_mapped_sgs
11011099 - req->num_queued_sgs;
11021100
1101+ /*
1102+ * If we resume preparing the request, then get the remaining length of
1103+ * the request and resume where we left off.
1104+ */
1105+ for_each_sg(req->request.sg, s, req->num_queued_sgs, i)
1106+ length -= sg_dma_len(s);
1107+
11031108 for_each_sg(sg, s, remaining, i) {
1104− unsigned int length = req->request.length;
11051109 unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc);
11061110 unsigned int rem = length % maxp;
1111+ unsigned int trb_length;
11071112 unsigned chain = true;
11081113
1114+ trb_length = min_t(unsigned int, length, sg_dma_len(s));
1115+
1116+ length -= trb_length;
1117+
11091118 /*
11101119 * IOMMU driver is coalescing the list of sgs which shares a
11111120 * page boundary into one and giving it to USB driver. With
@@ -1113,7 +1122,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, · 1 unmodified line
11131122 * sgs passed. So mark the chain bit to false if it isthe last
11141123 * mapped sg.
11151124 */
1116− if (i == remaining - 1)
1125+ if ((i == remaining - 1) || !length)
11171126 chain = false;
11181127
11191128 if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) {
@@ -1123,7 +1132,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, · 3 unmodified lines
11231132 req->needs_extra_trb = true;
11241133
11251134 /* prepare normal TRB */
1126− dwc3_prepare_one_trb(dep, req, true, i);
1135+ dwc3_prepare_one_trb(dep, req, trb_length, true, i);
11271136
11281137 /* Now prepare one extra TRB to align transfer size */
11291138 trb = &dep->trb_pool[dep->trb_enqueue];
@@ -1134,8 +1143,39 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, · 4 unmodified lines
11341143 req->request.short_not_ok,
11351144 req->request.no_interrupt,
11361145 req->request.is_last);
1146+ } else if (req->request.zero && req->request.length &&
1147+ !usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
1148+ !rem && !chain) {
1149+ struct dwc3 *dwc = dep->dwc;
1150+ struct dwc3_trb *trb;
1151+
1152+ req->needs_extra_trb = true;
1153+
1154+ /* Prepare normal TRB */
1155+ dwc3_prepare_one_trb(dep, req, trb_length, true, i);
1156+
1157+ /* Prepare one extra TRB to handle ZLP */
1158+ trb = &dep->trb_pool[dep->trb_enqueue];
1159+ req->num_trbs++;
1160+ __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0,
1161+ !req->direction, 1,
1162+ req->request.stream_id,
1163+ req->request.short_not_ok,
1164+ req->request.no_interrupt,
1165+ req->request.is_last);
1166+
1167+ /* Prepare one more TRB to handle MPS alignment */
1168+ if (!req->direction) {
1169+ trb = &dep->trb_pool[dep->trb_enqueue];
1170+ req->num_trbs++;
1171+ __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp,
1172+ false, 1, req->request.stream_id,
1173+ req->request.short_not_ok,
1174+ req->request.no_interrupt,
1175+ req->request.is_last);
1176+ }
11371177 } else {
1138− dwc3_prepare_one_trb(dep, req, chain, i);
1178+ dwc3_prepare_one_trb(dep, req, trb_length, chain, i);
11391179 }
11401180
11411181 /*
@@ -1150,6 +1190,16 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, · 8 unmodified lines
11501190
11511191 req->num_queued_sgs++;
11521192
1193+ /*
1194+ * The number of pending SG entries may not correspond to the
1195+ * number of mapped SG entries. If all the data are queued, then
1196+ * don't include unused SG entries.
1197+ */
1198+ if (length == 0) {
1199+ req->num_pending_sgs -= req->request.num_mapped_sgs - req->num_queued_sgs;
1200+ break;
1201+ }
1202+
11531203 if (!dwc3_calc_trbs_left(dep))
11541204 break;
11551205 }
@@ -1169,7 +1219,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, · 13 unmodified lines
11691219 req->needs_extra_trb = true;
11701220
11711221 /* prepare normal TRB */
1172− dwc3_prepare_one_trb(dep, req, true, 0);
1222+ dwc3_prepare_one_trb(dep, req, length, true, 0);
11731223
11741224 /* Now prepare one extra TRB to align transfer size */
11751225 trb = &dep->trb_pool[dep->trb_enqueue];
@@ -1180,6 +1230,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, · 4 unmodified lines
11801230 req->request.no_interrupt,
11811231 req->request.is_last);
11821232 } else if (req->request.zero && req->request.length &&
1233+ !usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
11831234 (IS_ALIGNED(req->request.length, maxp))) {
11841235 struct dwc3 *dwc = dep->dwc;
11851236 struct dwc3_trb *trb;
@@ -1187,18 +1238,29 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, · 1 unmodified line
11871238 req->needs_extra_trb = true;
11881239
11891240 /* prepare normal TRB */
1190− dwc3_prepare_one_trb(dep, req, true, 0);
1241+ dwc3_prepare_one_trb(dep, req, length, true, 0);
11911242
1192− /* Now prepare one extra TRB to handle ZLP */
1243+ /* Prepare one extra TRB to handle ZLP */
11931244 trb = &dep->trb_pool[dep->trb_enqueue];
11941245 req->num_trbs++;
11951246 __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0,
1196− false, 1, req->request.stream_id,
1247+ !req->direction, 1, req->request.stream_id,
11971248 req->request.short_not_ok,
11981249 req->request.no_interrupt,
11991250 req->request.is_last);
1251+
1252+ /* Prepare one more TRB to handle MPS alignment for OUT */
1253+ if (!req->direction) {
1254+ trb = &dep->trb_pool[dep->trb_enqueue];
1255+ req->num_trbs++;
1256+ __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp,
1257+ false, 1, req->request.stream_id,
1258+ req->request.short_not_ok,
1259+ req->request.no_interrupt,
1260+ req->request.is_last);
1261+ }
12001262 } else {
1201− dwc3_prepare_one_trb(dep, req, false, 0);
1263+ dwc3_prepare_one_trb(dep, req, length, false, 0);
12021264 }
12031265 }
12041266
@@ -2671,8 +2733,17 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, · 1466 unmodified lines
26712733 status);
26722734
26732735 if (req->needs_extra_trb) {
2736+ unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc);
2737+
26742738 ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
26752739 status);
2740+
2741+ /* Reclaim MPS padding TRB for ZLP */
2742+ if (!req->direction && req->request.zero && req->request.length &&
2743+ !usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
2744+ (IS_ALIGNED(req->request.length, maxp)))
2745+ ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status);
2746+
26762747 req->needs_extra_trb = false;
26772748 }
26782749
drivers/usb/gadget/function/f_ncm.c+69−12
@@ -1181,12 +1181,15 @@ static int ncm_unwrap_ntb(struct gether *port, · 1180 unmodified lines
11811181 int ndp_index;
11821182 unsigned dg_len, dg_len2;
11831183 unsigned ndp_len;
1184+ unsigned block_len;
11841185 struct sk_buff *skb2;
11851186 int ret = -EINVAL;
1186− unsigned max_size = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
1187+ unsigned ntb_max = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
1188+ unsigned frame_max = le16_to_cpu(ecm_desc.wMaxSegmentSize);
11871189 const struct ndp_parser_opts *opts = ncm->parser_opts;
11881190 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
11891191 int dgram_counter;
1192+ bool ndp_after_header;
11901193
11911194 /* dwSignature */
11921195 if (get_unaligned_le32(tmp) != opts->nth_sign) {
@@ -1205,25 +1208,37 @@ static int ncm_unwrap_ntb(struct gether *port, · 12 unmodified lines
12051208 }
12061209 tmp++; /* skip wSequence */
12071210
1211+ block_len = get_ncm(&tmp, opts->block_length);
12081212 /* (d)wBlockLength */
1209− if (get_ncm(&tmp, opts->block_length) > max_size) {
1213+ if (block_len > ntb_max) {
12101214 INFO(port->func.config->cdev, "OUT size exceeded\n");
12111215 goto err;
12121216 }
12131217
12141218 ndp_index = get_ncm(&tmp, opts->ndp_index);
1219+ ndp_after_header = false;
12151220
12161221 /* Run through all the NDP's in the NTB */
12171222 do {
1218− /* NCM 3.2 */
1219− if (((ndp_index % 4) != 0) &&
1220− (ndp_index < opts->nth_size)) {
1223+ /*
1224+ * NCM 3.2
1225+ * dwNdpIndex
1226+ */
1227+ if (((ndp_index % 4) != 0) ||
1228+ (ndp_index < opts->nth_size) ||
1229+ (ndp_index > (block_len -
1230+ opts->ndp_size))) {
12211231 INFO(port->func.config->cdev, "Bad index: %#X\n",
12221232 ndp_index);
12231233 goto err;
12241234 }
1235+ if (ndp_index == opts->nth_size)
1236+ ndp_after_header = true;
12251237
1226− /* walk through NDP */
1238+ /*
1239+ * walk through NDP
1240+ * dwSignature
1241+ */
12271242 tmp = (void *)(skb->data + ndp_index);
12281243 if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
12291244 INFO(port->func.config->cdev, "Wrong NDP SIGN\n");
@@ -1234,14 +1249,15 @@ static int ncm_unwrap_ntb(struct gether *port, · 4 unmodified lines
12341249 ndp_len = get_unaligned_le16(tmp++);
12351250 /*
12361251 * NCM 3.3.1
1252+ * wLength
12371253 * entry is 2 items
12381254 * item size is 16/32 bits, opts->dgram_item_len * 2 bytes
12391255 * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry
12401256 * Each entry is a dgram index and a dgram length.
12411257 */
12421258 if ((ndp_len < opts->ndp_size
1243− + 2 * 2 * (opts->dgram_item_len * 2))
1244− || (ndp_len % opts->ndplen_align != 0)) {
1259+ + 2 * 2 * (opts->dgram_item_len * 2)) ||
1260+ (ndp_len % opts->ndplen_align != 0)) {
12451261 INFO(port->func.config->cdev, "Bad NDP length: %#X\n",
12461262 ndp_len);
12471263 goto err;
@@ -1258,8 +1274,21 @@ static int ncm_unwrap_ntb(struct gether *port, · 10 unmodified lines
12581274
12591275 do {
12601276 index = index2;
1277+ /* wDatagramIndex[0] */
1278+ if ((index < opts->nth_size) ||
1279+ (index > block_len - opts->dpe_size)) {
1280+ INFO(port->func.config->cdev,
1281+ "Bad index: %#X\n", index);
1282+ goto err;
1283+ }
1284+
12611285 dg_len = dg_len2;
1262− if (dg_len < 14 + crc_len) { /* ethernet hdr + crc */
1286+ /*
1287+ * wDatagramLength[0]
1288+ * ethernet hdr + crc or larger than max frame size
1289+ */
1290+ if ((dg_len < 14 + crc_len) ||
1291+ (dg_len > frame_max)) {
12631292 INFO(port->func.config->cdev,
12641293 "Bad dgram length: %#X\n", dg_len);
12651294 goto err;
@@ -1283,6 +1312,37 @@ static int ncm_unwrap_ntb(struct gether *port, · 17 unmodified lines
12831312 index2 = get_ncm(&tmp, opts->dgram_item_len);
12841313 dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
12851314
1315+ if (index2 == 0 || dg_len2 == 0)
1316+ break;
1317+
1318+ /* wDatagramIndex[1] */
1319+ if (ndp_after_header) {
1320+ if (index2 < opts->nth_size + opts->ndp_size) {
1321+ INFO(port->func.config->cdev,
1322+ "Bad index: %#X\n", index2);
1323+ goto err;
1324+ }
1325+ } else {
1326+ if (index2 < opts->nth_size + opts->dpe_size) {
1327+ INFO(port->func.config->cdev,
1328+ "Bad index: %#X\n", index2);
1329+ goto err;
1330+ }
1331+ }
1332+ if (index2 > block_len - opts->dpe_size) {
1333+ INFO(port->func.config->cdev,
1334+ "Bad index: %#X\n", index2);
1335+ goto err;
1336+ }
1337+
1338+ /* wDatagramLength[1] */
1339+ if ((dg_len2 < 14 + crc_len) ||
1340+ (dg_len2 > frame_max)) {
1341+ INFO(port->func.config->cdev,
1342+ "Bad dgram length: %#X\n", dg_len);
1343+ goto err;
1344+ }
1345+
12861346 /*
12871347 * Copy the data into a new skb.
12881348 * This ensures the truesize is correct
@@ -1299,9 +1359,6 @@ static int ncm_unwrap_ntb(struct gether *port, · 10 unmodified lines
12991359 ndp_len -= 2 * (opts->dgram_item_len * 2);
13001360
13011361 dgram_counter++;
1302−
1303− if (index2 == 0 || dg_len2 == 0)
1304− break;
13051362 } while (ndp_len > 2 * (opts->dgram_item_len * 2));
13061363 } while (ndp_index);
13071364
drivers/usb/gadget/function/f_tcm.c+4−3
@@ -753,12 +753,13 @@ static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) · 752 unmodified lines
753753 goto err_sts;
754754
755755 return 0;
756+
756757 err_sts:
757− usb_ep_free_request(fu->ep_status, stream->req_status);
758− stream->req_status = NULL;
759−err_out:
760758 usb_ep_free_request(fu->ep_out, stream->req_out);
761759 stream->req_out = NULL;
760+err_out:
761+ usb_ep_free_request(fu->ep_in, stream->req_in);
762+ stream->req_in = NULL;
762763 out:
763764 return -ENOMEM;
764765 }
drivers/usb/gadget/u_f.h+27−11
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #define __U_F_H__
1515
1616 #include <linux/usb/gadget.h>
17+#include <linux/overflow.h>
1718
1819 /* Variable Length Array Macros **********************************************/
1920 #define vla_group(groupname) size_t groupname##__next = 0
@@ -21,21 +22,36 @@ · 1 unmodified line
2122
2223 #define vla_item(groupname, type, name, n) \
2324 size_t groupname##_##name##__offset = ({ \
24− size_t align_mask = __alignof__(type) - 1; \
25− size_t offset = (groupname##__next + align_mask) & ~align_mask;\
26− size_t size = (n) * sizeof(type); \
27− groupname##__next = offset + size; \
25+ size_t offset = 0; \
26+ if (groupname##__next != SIZE_MAX) { \
27+ size_t align_mask = __alignof__(type) - 1; \
28+ size_t size = array_size(n, sizeof(type)); \
29+ offset = (groupname##__next + align_mask) & \
30+ ~align_mask; \
31+ if (check_add_overflow(offset, size, \
32+ &groupname##__next)) { \
33+ groupname##__next = SIZE_MAX; \
34+ offset = 0; \
35+ } \
36+ } \
2837 offset; \
2938 })
3039
3140 #define vla_item_with_sz(groupname, type, name, n) \
32− size_t groupname##_##name##__sz = (n) * sizeof(type); \
33− size_t groupname##_##name##__offset = ({ \
34− size_t align_mask = __alignof__(type) - 1; \
35− size_t offset = (groupname##__next + align_mask) & ~align_mask;\
36− size_t size = groupname##_##name##__sz; \
37− groupname##__next = offset + size; \
38− offset; \
41+ size_t groupname##_##name##__sz = array_size(n, sizeof(type)); \
42+ size_t groupname##_##name##__offset = ({ \
43+ size_t offset = 0; \
44+ if (groupname##__next != SIZE_MAX) { \
45+ size_t align_mask = __alignof__(type) - 1; \
46+ offset = (groupname##__next + align_mask) & \
47+ ~align_mask; \
48+ if (check_add_overflow(offset, groupname##_##name##__sz,\
49+ &groupname##__next)) { \
50+ groupname##__next = SIZE_MAX; \
51+ offset = 0; \
52+ } \
53+ } \
54+ offset; \
3955 })
4056
4157 #define vla_ptr(ptr, groupname, name) \
drivers/usb/host/ohci-exynos.c+2−3
@@ -171,9 +171,8 @@ static int exynos_ohci_probe(struct platform_device *pdev) · 170 unmodified lines
171171 hcd->rsrc_len = resource_size(res);
172172
173173 irq = platform_get_irq(pdev, 0);
174− if (!irq) {
175− dev_err(&pdev->dev, "Failed to get IRQ\n");
176− err = -ENODEV;
174+ if (irq < 0) {
175+ err = irq;
177176 goto fail_io;
178177 }
179178
drivers/usb/host/xhci-debugfs.c+4−4
@@ -274,7 +274,7 @@ static int xhci_slot_context_show(struct seq_file *s, void *unused) · 273 unmodified lines
274274
275275 static int xhci_endpoint_context_show(struct seq_file *s, void *unused)
276276 {
277− int dci;
277+ int ep_index;
278278 dma_addr_t dma;
279279 struct xhci_hcd *xhci;
280280 struct xhci_ep_ctx *ep_ctx;
@@ -283,9 +283,9 @@ static int xhci_endpoint_context_show(struct seq_file *s, void *unused) · 2 unmodified lines
283283
284284 xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
285285
286− for (dci = 1; dci < 32; dci++) {
287− ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, dci);
288− dma = dev->out_ctx->dma + dci * CTX_SIZE(xhci->hcc_params);
286+ for (ep_index = 0; ep_index < 31; ep_index++) {
287+ ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
288+ dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params);
289289 seq_printf(s, "%pad: %s\n", &dma,
290290 xhci_decode_ep_context(le32_to_cpu(ep_ctx->ep_info),
291291 le32_to_cpu(ep_ctx->ep_info2),
drivers/usb/host/xhci-hub.c+10−9
@@ -740,15 +740,6 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, · 739 unmodified lines
740740 {
741741 u32 pls = status_reg & PORT_PLS_MASK;
742742
743− /* resume state is a xHCI internal state.
744− * Do not report it to usb core, instead, pretend to be U3,
745− * thus usb core knows it's not ready for transfer
746− */
747− if (pls == XDEV_RESUME) {
748− *status |= USB_SS_PORT_LS_U3;
749− return;
750− }
751−
752743 /* When the CAS bit is set then warm reset
753744 * should be performed on port
754745 */
@@ -770,6 +761,16 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, · 15 unmodified lines
770761 */
771762 pls |= USB_PORT_STAT_CONNECTION;
772763 } else {
764+ /*
765+ * Resume state is an xHCI internal state. Do not report it to
766+ * usb core, instead, pretend to be U3, thus usb core knows
767+ * it's not ready for transfer.
768+ */
769+ if (pls == XDEV_RESUME) {
770+ *status |= USB_SS_PORT_LS_U3;
771+ return;
772+ }
773+
773774 /*
774775 * If CAS bit isn't set but the Port is already at
775776 * Compliance Mode, fake a connection so the USB core
drivers/usb/host/xhci-pci-renesas.c+1−18
@@ -50,20 +50,6 @@ · 49 unmodified lines
5050 #define RENESAS_RETRY 10000
5151 #define RENESAS_DELAY 10
5252
53−#define ROM_VALID_01 0x2013
54−#define ROM_VALID_02 0x2026
55−
56−static int renesas_verify_fw_version(struct pci_dev *pdev, u32 version)
57−{
58− switch (version) {
59− case ROM_VALID_01:
60− case ROM_VALID_02:
61− return 0;
62− }
63− dev_err(&pdev->dev, "FW has invalid version :%d\n", version);
64− return -EINVAL;
65−}
66−
6753 static int renesas_fw_download_image(struct pci_dev *dev,
6854 const u32 *fw, size_t step, bool rom)
6955 {
@@ -202,10 +188,7 @@ static int renesas_check_rom_state(struct pci_dev *pdev) · 132 unmodified lines
202188
203189 version &= RENESAS_FW_VERSION_FIELD;
204190 version = version >> RENESAS_FW_VERSION_OFFSET;
205−
206− err = renesas_verify_fw_version(pdev, version);
207− if (err)
208− return err;
191+ dev_dbg(&pdev->dev, "Found ROM version: %x\n", version);
209192
210193 /*
211194 * Test if ROM is present and loaded, if so we can skip everything
drivers/usb/host/xhci-tegra.c+3−1
@@ -1136,7 +1136,7 @@ static struct phy *tegra_xusb_get_phy(struct tegra_xusb *tegra, char *name, · 1135 unmodified lines
11361136 unsigned int i, phy_count = 0;
11371137
11381138 for (i = 0; i < tegra->soc->num_types; i++) {
1139− if (!strncmp(tegra->soc->phy_types[i].name, "usb2",
1139+ if (!strncmp(tegra->soc->phy_types[i].name, name,
11401140 strlen(name)))
11411141 return tegra->phys[phy_count+port];
11421142
@@ -1258,6 +1258,8 @@ static int tegra_xusb_init_usb_phy(struct tegra_xusb *tegra) · 115 unmodified lines
12581258
12591259 INIT_WORK(&tegra->id_work, tegra_xhci_id_work);
12601260 tegra->id_nb.notifier_call = tegra_xhci_id_notify;
1261+ tegra->otg_usb2_port = -EINVAL;
1262+ tegra->otg_usb3_port = -EINVAL;
12611263
12621264 for (i = 0; i < tegra->num_usb_phys; i++) {
12631265 struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", i);
drivers/usb/host/xhci.c+2−1
@@ -3236,10 +3236,11 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, · 3235 unmodified lines
32363236
32373237 wait_for_completion(cfg_cmd->completion);
32383238
3239− ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE;
32403239 xhci_free_command(xhci, cfg_cmd);
32413240 cleanup:
32423241 xhci_free_command(xhci, stop_cmd);
3242+ if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE)
3243+ ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE;
32433244 }
32443245
32453246 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,
drivers/usb/misc/lvstest.c+1−1
@@ -426,7 +426,7 @@ static int lvs_rh_probe(struct usb_interface *intf, · 425 unmodified lines
426426 USB_DT_SS_HUB_SIZE, USB_CTRL_GET_TIMEOUT);
427427 if (ret < (USB_DT_HUB_NONVAR_SIZE + 2)) {
428428 dev_err(&hdev->dev, "wrong root hub descriptor read %d\n", ret);
429− return ret;
429+ return ret < 0 ? ret : -EINVAL;
430430 }
431431
432432 /* submit urb to poll interrupt endpoint */
drivers/usb/misc/yurex.c+1−1
@@ -492,7 +492,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer, · 491 unmodified lines
492492 prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
493493 dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__,
494494 dev->cntl_buffer[0]);
495− retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL);
495+ retval = usb_submit_urb(dev->cntl_urb, GFP_ATOMIC);
496496 if (retval >= 0)
497497 timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);
498498 finish_wait(&dev->waitq, &wait);
drivers/usb/phy/phy-jz4770.c+1−0
@@ -176,6 +176,7 @@ static int ingenic_usb_phy_init(struct usb_phy *phy) · 175 unmodified lines
176176
177177 /* Wait for PHY to reset */
178178 usleep_range(30, 300);
179+ reg = readl(priv->base + REG_USBPCR_OFFSET);
179180 writel(reg & ~USBPCR_POR, priv->base + REG_USBPCR_OFFSET);
180181 usleep_range(300, 1000);
181182
drivers/usb/storage/unusual_devs.h+1−1
@@ -2328,7 +2328,7 @@ UNUSUAL_DEV( 0x357d, 0x7788, 0x0114, 0x0114, · 2327 unmodified lines
23282328 "JMicron",
23292329 "USB to ATA/ATAPI Bridge",
23302330 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2331− US_FL_BROKEN_FUA ),
2331+ US_FL_BROKEN_FUA | US_FL_IGNORE_UAS ),
23322332
23332333 /* Reported by Andrey Rahmatullin <wrar@altlinux.org> */
23342334 UNUSUAL_DEV( 0x4102, 0x1020, 0x0100, 0x0100,
drivers/usb/storage/unusual_uas.h+14−0
@@ -28,6 +28,13 @@ · 27 unmodified lines
2828 * and don't forget to CC: the USB development list <linux-usb@vger.kernel.org>
2929 */
3030
31+/* Reported-by: Till Dörges <doerges@pre-sense.de> */
32+UNUSUAL_DEV(0x054c, 0x087d, 0x0000, 0x9999,
33+ "Sony",
34+ "PSZ-HA*",
35+ USB_SC_DEVICE, USB_PR_DEVICE, NULL,
36+ US_FL_NO_REPORT_OPCODES),
37+
3138 /* Reported-by: Julian Groß <julian.g@posteo.de> */
3239 UNUSUAL_DEV(0x059f, 0x105f, 0x0000, 0x9999,
3340 "LaCie",
@@ -80,6 +87,13 @@ UNUSUAL_DEV(0x152d, 0x0578, 0x0000, 0x9999, · 46 unmodified lines
8087 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
8188 US_FL_BROKEN_FUA),
8289
90+/* Reported-by: Thinh Nguyen <thinhn@synopsys.com> */
91+UNUSUAL_DEV(0x154b, 0xf00d, 0x0000, 0x9999,
92+ "PNY",
93+ "Pro Elite SSD",
94+ USB_SC_DEVICE, USB_PR_DEVICE, NULL,
95+ US_FL_NO_ATA_1X),
96+
8397 /* Reported-by: Hans de Goede <hdegoede@redhat.com> */
8498 UNUSUAL_DEV(0x2109, 0x0711, 0x0000, 0x9999,
8599 "VIA",
drivers/usb/typec/tcpm/tcpm.c+25−3
@@ -3372,13 +3372,31 @@ static void run_state_machine(struct tcpm_port *port) · 3371 unmodified lines
33723372 tcpm_set_state(port, SNK_HARD_RESET_SINK_OFF, 0);
33733373 break;
33743374 case SRC_HARD_RESET_VBUS_OFF:
3375− tcpm_set_vconn(port, true);
3375+ /*
3376+ * 7.1.5 Response to Hard Resets
3377+ * Hard Reset Signaling indicates a communication failure has occurred and the
3378+ * Source Shall stop driving VCONN, Shall remove Rp from the VCONN pin and Shall
3379+ * drive VBUS to vSafe0V as shown in Figure 7-9.
3380+ */
3381+ tcpm_set_vconn(port, false);
33763382 tcpm_set_vbus(port, false);
33773383 tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE,
33783384 tcpm_data_role_for_source(port));
3379− tcpm_set_state(port, SRC_HARD_RESET_VBUS_ON, PD_T_SRC_RECOVER);
3385+ /*
3386+ * If tcpc fails to notify vbus off, TCPM will wait for PD_T_SAFE_0V +
3387+ * PD_T_SRC_RECOVER before turning vbus back on.
3388+ * From Table 7-12 Sequence Description for a Source Initiated Hard Reset:
3389+ * 4. Policy Engine waits tPSHardReset after sending Hard Reset Signaling and then
3390+ * tells the Device Policy Manager to instruct the power supply to perform a
3391+ * Hard Reset. The transition to vSafe0V Shall occur within tSafe0V (t2).
3392+ * 5. After tSrcRecover the Source applies power to VBUS in an attempt to
3393+ * re-establish communication with the Sink and resume USB Default Operation.
3394+ * The transition to vSafe5V Shall occur within tSrcTurnOn(t4).
3395+ */
3396+ tcpm_set_state(port, SRC_HARD_RESET_VBUS_ON, PD_T_SAFE_0V + PD_T_SRC_RECOVER);
33803397 break;
33813398 case SRC_HARD_RESET_VBUS_ON:
3399+ tcpm_set_vconn(port, true);
33823400 tcpm_set_vbus(port, true);
33833401 port->tcpc->set_pd_rx(port->tcpc, true);
33843402 tcpm_set_attached_state(port, true);
@@ -3944,7 +3962,11 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port) · 559 unmodified lines
39443962 tcpm_set_state(port, SNK_HARD_RESET_WAIT_VBUS, 0);
39453963 break;
39463964 case SRC_HARD_RESET_VBUS_OFF:
3947− tcpm_set_state(port, SRC_HARD_RESET_VBUS_ON, 0);
3965+ /*
3966+ * After establishing the vSafe0V voltage condition on VBUS, the Source Shall wait
3967+ * tSrcRecover before re-applying VCONN and restoring VBUS to vSafe5V.
3968+ */
3969+ tcpm_set_state(port, SRC_HARD_RESET_VBUS_ON, PD_T_SRC_RECOVER);
39483970 break;
39493971 case HARD_RESET_SEND:
39503972 break;
drivers/usb/typec/ucsi/displayport.c+1−8
@@ -288,8 +288,6 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, · 287 unmodified lines
288288 struct typec_altmode *alt;
289289 struct ucsi_dp *dp;
290290
291− mutex_lock(&con->lock);
292−
293291 /* We can't rely on the firmware with the capabilities. */
294292 desc->vdo |= DP_CAP_DP_SIGNALING | DP_CAP_RECEPTACLE;
295293
@@ -298,15 +296,12 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, · 2 unmodified lines
298296 desc->vdo |= all_assignments << 16;
299297
300298 alt = typec_port_register_altmode(con->port, desc);
301− if (IS_ERR(alt)) {
302− mutex_unlock(&con->lock);
299+ if (IS_ERR(alt))
303300 return alt;
304− }
305301
306302 dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
307303 if (!dp) {
308304 typec_unregister_altmode(alt);
309− mutex_unlock(&con->lock);
310305 return ERR_PTR(-ENOMEM);
311306 }
312307
@@ -319,7 +314,5 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, · 6 unmodified lines
319314 alt->ops = &ucsi_displayport_ops;
320315 typec_altmode_set_drvdata(alt, dp);
321316
322− mutex_unlock(&con->lock);
323−
324317 return alt;
325318 }
drivers/usb/typec/ucsi/ucsi.c+53−50
@@ -146,40 +146,33 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) · 145 unmodified lines
146146 return UCSI_CCI_LENGTH(cci);
147147 }
148148
149−static int ucsi_run_command(struct ucsi *ucsi, u64 command,
150− void *data, size_t size)
149+int ucsi_send_command(struct ucsi *ucsi, u64 command,
150+ void *data, size_t size)
151151 {
152152 u8 length;
153153 int ret;
154154
155+ mutex_lock(&ucsi->ppm_lock);
156+
155157 ret = ucsi_exec_command(ucsi, command);
156158 if (ret < 0)
157− return ret;
159+ goto out;
158160
159161 length = ret;
160162
161163 if (data) {
162164 ret = ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, data, size);
163165 if (ret)
164− return ret;
166+ goto out;
165167 }
166168
167169 ret = ucsi_acknowledge_command(ucsi);
168170 if (ret)
169− return ret;
170−
171− return length;
172−}
173−
174−int ucsi_send_command(struct ucsi *ucsi, u64 command,
175− void *retval, size_t size)
176−{
177− int ret;
171+ goto out;
178172
179− mutex_lock(&ucsi->ppm_lock);
180− ret = ucsi_run_command(ucsi, command, retval, size);
173+ ret = length;
174+out:
181175 mutex_unlock(&ucsi->ppm_lock);
182−
183176 return ret;
184177 }
185178 EXPORT_SYMBOL_GPL(ucsi_send_command);
@@ -205,7 +198,7 @@ void ucsi_altmode_update_active(struct ucsi_connector *con) · 19 unmodified lines
205198 int i;
206199
207200 command = UCSI_GET_CURRENT_CAM | UCSI_CONNECTOR_NUMBER(con->num);
208− ret = ucsi_run_command(con->ucsi, command, &cur, sizeof(cur));
201+ ret = ucsi_send_command(con->ucsi, command, &cur, sizeof(cur));
209202 if (ret < 0) {
210203 if (con->ucsi->version > 0x0100) {
211204 dev_err(con->ucsi->dev,
@@ -354,7 +347,7 @@ ucsi_register_altmodes_nvidia(struct ucsi_connector *con, u8 recipient) · 142 unmodified lines
354347 command |= UCSI_GET_ALTMODE_RECIPIENT(recipient);
355348 command |= UCSI_GET_ALTMODE_CONNECTOR_NUMBER(con->num);
356349 command |= UCSI_GET_ALTMODE_OFFSET(i);
357− len = ucsi_run_command(con->ucsi, command, &alt, sizeof(alt));
350+ len = ucsi_send_command(con->ucsi, command, &alt, sizeof(alt));
358351 /*
359352 * We are collecting all altmodes first and then registering.
360353 * Some type-C device will return zero length data beyond last
@@ -431,7 +424,7 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient) · 70 unmodified lines
431424 command |= UCSI_GET_ALTMODE_RECIPIENT(recipient);
432425 command |= UCSI_GET_ALTMODE_CONNECTOR_NUMBER(con->num);
433426 command |= UCSI_GET_ALTMODE_OFFSET(i);
434− len = ucsi_run_command(con->ucsi, command, alt, sizeof(alt));
427+ len = ucsi_send_command(con->ucsi, command, alt, sizeof(alt));
435428 if (len <= 0)
436429 return len;
437430
@@ -502,7 +495,7 @@ static void ucsi_get_pdos(struct ucsi_connector *con, int is_partner) · 64 unmodified lines
502495 command |= UCSI_GET_PDOS_PARTNER_PDO(is_partner);
503496 command |= UCSI_GET_PDOS_NUM_PDOS(UCSI_MAX_PDOS - 1);
504497 command |= UCSI_GET_PDOS_SRC_PDOS;
505− ret = ucsi_run_command(ucsi, command, con->src_pdos,
498+ ret = ucsi_send_command(ucsi, command, con->src_pdos,
506499 sizeof(con->src_pdos));
507500 if (ret < 0) {
508501 dev_err(ucsi->dev, "UCSI_GET_PDOS failed (%d)\n", ret);
@@ -681,7 +674,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) · 172 unmodified lines
681674 */
682675 command = UCSI_GET_CAM_SUPPORTED;
683676 command |= UCSI_CONNECTOR_NUMBER(con->num);
684− ucsi_run_command(con->ucsi, command, NULL, 0);
677+ ucsi_send_command(con->ucsi, command, NULL, 0);
685678 }
686679
687680 if (con->status.change & UCSI_CONSTAT_PARTNER_CHANGE)
@@ -736,20 +729,24 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) · 48 unmodified lines
736729 u32 cci;
737730 int ret;
738731
732+ mutex_lock(&ucsi->ppm_lock);
733+
739734 ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
740735 sizeof(command));
741736 if (ret < 0)
742− return ret;
737+ goto out;
743738
744739 tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS);
745740
746741 do {
747− if (time_is_before_jiffies(tmo))
748− return -ETIMEDOUT;
742+ if (time_is_before_jiffies(tmo)) {
743+ ret = -ETIMEDOUT;
744+ goto out;
745+ }
749746
750747 ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
751748 if (ret)
752− return ret;
749+ goto out;
753750
754751 /* If the PPM is still doing something else, reset it again. */
755752 if (cci & ~UCSI_CCI_RESET_COMPLETE) {
@@ -757,13 +754,15 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) · 1 unmodified line
757754 &command,
758755 sizeof(command));
759756 if (ret < 0)
760− return ret;
757+ goto out;
761758 }
762759
763760 msleep(20);
764761 } while (!(cci & UCSI_CCI_RESET_COMPLETE));
765762
766− return 0;
763+out:
764+ mutex_unlock(&ucsi->ppm_lock);
765+ return ret;
767766 }
768767
769768 static int ucsi_role_cmd(struct ucsi_connector *con, u64 command)
@@ -775,9 +774,7 @@ static int ucsi_role_cmd(struct ucsi_connector *con, u64 command) · 5 unmodified lines
775774 u64 c;
776775
777776 /* PPM most likely stopped responding. Resetting everything. */
778− mutex_lock(&con->ucsi->ppm_lock);
779777 ucsi_reset_ppm(con->ucsi);
780− mutex_unlock(&con->ucsi->ppm_lock);
781778
782779 c = UCSI_SET_NOTIFICATION_ENABLE | con->ucsi->ntfy;
783780 ucsi_send_command(con->ucsi, c, NULL, 0);
@@ -901,12 +898,15 @@ static int ucsi_register_port(struct ucsi *ucsi, int index) · 117 unmodified lines
901898 con->num = index + 1;
902899 con->ucsi = ucsi;
903900
901+ /* Delay other interactions with the con until registration is complete */
902+ mutex_lock(&con->lock);
903+
904904 /* Get connector capability */
905905 command = UCSI_GET_CONNECTOR_CAPABILITY;
906906 command |= UCSI_CONNECTOR_NUMBER(con->num);
907− ret = ucsi_run_command(ucsi, command, &con->cap, sizeof(con->cap));
907+ ret = ucsi_send_command(ucsi, command, &con->cap, sizeof(con->cap));
908908 if (ret < 0)
909− return ret;
909+ goto out;
910910
911911 if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DRP)
912912 cap->data = TYPEC_PORT_DRD;
@@ -938,27 +938,32 @@ static int ucsi_register_port(struct ucsi *ucsi, int index) · 25 unmodified lines
938938
939939 ret = ucsi_register_port_psy(con);
940940 if (ret)
941− return ret;
941+ goto out;
942942
943943 /* Register the connector */
944944 con->port = typec_register_port(ucsi->dev, cap);
945− if (IS_ERR(con->port))
946− return PTR_ERR(con->port);
945+ if (IS_ERR(con->port)) {
946+ ret = PTR_ERR(con->port);
947+ goto out;
948+ }
947949
948950 /* Alternate modes */
949951 ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_CON);
950− if (ret)
952+ if (ret) {
951953 dev_err(ucsi->dev, "con%d: failed to register alt modes\n",
952954 con->num);
955+ goto out;
956+ }
953957
954958 /* Get the status */
955959 command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
956− ret = ucsi_run_command(ucsi, command, &con->status,
957− sizeof(con->status));
960+ ret = ucsi_send_command(ucsi, command, &con->status, sizeof(con->status));
958961 if (ret < 0) {
959962 dev_err(ucsi->dev, "con%d: failed to get status\n", con->num);
960− return 0;
963+ ret = 0;
964+ goto out;
961965 }
966+ ret = 0; /* ucsi_send_command() returns length on success */
962967
963968 switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
964969 case UCSI_CONSTAT_PARTNER_TYPE_UFP:
@@ -983,17 +988,21 @@ static int ucsi_register_port(struct ucsi *ucsi, int index) · 18 unmodified lines
983988
984989 if (con->partner) {
985990 ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP);
986− if (ret)
991+ if (ret) {
987992 dev_err(ucsi->dev,
988993 "con%d: failed to register alternate modes\n",
989994 con->num);
990− else
995+ ret = 0;
996+ } else {
991997 ucsi_altmode_update_active(con);
998+ }
992999 }
9931000
9941001 trace_ucsi_register_port(con->num, &con->status);
9951002
996− return 0;
1003+out:
1004+ mutex_unlock(&con->lock);
1005+ return ret;
9971006 }
9981007
9991008 /**
@@ -1009,8 +1018,6 @@ static int ucsi_init(struct ucsi *ucsi) · 9 unmodified lines
10091018 int ret;
10101019 int i;
10111020
1012− mutex_lock(&ucsi->ppm_lock);
1013−
10141021 /* Reset the PPM */
10151022 ret = ucsi_reset_ppm(ucsi);
10161023 if (ret) {
@@ -1021,13 +1028,13 @@ static int ucsi_init(struct ucsi *ucsi) · 4 unmodified lines
10211028 /* Enable basic notifications */
10221029 ucsi->ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;
10231030 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
1024− ret = ucsi_run_command(ucsi, command, NULL, 0);
1031+ ret = ucsi_send_command(ucsi, command, NULL, 0);
10251032 if (ret < 0)
10261033 goto err_reset;
10271034
10281035 /* Get PPM capabilities */
10291036 command = UCSI_GET_CAPABILITY;
1030− ret = ucsi_run_command(ucsi, command, &ucsi->cap, sizeof(ucsi->cap));
1037+ ret = ucsi_send_command(ucsi, command, &ucsi->cap, sizeof(ucsi->cap));
10311038 if (ret < 0)
10321039 goto err_reset;
10331040
@@ -1054,12 +1061,10 @@ static int ucsi_init(struct ucsi *ucsi) · 20 unmodified lines
10541061 /* Enable all notifications */
10551062 ucsi->ntfy = UCSI_ENABLE_NTFY_ALL;
10561063 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
1057− ret = ucsi_run_command(ucsi, command, NULL, 0);
1064+ ret = ucsi_send_command(ucsi, command, NULL, 0);
10581065 if (ret < 0)
10591066 goto err_unregister;
10601067
1061− mutex_unlock(&ucsi->ppm_lock);
1062−
10631068 return 0;
10641069
10651070 err_unregister:
@@ -1074,8 +1079,6 @@ err_unregister: · 8 unmodified lines
10741079 err_reset:
10751080 ucsi_reset_ppm(ucsi);
10761081 err:
1077− mutex_unlock(&ucsi->ppm_lock);
1078−
10791082 return ret;
10801083 }
10811084
drivers/usb/usbip/stub_dev.c+6−0
@@ -461,6 +461,11 @@ static void stub_disconnect(struct usb_device *udev) · 460 unmodified lines
461461 return;
462462 }
463463
464+static bool usbip_match(struct usb_device *udev)
465+{
466+ return true;
467+}
468+
464469 #ifdef CONFIG_PM
465470
466471 /* These functions need usb_port_suspend and usb_port_resume,
@@ -486,6 +491,7 @@ struct usb_device_driver stub_driver = { · 19 unmodified lines
486491 .name = "usbip-host",
487492 .probe = stub_probe,
488493 .disconnect = stub_disconnect,
494+ .match = usbip_match,
489495 #ifdef CONFIG_PM
490496 .suspend = stub_suspend,
491497 .resume = stub_resume,
tools/usb/Build+2−0
@@ -0,0 +1,2 @@
1+testusb-y += testusb.o
2+ffs-test-y += ffs-test.o
tools/usb/Makefile+45−8
@@ -1,14 +1,51 @@
11 # SPDX-License-Identifier: GPL-2.0
22 # Makefile for USB tools
3+include ../scripts/Makefile.include
34
4−PTHREAD_LIBS = -lpthread
5−WARNINGS = -Wall -Wextra
6−CFLAGS = $(WARNINGS) -g -I../include
7−LDFLAGS = $(PTHREAD_LIBS)
5+bindir ?= /usr/bin
86
9−all: testusb ffs-test
10−%: %.c
11− $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
7+ifeq ($(srctree),)
8+srctree := $(patsubst %/,%,$(dir $(CURDIR)))
9+srctree := $(patsubst %/,%,$(dir $(srctree)))
10+endif
11+
12+# Do not use make's built-in rules
13+# (this improves performance and avoids hard-to-debug behaviour);
14+MAKEFLAGS += -r
15+
16+override CFLAGS += -O2 -Wall -Wextra -g -D_GNU_SOURCE -I$(OUTPUT)include -I$(srctree)/tools/include
17+override LDFLAGS += -lpthread
18+
19+ALL_TARGETS := testusb ffs-test
20+ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
21+
22+all: $(ALL_PROGRAMS)
23+
24+export srctree OUTPUT CC LD CFLAGS
25+include $(srctree)/tools/build/Makefile.include
26+
27+TESTUSB_IN := $(OUTPUT)testusb-in.o
28+$(TESTUSB_IN): FORCE
29+ $(Q)$(MAKE) $(build)=testusb
30+$(OUTPUT)testusb: $(TESTUSB_IN)
31+ $(QUIET_LINK)$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
32+
33+FFS_TEST_IN := $(OUTPUT)ffs-test-in.o
34+$(FFS_TEST_IN): FORCE
35+ $(Q)$(MAKE) $(build)=ffs-test
36+$(OUTPUT)ffs-test: $(FFS_TEST_IN)
37+ $(QUIET_LINK)$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
1238
1339 clean:
14− $(RM) testusb ffs-test
40+ rm -f $(ALL_PROGRAMS)
41+ find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.o.cmd' -delete
42+
43+install: $(ALL_PROGRAMS)
44+ install -d -m 755 $(DESTDIR)$(bindir); \
45+ for program in $(ALL_PROGRAMS); do \
46+ install $$program $(DESTDIR)$(bindir); \
47+ done
48+
49+FORCE:
50+
51+.PHONY: all install clean FORCE prepare

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t