Thread (6 messages) 6 messages, 2 authors, 2d ago
WARM2d

[PATCH 1/4] usb: core: pass THIS_MODULE implicitly through a macro

From: Shashank Balaji <hidden>
Date: 2026-07-22 03:41:49
Also in: linux-usb, lkml
Subsystem: networking drivers, onboard usb hub driver, the rest, usb apple mfi fastcharge driver, usb networking drivers, usb over ip driver, usb subsystem · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Kaehlcke, Linus Torvalds, Bastien Nocera, Valentina Manea, Shuah Khan, Greg Kroah-Hartman

Rename usb_register_device_driver() to __usb_register_device_driver() and replace
it with a macro wrapper that passes THIS_MODULE implicitly. This is in line with
what other buses do.

Co-developed-by: Rahul Bukte <redacted>
Signed-off-by: Rahul Bukte <redacted>
Signed-off-by: Shashank Balaji <redacted>
---
 include/linux/usb.h                     | 4 +++-
 drivers/net/usb/r8152.c                 | 2 +-
 drivers/usb/core/driver.c               | 6 +++---
 drivers/usb/core/usb.c                  | 2 +-
 drivers/usb/misc/apple-mfi-fastcharge.c | 2 +-
 drivers/usb/misc/onboard_usb_dev.c      | 2 +-
 drivers/usb/usbip/stub_main.c           | 2 +-
 7 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 1da4ad1610bc..2466183a45f0 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1368,7 +1368,9 @@ extern void usb_deregister(struct usb_driver *);
 	module_driver(__usb_driver, usb_register, \
 		       usb_deregister)
 
-extern int usb_register_device_driver(struct usb_device_driver *,
+#define usb_register_device_driver(new_udriver) \
+	__usb_register_device_driver(new_udriver, THIS_MODULE)
+extern int __usb_register_device_driver(struct usb_device_driver *,
 			struct module *);
 extern void usb_deregister_device_driver(struct usb_device_driver *);
 
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index f61686433031..73b9b2af1ed2 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -10495,7 +10495,7 @@ static int __init rtl8152_driver_init(void)
 {
 	int ret;
 
-	ret = usb_register_device_driver(&rtl8152_cfgselector_driver, THIS_MODULE);
+	ret = usb_register_device_driver(&rtl8152_cfgselector_driver);
 	if (ret)
 		return ret;
 
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f63004417058..eac1ff468c08 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -980,7 +980,7 @@ bool is_usb_device_driver(const struct device_driver *drv)
 }
 
 /**
- * usb_register_device_driver - register a USB device (not interface) driver
+ * __usb_register_device_driver - register a USB device (not interface) driver
  * @new_udriver: USB operations for the device driver
  * @owner: module owner of this driver.
  *
@@ -990,7 +990,7 @@ bool is_usb_device_driver(const struct device_driver *drv)
  *
  * Return: A negative error code on failure and 0 on success.
  */
-int usb_register_device_driver(struct usb_device_driver *new_udriver,
+int __usb_register_device_driver(struct usb_device_driver *new_udriver,
 		struct module *owner)
 {
 	int retval = 0;
@@ -1023,7 +1023,7 @@ int usb_register_device_driver(struct usb_device_driver *new_udriver,
 
 	return retval;
 }
-EXPORT_SYMBOL_GPL(usb_register_device_driver);
+EXPORT_SYMBOL_GPL(__usb_register_device_driver);
 
 /**
  * usb_deregister_device_driver - unregister a USB device (not interface) driver
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index df166cafe106..2559a180fdee 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1241,7 +1241,7 @@ static int __init usb_init(void)
 	retval = usb_hub_init();
 	if (retval)
 		goto hub_init_failed;
-	retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);
+	retval = usb_register_device_driver(&usb_generic_driver);
 	if (!retval)
 		goto out;
 
diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index af266e19f2fd..02adec28d9e6 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -245,7 +245,7 @@ static struct usb_device_driver mfi_fc_driver = {
 
 static int __init mfi_fc_driver_init(void)
 {
-	return usb_register_device_driver(&mfi_fc_driver, THIS_MODULE);
+	return usb_register_device_driver(&mfi_fc_driver);
 }
 
 static void __exit mfi_fc_driver_exit(void)
diff --git a/drivers/usb/misc/onboard_usb_dev.c b/drivers/usb/misc/onboard_usb_dev.c
index 11508ed4df25..c60406240416 100644
--- a/drivers/usb/misc/onboard_usb_dev.c
+++ b/drivers/usb/misc/onboard_usb_dev.c
@@ -706,7 +706,7 @@ static int __init onboard_dev_init(void)
 {
 	int ret;
 
-	ret = usb_register_device_driver(&onboard_dev_usbdev_driver, THIS_MODULE);
+	ret = usb_register_device_driver(&onboard_dev_usbdev_driver);
 	if (ret)
 		return ret;
 
diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
index 79110a69d697..01452f7bdabb 100644
--- a/drivers/usb/usbip/stub_main.c
+++ b/drivers/usb/usbip/stub_main.c
@@ -371,7 +371,7 @@ static int __init usbip_host_init(void)
 		return -ENOMEM;
 	}
 
-	ret = usb_register_device_driver(&stub_driver, THIS_MODULE);
+	ret = usb_register_device_driver(&stub_driver);
 	if (ret) {
 		pr_err("usb_register failed %d\n", ret);
 		goto err_usb_register;
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help