Skip to content

Commit 6f0306d

Browse files
committed
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() ...
2 parents 42df60f + 20934c0 commit 6f0306d

26 files changed

Lines changed: 423 additions & 169 deletions

drivers/usb/class/cdc-acm.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,19 @@ static void acm_ctrl_irq(struct urb *urb)
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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,35 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
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,
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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ static int __check_usb_generic(struct device_driver *drv, void *data)
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,14 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_probe);
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)
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ static const struct usb_device_id usb_quirk_list[] = {
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[] = {
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[] = {
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

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,27 +1054,25 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb,
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,
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,24 +1094,35 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
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
11121121
* this the number of sgs mapped is not equal to the number of
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,
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,
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,
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,
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,25 +1230,37 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
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;
11861237

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,
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

0 commit comments

Comments
 (0)