Skip to content

Commit 5f05663

Browse files
committed
Merge tag 'usb-5.9-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB/PHY fixes from Greg KH: "Here are some small USB and PHY driver fixes for 5.9-rc8 The PHY driver fix resolves an issue found by Dan Carpenter for a memory leak. The USB fixes fall into two groups: - usb gadget fix from Bryan that is a fix for a previous security fix that showed up in in-the-wild testing - usb core driver matching bugfixes. This fixes a bug that has plagued the both the usbip driver and syzbot testing tools this -rc release cycle. All is now working properly so usbip connections will work, and syzbot can get back to fuzzing USB drivers properly. All have been in linux-next for a while with no reported issues" * tag 'usb-5.9-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: usbcore/driver: Accommodate usbip usbcore/driver: Fix incorrect downcast usbcore/driver: Fix specific driver selection Revert "usbip: Implement a match function to fix usbip" USB: gadget: f_ncm: Fix NDP16 datagram validation phy: ti: am654: Fix a leak in serdes_am654_probe()
2 parents f35c08e + 25b9e4b commit 5f05663

File tree

4 files changed

+40
-52
lines changed

4 files changed

+40
-52
lines changed

drivers/phy/ti/phy-am654-serdes.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,10 @@ static int serdes_am654_probe(struct platform_device *pdev)
725725
pm_runtime_enable(dev);
726726

727727
phy = devm_phy_create(dev, NULL, &ops);
728-
if (IS_ERR(phy))
729-
return PTR_ERR(phy);
728+
if (IS_ERR(phy)) {
729+
ret = PTR_ERR(phy);
730+
goto clk_err;
731+
}
730732

731733
phy_set_drvdata(phy, am654_phy);
732734
phy_provider = devm_of_phy_provider_register(dev, serdes_am654_xlate);

drivers/usb/core/driver.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,30 @@ static int usb_probe_device(struct device *dev)
269269
if (error)
270270
return error;
271271

272+
/* Probe the USB device with the driver in hand, but only
273+
* defer to a generic driver in case the current USB
274+
* device driver has an id_table or a match function; i.e.,
275+
* when the device driver was explicitly matched against
276+
* a device.
277+
*
278+
* If the device driver does not have either of these,
279+
* then we assume that it can bind to any device and is
280+
* not truly a more specialized/non-generic driver, so a
281+
* return value of -ENODEV should not force the device
282+
* to be handled by the generic USB driver, as there
283+
* can still be another, more specialized, device driver.
284+
*
285+
* This accommodates the usbip driver.
286+
*
287+
* TODO: What if, in the future, there are multiple
288+
* specialized USB device drivers for a particular device?
289+
* In such cases, there is a need to try all matching
290+
* specialised device drivers prior to setting the
291+
* use_generic_driver bit.
292+
*/
272293
error = udriver->probe(udev);
273-
if (error == -ENODEV && udriver != &usb_generic_driver) {
294+
if (error == -ENODEV && udriver != &usb_generic_driver &&
295+
(udriver->id_table || udriver->match)) {
274296
udev->use_generic_driver = 1;
275297
return -EPROBE_DEFER;
276298
}
@@ -831,14 +853,17 @@ static int usb_device_match(struct device *dev, struct device_driver *drv)
831853
udev = to_usb_device(dev);
832854
udrv = to_usb_device_driver(drv);
833855

834-
if (udrv->id_table &&
835-
usb_device_match_id(udev, udrv->id_table) != NULL) {
836-
return 1;
837-
}
856+
if (udrv->id_table)
857+
return usb_device_match_id(udev, udrv->id_table) != NULL;
838858

839859
if (udrv->match)
840860
return udrv->match(udev);
841-
return 0;
861+
862+
/* If the device driver under consideration does not have a
863+
* id_table or a match function, then let the driver's probe
864+
* function decide.
865+
*/
866+
return 1;
842867

843868
} else if (is_usb_interface(dev)) {
844869
struct usb_interface *intf;
@@ -905,26 +930,19 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
905930
return 0;
906931
}
907932

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-
916933
static int __usb_bus_reprobe_drivers(struct device *dev, void *data)
917934
{
918935
struct usb_device_driver *new_udriver = data;
919936
struct usb_device *udev;
920937
int ret;
921938

922-
if (!is_dev_usb_generic_driver(dev))
939+
/* Don't reprobe if current driver isn't usb_generic_driver */
940+
if (dev->driver != &usb_generic_driver.drvwrap.driver)
923941
return 0;
924942

925943
udev = to_usb_device(dev);
926944
if (usb_device_match_id(udev, new_udriver->id_table) == NULL &&
927-
(!new_udriver->match || new_udriver->match(udev) != 0))
945+
(!new_udriver->match || new_udriver->match(udev) == 0))
928946
return 0;
929947

