Skip to content

Commit 49a78b0

Browse files
Yajun Denggregkh
authored andcommitted
USB: core: Use device_driver directly in struct usb_driver and usb_device_driver
There is usbdrv_wrap in struct usb_driver and usb_device_driver, it contains device_driver and for_devices. for_devices is used to distinguish between device drivers and interface drivers. Like the is_usb_device(), it tests the type of the device. We can test that if the probe of device_driver is equal to usb_probe_device in is_usb_device_driver(), and then the struct usbdrv_wrap is no longer needed. Clean up struct usbdrv_wrap, use device_driver directly in struct usb_driver and usb_device_driver. This makes the code cleaner. Signed-off-by: Yajun Deng <[email protected]> Acked-by: Alan Stern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 33d4137 commit 49a78b0

File tree

13 files changed

+53
-68
lines changed

13 files changed

+53
-68
lines changed

drivers/bluetooth/btusb.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,10 +4790,8 @@ static struct usb_driver btusb_driver = {
47904790
.disable_hub_initiated_lpm = 1,
47914791

47924792
#ifdef CONFIG_DEV_COREDUMP
4793-
.drvwrap = {
4794-
.driver = {
4795-
.coredump = btusb_coredump,
4796-
},
4793+
.driver = {
4794+
.coredump = btusb_coredump,
47974795
},
47984796
#endif
47994797
};

drivers/net/can/usb/peak_usb/pcan_usb_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ static void __exit peak_usb_exit(void)
11431143
int err;
11441144

11451145
/* last chance do send any synchronous commands here */
1146-
err = driver_for_each_device(&peak_usb_driver.drvwrap.driver, NULL,
1146+
err = driver_for_each_device(&peak_usb_driver.driver, NULL,
11471147
NULL, peak_usb_do_device_exit);
11481148
if (err)
11491149
pr_err("%s: failed to stop all can devices (err %d)\n",

drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ static int brcmf_usb_reset_device(struct device *dev, void *notused)
15811581

15821582
void brcmf_usb_exit(void)
15831583
{
1584-
struct device_driver *drv = &brcmf_usbdrvr.drvwrap.driver;
1584+
struct device_driver *drv = &brcmf_usbdrvr.driver;
15851585
int ret;
15861586

15871587
brcmf_dbg(USB, "Enter\n");

drivers/net/wireless/marvell/mwifiex/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ static struct usb_driver mwifiex_usb_driver = {
687687
.suspend = mwifiex_usb_suspend,
688688
.resume = mwifiex_usb_resume,
689689
.soft_unbind = 1,
690-
.drvwrap.driver = {
690+
.driver = {
691691
.coredump = mwifiex_usb_coredump,
692692
},
693693
};

drivers/usb/core/driver.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ static int usb_create_newid_files(struct usb_driver *usb_drv)
189189
goto exit;
190190

191191
if (usb_drv->probe != NULL) {
192-
error = driver_create_file(&usb_drv->drvwrap.driver,
192+
error = driver_create_file(&usb_drv->driver,
193193
&driver_attr_new_id);
194194
if (error == 0) {
195-
error = driver_create_file(&usb_drv->drvwrap.driver,
195+
error = driver_create_file(&usb_drv->driver,
196196
&driver_attr_remove_id);
197197
if (error)
198-
driver_remove_file(&usb_drv->drvwrap.driver,
198+
driver_remove_file(&usb_drv->driver,
199199
&driver_attr_new_id);
200200
}
201201
}
@@ -209,9 +209,9 @@ static void usb_remove_newid_files(struct usb_driver *usb_drv)
209209
return;
210210

211211
if (usb_drv->probe != NULL) {
212-
driver_remove_file(&usb_drv->drvwrap.driver,
212+
driver_remove_file(&usb_drv->driver,
213213
&driver_attr_remove_id);
214-
driver_remove_file(&usb_drv->drvwrap.driver,
214+
driver_remove_file(&usb_drv->driver,
215215
&driver_attr_new_id);
216216
}
217217
}
@@ -552,7 +552,7 @@ int usb_driver_claim_interface(struct usb_driver *driver,
552552
if (!iface->authorized)
553553
return -ENODEV;
554554

555-
dev->driver = &driver->drvwrap.driver;
555+
dev->driver = &driver->driver;
556556
usb_set_intfdata(iface, data);
557557
iface->needs_binding = 0;
558558

@@ -615,7 +615,7 @@ void usb_driver_release_interface(struct usb_driver *driver,
615615
struct device *dev = &iface->dev;
616616

617617
/* this should never happen, don't release something that's not ours */
618-
if (!dev->driver || dev->driver != &driver->drvwrap.driver)
618+
if (!dev->driver || dev->driver != &driver->driver)
619619
return;
620620

621621
/* don't release from within disconnect() */
@@ -950,7 +950,7 @@ static int __usb_bus_reprobe_drivers(struct device *dev, void *data)
950950
int ret;
951951

952952
/* Don't reprobe if current driver isn't usb_generic_driver */
953-
if (dev->driver != &usb_generic_driver.drvwrap.driver)
953+
if (dev->driver != &usb_generic_driver.driver)
954954
return 0;
955955

956956
udev = to_usb_device(dev);
@@ -964,6 +964,11 @@ static int __usb_bus_reprobe_drivers(struct device *dev, void *data)
964964
return 0;
965965
}
966966

967+
bool is_usb_device_driver(const struct device_driver *drv)
968+
{
969+
return drv->probe == usb_probe_device;
970+
}
971+
967972
/**
968973
* usb_register_device_driver - register a USB device (not interface) driver
969974
* @new_udriver: USB operations for the device driver
@@ -983,15 +988,14 @@ int usb_register_device_driver(struct usb_device_driver *new_udriver,
983988
if (usb_disabled())
984989
return -ENODEV;
985990

986-
new_udriver->drvwrap.for_devices = 1;
987-
new_udriver->drvwrap.driver.name = new_udriver->name;
988-
new_udriver->drvwrap.driver.bus = &usb_bus_type;
989-
new_udriver->drvwrap.driver.probe = usb_probe_device;
990-
new_udriver->drvwrap.driver.remove = usb_unbind_device;
991-
new_udriver->drvwrap.driver.owner = owner;
992-
new_udriver->drvwrap.driver.dev_groups = new_udriver->dev_groups;
991+
new_udriver->driver.name = new_udriver->name;
992+
new_udriver->driver.bus = &usb_bus_type;
993+
new_udriver->driver.probe = usb_probe_device;
994+
new_udriver->driver.remove = usb_unbind_device;
995+
new_udriver->driver.owner = owner;
996+
new_udriver->driver.dev_groups = new_udriver->dev_groups;
993997

994-
retval = driver_register(&new_udriver->drvwrap.driver);
998+
retval = driver_register(&new_udriver->driver);
995999

9961000
if (!retval) {
9971001
pr_info("%s: registered new device driver %s\n",
@@ -1023,7 +1027,7 @@ void usb_deregister_device_driver(struct usb_device_driver *udriver)
10231027
pr_info("%s: deregistering device driver %s\n",
10241028
usbcore_name, udriver->name);
10251029

1026-
driver_unregister(&udriver->drvwrap.driver);
1030+
driver_unregister(&udriver->driver);
10271031
}
10281032
EXPORT_SYMBOL_GPL(usb_deregister_device_driver);
10291033

@@ -1051,18 +1055,17 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
10511055
if (usb_disabled())
10521056
return -ENODEV;
10531057

1054-
new_driver->drvwrap.for_devices = 0;
1055-
new_driver->drvwrap.driver.name = new_driver->name;
1056-
new_driver->drvwrap.driver.bus = &usb_bus_type;
1057-
new_driver->drvwrap.driver.probe = usb_probe_interface;
1058-
new_driver->drvwrap.driver.remove = usb_unbind_interface;
1059-
new_driver->drvwrap.driver.owner = owner;
1060-
new_driver->drvwrap.driver.mod_name = mod_name;
1061-
new_driver->drvwrap.driver.dev_groups = new_driver->dev_groups;
1058+
new_driver->driver.name = new_driver->name;
1059+
new_driver->driver.bus = &usb_bus_type;
1060+
new_driver->driver.probe = usb_probe_interface;
1061+
new_driver->driver.remove = usb_unbind_interface;
1062+
new_driver->driver.owner = owner;
1063+
new_driver->driver.mod_name = mod_name;
1064+
new_driver->driver.dev_groups = new_driver->dev_groups;
10621065
spin_lock_init(&new_driver->dynids.lock);
10631066
INIT_LIST_HEAD(&new_driver->dynids.list);
10641067

1065-
retval = driver_register(&new_driver->drvwrap.driver);
1068+
retval = driver_register(&new_driver->driver);
10661069
if (retval)
10671070
goto out;
10681071

@@ -1077,7 +1080,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
10771080
return retval;
10781081

10791082
out_newid:
1080-
driver_unregister(&new_driver->drvwrap.driver);
1083+
driver_unregister(&new_driver->driver);
10811084

10821085
pr_err("%s: error %d registering interface driver %s\n",
10831086
usbcore_name, retval, new_driver->name);
@@ -1102,7 +1105,7 @@ void usb_deregister(struct usb_driver *driver)
11021105
usbcore_name, driver->name);
11031106

11041107
usb_remove_newid_files(driver);
1105-
driver_unregister(&driver->drvwrap.driver);
1108+
driver_unregister(&driver->driver);
11061109
usb_free_dynids(driver);
11071110
}
11081111
EXPORT_SYMBOL_GPL(usb_deregister);

drivers/usb/core/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
431431
struct device *dev;
432432

433433
argb.minor = minor;
434-
argb.drv = &drv->drvwrap.driver;
434+
argb.drv = &drv->driver;
435435

436436
dev = bus_find_device(&usb_bus_type, NULL, &argb, __find_interface);
437437

drivers/usb/core/usb.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,7 @@ static inline int is_root_hub(struct usb_device *udev)
175175
return (udev->parent == NULL);
176176
}
177177

178-
/* Do the same for device drivers and interface drivers. */
179-
180-
static inline int is_usb_device_driver(struct device_driver *drv)
181-
{
182-
return container_of(drv, struct usbdrv_wrap, driver)->
183-
for_devices;
184-
}
178+
extern bool is_usb_device_driver(const struct device_driver *drv);
185179

186180
/* for labeling diagnostics */
187181
extern const char *usbcore_name;

drivers/usb/misc/onboard_usb_hub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static void onboard_hub_attach_usb_driver(struct work_struct *work)
244244
{
245245
int err;
246246

247-
err = driver_attach(&onboard_hub_usbdev_driver.drvwrap.driver);
247+
err = driver_attach(&onboard_hub_usbdev_driver.driver);
248248
if (err)
249249
pr_err("Failed to attach USB driver: %pe\n", ERR_PTR(err));
250250
}

drivers/usb/serial/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static ssize_t new_id_store(struct device_driver *driver,
113113
if (retval >= 0 && usb_drv->usb_driver != NULL)
114114
retval = usb_store_new_id(&usb_drv->usb_driver->dynids,
115115
usb_drv->usb_driver->id_table,
116-
&usb_drv->usb_driver->drvwrap.driver,
116+
&usb_drv->usb_driver->driver,
117117
buf, count);
118118
return retval;
119119
}

drivers/usb/serial/usb-serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
15211521

15221522
/* Now set udriver's id_table and look for matches */
15231523
udriver->id_table = id_table;
1524-
rc = driver_attach(&udriver->drvwrap.driver);
1524+
rc = driver_attach(&udriver->driver);
15251525
return 0;
15261526

15271527
err_deregister_drivers:

0 commit comments

Comments
 (0)