From f772bb71891b5090472a744f07dbe268b5d4081b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 21 Oct 2020 15:04:33 +0200 Subject: [PATCH 1/2] usbcore/driver: Check both id_table and match() when both available When a USB device driver has both an id_table and a match() function, make sure to check both to find a match, first matching the id_table, then checking the match() function. This makes it possible to have module autoloading done through the id_table when devices are plugged in, before checking for further device eligibility in the match() function. Signed-off-by: Bastien Nocera --- drivers/usb/core/driver.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 98b7449c11f3..575275e72d65 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -845,6 +845,7 @@ static int usb_device_match(struct device *dev, struct device_driver *drv) if (is_usb_device(dev)) { struct usb_device *udev; struct usb_device_driver *udrv; + bool has_matched_id = false; /* interface drivers never match devices */ if (!is_usb_device_driver(drv)) @@ -853,8 +854,11 @@ static int usb_device_match(struct device *dev, struct device_driver *drv) udev = to_usb_device(dev); udrv = to_usb_device_driver(drv); - if (udrv->id_table) - return usb_device_match_id(udev, udrv->id_table) != NULL; + if (udrv->id_table) { + if (usb_device_match_id(udev, udrv->id_table) == NULL) + return 0; + has_matched_id = true; + } if (udrv->match) return udrv->match(udev); @@ -863,6 +867,8 @@ static int usb_device_match(struct device *dev, struct device_driver *drv) * id_table or a match function, then let the driver's probe * function decide. */ + if (has_matched_id) + return 0; return 1; } else if (is_usb_interface(dev)) { -- 2.28.0