Skip to content

Commit af8a6e6

Browse files
krzkjhovold
authored andcommitted
USB: serial: set driver owner when registering drivers
Modules registering drivers with usb_serial_register_drivers() might forget to set .owner field. The field is used by some of other kernel parts for reference counting (try_module_get()), so it is expected that drivers will set it. Solve the problem by moving this task away from the drivers to the core USB serial code, just like we did for platform_driver in commit 9447057 ("platform_device: use a macro instead of platform_driver_register"). Signed-off-by: Krzysztof Kozlowski <[email protected]> [ johan: amend commit summary ] Signed-off-by: Johan Hovold <[email protected]>
1 parent 47ac09b commit af8a6e6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

drivers/usb/serial/usb-serial.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,17 +1459,18 @@ static void usb_serial_deregister(struct usb_serial_driver *device)
14591459
}
14601460

14611461
/**
1462-
* usb_serial_register_drivers - register drivers for a usb-serial module
1462+
* __usb_serial_register_drivers - register drivers for a usb-serial module
14631463
* @serial_drivers: NULL-terminated array of pointers to drivers to be registered
1464+
* @owner: owning module
14641465
* @name: name of the usb_driver for this set of @serial_drivers
14651466
* @id_table: list of all devices this @serial_drivers set binds to
14661467
*
14671468
* Registers all the drivers in the @serial_drivers array, and dynamically
14681469
* creates a struct usb_driver with the name @name and id_table of @id_table.
14691470
*/
1470-
int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
1471-
const char *name,
1472-
const struct usb_device_id *id_table)
1471+
int __usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
1472+
struct module *owner, const char *name,
1473+
const struct usb_device_id *id_table)
14731474
{
14741475
int rc;
14751476
struct usb_driver *udriver;
@@ -1514,6 +1515,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
15141515

15151516
for (sd = serial_drivers; *sd; ++sd) {
15161517
(*sd)->usb_driver = udriver;
1518+
(*sd)->driver.owner = owner;
15171519
rc = usb_serial_register(*sd);
15181520
if (rc)
15191521
goto err_deregister_drivers;
@@ -1532,7 +1534,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
15321534
kfree(udriver);
15331535
return rc;
15341536
}
1535-
EXPORT_SYMBOL_GPL(usb_serial_register_drivers);
1537+
EXPORT_SYMBOL_GPL(__usb_serial_register_drivers);
15361538

15371539
/**
15381540
* usb_serial_deregister_drivers - deregister drivers for a usb-serial module

include/linux/usb/serial.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,11 @@ struct usb_serial_driver {
311311
#define to_usb_serial_driver(d) \
312312
container_of(d, struct usb_serial_driver, driver)
313313

314-
int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
315-
const char *name, const struct usb_device_id *id_table);
314+
#define usb_serial_register_drivers(serial_drivers, name, id_table) \
315+
__usb_serial_register_drivers(serial_drivers, THIS_MODULE, name, id_table)
316+
int __usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
317+
struct module *owner, const char *name,
318+
const struct usb_device_id *id_table);
316319
void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]);
317320
void usb_serial_port_softint(struct usb_serial_port *port);
318321

0 commit comments

Comments
 (0)