Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88b7381

Browse files
hadessgregkh
authored andcommitted
USB: Select better matching USB drivers when available
Now that USB device drivers can reuse code from the generic USB devicedriver, we need to make sure that they get selected rather than thegeneric driver. Add an id_table and match vfunc to the usb_device_driverstruct, which will get used to select a better matching driver at->probe time.This is a similar mechanism to that used in the HID drivers, with thegeneric driver being selected unless there's a better matching one foundin the registered drivers (see hid_generic_match() indrivers/hid/hid-generic.c).Signed-off-by: Bastien Nocera <hadess@hadess.net>Acked-by: Alan Stern <stern@rowland.harvard.edu>Link:https://lore.kernel.org/r/20191016093933.693-5-hadess@hadess.netSigned-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parentaeebf2b commit88b7381

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

‎drivers/usb/core/driver.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,24 @@ static int usb_device_match(struct device *dev, struct device_driver *drv)
818818
{
819819
/* devices and interfaces are handled separately */
820820
if (is_usb_device(dev)) {
821+
structusb_device*udev;
822+
structusb_device_driver*udrv;
821823

822824
/* interface drivers never match devices */
823825
if (!is_usb_device_driver(drv))
824826
return0;
825827

826-
/* TODO: Add real matching code */
827-
return1;
828+
udev=to_usb_device(dev);
829+
udrv=to_usb_device_driver(drv);
830+
831+
if (udrv->id_table&&
832+
usb_device_match_id(udev,udrv->id_table)!=NULL) {
833+
return1;
834+
}
835+
836+
if (udrv->match)
837+
returnudrv->match(udev);
838+
return0;
828839

829840
}elseif (is_usb_interface(dev)) {
830841
structusb_interface*intf;

‎drivers/usb/core/generic.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,34 @@ int usb_choose_configuration(struct usb_device *udev)
195195
}
196196
EXPORT_SYMBOL_GPL(usb_choose_configuration);
197197

198+
staticint__check_usb_generic(structdevice_driver*drv,void*data)
199+
{
200+
structusb_device*udev=data;
201+
structusb_device_driver*udrv;
202+
203+
if (!is_usb_device_driver(drv))
204+
return0;
205+
udrv=to_usb_device_driver(drv);
206+
if (udrv==&usb_generic_driver)
207+
return0;
208+
if (!udrv->id_table)
209+
return0;
210+
211+
returnusb_device_match_id(udev,udrv->id_table)!=NULL;
212+
}
213+
214+
staticboolusb_generic_driver_match(structusb_device*udev)
215+
{
216+
/*
217+
* If any other driver wants the device, leave the device to this other
218+
* driver.
219+
*/
220+
if (bus_for_each_drv(&usb_bus_type,NULL,udev,__check_usb_generic))
221+
return false;
222+
223+
return true;
224+
}
225+
198226
intusb_generic_driver_probe(structusb_device*udev)
199227
{
200228
interr,c;
@@ -285,6 +313,7 @@ int usb_generic_driver_resume(struct usb_device *udev, pm_message_t msg)
285313

286314
structusb_device_driverusb_generic_driver= {
287315
.name="usb",
316+
.match=usb_generic_driver_match,
288317
.probe=usb_generic_driver_probe,
289318
.disconnect=usb_generic_driver_disconnect,
290319
#ifdefCONFIG_PM

‎include/linux/usb.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,13 +1237,15 @@ struct usb_driver {
12371237
structusb_device_driver {
12381238
constchar*name;
12391239

1240+
bool (*match) (structusb_device*udev);
12401241
int (*probe) (structusb_device*udev);
12411242
void (*disconnect) (structusb_device*udev);
12421243

12431244
int (*suspend) (structusb_device*udev,pm_message_tmessage);
12441245
int (*resume) (structusb_device*udev,pm_message_tmessage);
12451246
conststructattribute_group**dev_groups;
12461247
structusbdrv_wrapdrvwrap;
1248+
conststructusb_device_id*id_table;
12471249
unsignedintsupports_autosuspend:1;
12481250
unsignedintgeneric_subclass:1;
12491251
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp