* [PATCH] PCI: Add helper macro for pci_register_driver boilerplate
@ 2011-11-18 18:12 Greg KH
2011-11-18 18:14 ` [PATCH] DWC3: use module_pci_driver Greg KH
2011-12-05 18:28 ` [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Jesse Barnes
0 siblings, 2 replies; 7+ messages in thread
From: Greg KH @ 2011-11-18 18:12 UTC (permalink / raw)
To: Jesse Barnes; +Cc: linux-pci, Lars-Peter Clausen, Felipe Balbi
From: Greg Kroah-Hartman <gregkh@suse.de>
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 <lars@metafoo.de> for other
busses (i2c and spi).
Cc: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
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(+)
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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,
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] DWC3: use module_pci_driver
2011-11-18 18:12 [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Greg KH
@ 2011-11-18 18:14 ` Greg KH
2011-11-18 19:04 ` Felipe Balbi
2011-12-05 18:28 ` [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Jesse Barnes
1 sibling, 1 reply; 7+ messages in thread
From: Greg KH @ 2011-11-18 18:14 UTC (permalink / raw)
To: Jesse Barnes; +Cc: linux-pci, Lars-Peter Clausen, Felipe Balbi
From: Greg Kroah-Hartman <gregkh@suse.de>
This cuts down on the boilerplate code.
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
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(-)
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -206,14 +206,4 @@ MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
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);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DWC3: use module_pci_driver
2011-11-18 18:14 ` [PATCH] DWC3: use module_pci_driver Greg KH
@ 2011-11-18 19:04 ` Felipe Balbi
2011-11-18 19:11 ` Greg KH
0 siblings, 1 reply; 7+ messages in thread
From: Felipe Balbi @ 2011-11-18 19:04 UTC (permalink / raw)
To: Greg KH; +Cc: Jesse Barnes, linux-pci, Lars-Peter Clausen, Felipe Balbi
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
Hi,
On Fri, Nov 18, 2011 at 10:14:24AM -0800, Greg KH wrote:
> From: Greg Kroah-Hartman <gregkh@suse.de>
>
> This cuts down on the boilerplate code.
>
>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: Felipe Balbi <balbi@ti.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
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 :-)
Acked-by: Felipe Balbi <balbi@ti.com>
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DWC3: use module_pci_driver
2011-11-18 19:04 ` Felipe Balbi
@ 2011-11-18 19:11 ` Greg KH
2011-11-18 19:22 ` Felipe Balbi
0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2011-11-18 19:11 UTC (permalink / raw)
To: Felipe Balbi; +Cc: Jesse Barnes, linux-pci, Lars-Peter Clausen
On Fri, Nov 18, 2011 at 09:04:14PM +0200, Felipe Balbi wrote:
> Hi,
>
> On Fri, Nov 18, 2011 at 10:14:24AM -0800, Greg KH wrote:
> > From: Greg Kroah-Hartman <gregkh@suse.de>
> >
> > This cuts down on the boilerplate code.
> >
> >
> > Cc: Lars-Peter Clausen <lars@metafoo.de>
> > Cc: Felipe Balbi <balbi@ti.com>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
>
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] DWC3: use module_pci_driver
2011-11-18 19:11 ` Greg KH
@ 2011-11-18 19:22 ` Felipe Balbi
0 siblings, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2011-11-18 19:22 UTC (permalink / raw)
To: Greg KH; +Cc: Felipe Balbi, Jesse Barnes, linux-pci, Lars-Peter Clausen
[-- Attachment #1: Type: text/plain, Size: 780 bytes --]
On Fri, Nov 18, 2011 at 11:11:17AM -0800, Greg KH wrote:
> On Fri, Nov 18, 2011 at 09:04:14PM +0200, Felipe Balbi wrote:
> > Hi,
> >
> > On Fri, Nov 18, 2011 at 10:14:24AM -0800, Greg KH wrote:
> > > From: Greg Kroah-Hartman <gregkh@suse.de>
> > >
> > > This cuts down on the boilerplate code.
> > >
> > >
> > > Cc: Lars-Peter Clausen <lars@metafoo.de>
> > > Cc: Felipe Balbi <balbi@ti.com>
> > > Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
> >
> > 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.
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PCI: Add helper macro for pci_register_driver boilerplate
2011-11-18 18:12 [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Greg KH
2011-11-18 18:14 ` [PATCH] DWC3: use module_pci_driver Greg KH
@ 2011-12-05 18:28 ` Jesse Barnes
2011-12-05 18:38 ` Greg KH
1 sibling, 1 reply; 7+ messages in thread
From: Jesse Barnes @ 2011-12-05 18:28 UTC (permalink / raw)
To: Greg KH; +Cc: linux-pci, Lars-Peter Clausen, Felipe Balbi
[-- Attachment #1: Type: text/plain, Size: 1212 bytes --]
On Fri, 18 Nov 2011 10:12:49 -0800
Greg KH <greg@kroah.com> wrote:
> From: Greg Kroah-Hartman <gregkh@suse.de>
>
> 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 <lars@metafoo.de> for other
> busses (i2c and spi).
>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
>
> ---
>
> 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,
--
Jesse Barnes, Intel Open Source Technology Center
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PCI: Add helper macro for pci_register_driver boilerplate
2011-12-05 18:28 ` [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Jesse Barnes
@ 2011-12-05 18:38 ` Greg KH
0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2011-12-05 18:38 UTC (permalink / raw)
To: Jesse Barnes; +Cc: linux-pci, Lars-Peter Clausen, Felipe Balbi
On Mon, Dec 05, 2011 at 10:28:29AM -0800, Jesse Barnes wrote:
> On Fri, 18 Nov 2011 10:12:49 -0800
> Greg KH <greg@kroah.com> wrote:
>
> > From: Greg Kroah-Hartman <gregkh@suse.de>
> >
> > 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 <lars@metafoo.de> for other
> > busses (i2c and spi).
> >
> > Cc: Lars-Peter Clausen <lars@metafoo.de>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
> >
> > ---
> >
> > 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.
Wonderful, will do.
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-12-05 18:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-18 18:12 [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Greg KH
2011-11-18 18:14 ` [PATCH] DWC3: use module_pci_driver Greg KH
2011-11-18 19:04 ` Felipe Balbi
2011-11-18 19:11 ` Greg KH
2011-11-18 19:22 ` Felipe Balbi
2011-12-05 18:28 ` [PATCH] PCI: Add helper macro for pci_register_driver boilerplate Jesse Barnes
2011-12-05 18:38 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).