930948
ret = device_reprobe(dev);

drivers/usb/gadget/function/f_ncm.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,6 @@ static int ncm_unwrap_ntb(struct gether *port,
11891189
const struct ndp_parser_opts *opts = ncm->parser_opts;
11901190
unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
11911191
int dgram_counter;
1192-
bool ndp_after_header;
11931192

11941193
/* dwSignature */
11951194
if (get_unaligned_le32(tmp) != opts->nth_sign) {
@@ -1216,7 +1215,6 @@ static int ncm_unwrap_ntb(struct gether *port,
12161215
}
12171216

12181217
ndp_index = get_ncm(&tmp, opts->ndp_index);
1219-
ndp_after_header = false;
12201218

12211219
/* Run through all the NDP's in the NTB */
12221220
do {
@@ -1232,8 +1230,6 @@ static int ncm_unwrap_ntb(struct gether *port,
12321230
ndp_index);
12331231
goto err;
12341232
}
1235-
if (ndp_index == opts->nth_size)
1236-
ndp_after_header = true;
12371233

12381234
/*
12391235
* walk through NDP
@@ -1312,37 +1308,13 @@ static int ncm_unwrap_ntb(struct gether *port,
13121308
index2 = get_ncm(&tmp, opts->dgram_item_len);
13131309
dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
13141310

1315-
if (index2 == 0 || dg_len2 == 0)
1316-
break;
1317-
13181311
/* 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-
}
13321312
if (index2 > block_len - opts->dpe_size) {
13331313
INFO(port->func.config->cdev,
13341314
"Bad index: %#X\n", index2);
13351315
goto err;
13361316
}
13371317

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-
13461318
/*
13471319
* Copy the data into a new skb.
13481320
* This ensures the truesize is correct
@@ -1359,6 +1331,8 @@ static int ncm_unwrap_ntb(struct gether *port,
13591331
ndp_len -= 2 * (opts->dgram_item_len * 2);
13601332

13611333
dgram_counter++;
1334+
if (index2 == 0 || dg_len2 == 0)
1335+
break;
13621336
} while (ndp_len > 2 * (opts->dgram_item_len * 2));
13631337
} while (ndp_index);
13641338

drivers/usb/usbip/stub_dev.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,6 @@ static void stub_disconnect(struct usb_device *udev)
461461
return;
462462
}
463463

464-
static bool usbip_match(struct usb_device *udev)
465-
{
466-
return true;
467-
}
468-
469464
#ifdef CONFIG_PM
470465

471466
/* These functions need usb_port_suspend and usb_port_resume,
@@ -491,7 +486,6 @@ struct usb_device_driver stub_driver = {
491486
.name = "usbip-host",
492487
.probe = stub_probe,
493488
.disconnect = stub_disconnect,
494-
.match = usbip_match,
495489
#ifdef CONFIG_PM
496490
.suspend = stub_suspend,
497491
.resume = stub_resume,

0 commit comments

Comments
 (0)