Skip to contentSkip to conversation

PCI: Add helper macro for pci_register_driver boilerplate

PATCH In review Greg KH 3 participants 7 messages Nov 18, 2011 – Dec 5, 2011

Subsystems (3)
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 PCI: Add helper macro for pci_register_driver boilerplate

From: Greg Kroah-Hartman <[email protected]>

This patch introduces the module_pci_driver macro which is a convenience macro for PCI driver modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the PCI driver. By using this macro it is possible to eliminate a few lines of boilerplate code per PCI driver.

Based on work done by Lars-Peter Clausen <[email protected]> for other busses (i2c and spi).

Cc Lars-Peter Clausen <[email protected]>

---

Jesse, I've added the same type of macros for i2c, spi, and usb to my driver-core tree, and converted a number of drivers to these new macros. If you give me the ack, I can add this patch to my tree as well.

I'll follow up this patch with an example showing how it works.

Comments?

 include/linux/pci.h |   13 +++++++++++++
 1 file changed, 13 insertions(+)
include/linux/pci.h +13 -0
@@ -941,6 +941,19 @@ int __must_check __pci_register_driver(struct pci_driver *, struct module *,
 	__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
 
 void pci_unregister_driver(struct pci_driver *dev);
+
+/**
+ * module_pci_driver() - Helper macro for registering a PCI driver
+ * @__pci_driver: pci_driver struct
+ *
+ * Helper macro for PCI drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_pci_driver(__pci_driver) \
+	module_driver(__pci_driver, pci_register_driver, \
+		       pci_unregister_driver)
+
 void pci_remove_behind_bridge(struct pci_dev *dev);
 struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
 int pci_add_dynid(struct pci_driver *drv,
author
#1 lore raw

PATCH 1/1 DWC3: use module_pci_driver

From: Greg Kroah-Hartman <[email protected]>

This cuts down on the boilerplate code.

Cc Lars-Peter Clausen <[email protected]>
Cc Felipe Balbi <[email protected]>

---

Here's an example of how this works, it ends up deleting a ton of duplicated code all over the kernel, and it also has the very nice side affect of deleting a bunch of "this module is now loading" printks that are just cluttering up our kernel logs, making the overall kernel size smaller, which is good thing.

 drivers/usb/dwc3/dwc3-pci.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/usb/dwc3/dwc3-pci.c +1 -11
@@ -206,14 +206,4 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
 
-static int __devinit dwc3_pci_init(void)
-{
-	return pci_register_driver(&dwc3_pci_driver);
-}
-module_init(dwc3_pci_init);
-
-static void __exit dwc3_pci_exit(void)
-{
-	pci_unregister_driver(&dwc3_pci_driver);
-}
-module_exit(dwc3_pci_exit);
+module_pci_driver(dwc3_pci_driver);
Acked-by on v1 1/1
#2 lore raw

Re: [PATCH] DWC3: use module_pci_driver

Hi,

Quoted 8 lines · Greg KH

From: Greg Kroah-Hartman <[email protected]>

This cuts down on the boilerplate code.

Cc Lars-Peter Clausen <[email protected]>
Cc Felipe Balbi <[email protected]>

Looks good to me. It would be nice to see a similar patch for dwc3-omap.c moving the platform_driver_register to this new macro :-)

Signature · 1 line
balbi
author
#3 lore raw

Re: [PATCH] DWC3: use module_pci_driver

Quoted 8 lines · Felipe Balbi

Hi,

Quoted 5 lines · Greg KH

From: Greg Kroah-Hartman <[email protected]>

This cuts down on the boilerplate code.

Quoted 6 lines
Quoted 3 lines
Cc Lars-Peter Clausen <[email protected]>
Cc Felipe Balbi <[email protected]>

Looks good to me. It would be nice to see a similar patch for dwc3-omap.c moving the platform_driver_register to this new macro :-)

We already have a platform driver macro in the tree, feel free to move it to use it now if you want :)

thanks,

gre gk-h

#4 lore raw

Re: [PATCH] DWC3: use module_pci_driver

Quoted 13 lines · Greg KH
Quoted 12 lines · Felipe Balbi

Hi,

Quoted 8 lines · Greg KH

From: Greg Kroah-Hartman <[email protected]>

This cuts down on the boilerplate code.

Cc Lars-Peter Clausen <[email protected]>
Cc Felipe Balbi <[email protected]>
Quoted 5 lines
Quoted 2 lines

Looks good to me. It would be nice to see a similar patch for dwc3-omap.c moving the platform_driver_register to this new macro :-)

We already have a platform driver macro in the tree, feel free to move it to use it now if you want :)

great, will do for 3.3 merge window.

Signature · 1 line
balbi
#5 lore raw
In reply to Greg KH
Quoted 16 lines · On Fri, 18 Nov 2011 10:12:49 -0800 Greg KH <[email protected]> wrote:

From: Greg Kroah-Hartman <[email protected]>

This patch introduces the module_pci_driver macro which is a convenience macro for PCI driver modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the PCI driver. By using this macro it is possible to eliminate a few lines of boilerplate code per PCI driver.

Based on work done by Lars-Peter Clausen <[email protected]> for other busses (i2c and spi).

Cc Lars-Peter Clausen <[email protected]>

---

Quoted 8 lines

Jesse, I've added the same type of macros for i2c, spi, and usb to my driver-core tree, and converted a number of drivers to these new macros. If you give me the ack, I can add this patch to my tree as well.

I'll follow up this patch with an example showing how it works.

Comments?

Yeah, I have no problem with it. You can queue it up with the other changes and add my acked-by to keep dependencies to a minimum.

Thanks,

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
author
#6 lore raw
Quoted 23 lines · Jesse Barnes
Quoted 20 lines · On Fri, 18 Nov 2011 10:12:49 -0800 Greg KH <[email protected]> wrote:

From: Greg Kroah-Hartman <[email protected]>

This patch introduces the module_pci_driver macro which is a convenience macro for PCI driver modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the PCI driver. By using this macro it is possible to eliminate a few lines of boilerplate code per PCI driver.

Based on work done by Lars-Peter Clausen <[email protected]> for other busses (i2c and spi).

Cc Lars-Peter Clausen <[email protected]>

---

Jesse, I've added the same type of macros for i2c, spi, and usb to my driver-core tree, and converted a number of drivers to these new macros. If you give me the ack, I can add this patch to my tree as well.

Quoted 7 lines
Quoted 4 lines

I'll follow up this patch with an example showing how it works.

Comments?

Yeah, I have no problem with it. You can queue it up with the other changes and add my acked-by to keep dependencies to a minimum.

Wonderful, will do.

greg k-h