Skip to contentSkip to conversation

PCI: create builtin_pci_driver to avoid registration boilerplate

PATCH Applied Paul Gortmaker 3 participants 4 messages Aug 26, 2015 – Oct 6, 2015 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: create builtin_pci_driver to avoid registration boilerplate

In commit f309d4443130bf814e991f836e919dca22df37ae ("platform_device:
better support builtin boilerplate avoidance") we introduced the builtin_driver macro.

Here we use that support and extend it to PCI driver registration, so where a driver is clearly non-modular and builtin-only, we can register it in a similar fashion. And existing code that is clearly non-modular can be updated with the simple mapping of

     module_pci_driver(...)  ---> builtin_pci_driver(...)

We've essentially cloned the former to make the latter, and taken out the remove/module_exit parts since those never get used in a non-modular build of the code.

---
 include/linux/pci.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/pci.h +11 -0
index 88bee285b93d..8da2758e7d0e 100644
@@ -1187,6 +1187,17 @@ void pci_unregister_driver(struct pci_driver *dev);
 	module_driver(__pci_driver, pci_register_driver, \
 		       pci_unregister_driver)
 
+/**
+ * builtin_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 their
+ * init code. This eliminates a lot of boilerplate. Each driver may only
+ * use this macro once, and calling it replaces device_initcall(...)
+ */
+#define builtin_pci_driver(__pci_driver) \
+	builtin_driver(__pci_driver, pci_register_driver)
+
 struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
 int pci_add_dynid(struct pci_driver *drv,
 		  unsigned int vendor, unsigned int device,
Signature · 1 line
2.5.0
maintainer
#1 lore raw

Hi Paul,

Quoted 9 lines · Paul Gortmaker

In commit f309d4443130bf814e991f836e919dca22df37ae ("platform_device:
better support builtin boilerplate avoidance") we introduced the builtin_driver macro.

Here we use that support and extend it to PCI driver registration, so where a driver is clearly non-modular and builtin-only, we can register it in a similar fashion. And existing code that is clearly non-modular can be updated with the simple mapping of

Quoted 5 lines
     module_pci_driver(...)  ---> builtin_pci_driver(...)

We've essentially cloned the former to make the latter, and taken out the remove/module_exit parts since those never get used in a non-modular build of the code.

Do you have any estimate of how many potential users of this there are? I took a quick look at users of module_pci_driver() (I see almost 300 of them in v4.3-rc1), and most of them look like legitimate modules. But the comment mentions replacing device_initcall() as well, so maybe there are more there?

If only a couple would be converted to builtin_pci_driver(), I'm not sure it's worth it, because it does add more things to look at (builtin_pci_driver() in addition to module_pci_driver()).

Quoted 12 lines
---
 include/linux/pci.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/pci.h +0 -0
index 88bee285b93d..8da2758e7d0e 100644

include/linux/pci.h void pci_unregister_driver(struct pci_driver *dev); · line 1196

Quoted 10 lines
include/linux/pci.h +7 -0
@@ -1187,6 +1187,17 @@ void pci_unregister_driver(struct pci_driver *dev);
 	module_driver(__pci_driver, pci_register_driver, \
 		       pci_unregister_driver)
 
+/**
+ * builtin_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 their
+ * init code. This eliminates a lot of boilerplate. Each driver may only
+ * use this macro once, and calling it replaces device_initcall(...)

The builtin_platform_driver() patches I see are single-line patches, so they don't look like they remove a *lot* of boilerplate.

Bjorn

Quoted 10 lines
include/linux/pci.h +4 -0
+ */
+#define builtin_pci_driver(__pci_driver) \
+	builtin_driver(__pci_driver, pci_register_driver)
+
 struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
 int pci_add_dynid(struct pci_driver *drv,
 		  unsigned int vendor, unsigned int device,
Signature · 1 line
2.5.0
#2 lore raw
Quoted 18 lines · [Re: [PATCH] PCI: create builtin_pci_driver to avoid registration boilerplate]…

Hi Paul,

Quoted 9 lines · Paul Gortmaker

In commit f309d4443130bf814e991f836e919dca22df37ae ("platform_device:
better support builtin boilerplate avoidance") we introduced the builtin_driver macro.

Here we use that support and extend it to PCI driver registration, so where a driver is clearly non-modular and builtin-only, we can register it in a similar fashion. And existing code that is clearly non-modular can be updated with the simple mapping of

Quoted 5 lines
     module_pci_driver(...)  ---> builtin_pci_driver(...)

We've essentially cloned the former to make the latter, and taken out the remove/module_exit parts since those never get used in a non-modular build of the code.

Quoted 5 lines

Do you have any estimate of how many potential users of this there are? I took a quick look at users of module_pci_driver() (I see almost 300 of them in v4.3-rc1), and most of them look like legitimate modules. But the comment mentions replacing device_initcall() as well, so maybe there are more there?

It doesn't appear to be a lot; maybe a couple. When I sent this, I had not completed much of the treewide audit, nor strayed outside of x86, but I sent it ahead of time since I was hoping to stage any infrastructure patches like this ahead of conversions to avoid cross subsystem dependencies.

Quoted 4 lines

If only a couple would be converted to builtin_pci_driver(), I'm not sure it's worth it, because it does add more things to look at (builtin_pci_driver() in addition to module_pci_driver()).

So the real goal I am after here, which may not have been clear from this one stand-alone patch, is to ensure people have what they need to make non-modular drivers clearly non-modular. Currently we have about 300+ drivers/files including module.h and using modular registration functions when they can only be built in. And along with that is about 5k worth of dead code in exit / unregistration functions that never has been used.

In which case, the numbers maybe don't matter. If we have a specific modular registration function for subsystem X, then we probably should also have a non-modular/builtin parallel of the same thing.

However, since there are so few in PCI, I guess we could replace non-modular users with it open coded, if you don't want to add the new alias/macro, i.e.:

module_pci_driver(xyz) --> builtin_driver(xyz, pci_register_driver)

[...]

Quoted 9 lines
Quoted 6 lines

+ * builtin_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 their
+ * init code. This eliminates a lot of boilerplate. Each driver may only
+ * use this macro once, and calling it replaces device_initcall(...)

The builtin_platform_driver() patches I see are single-line patches, so they don't look like they remove a *lot* of boilerplate.

The comment applies here as much as it does to the same comment for the module_pci_driver macro ; I'm assuming it was in reference to what it would look like if none of the platform driver helper macros were used and the whole thing was open coded.

Anyway, I'm open to suggestions here, now that you know the whole story.

Paul.
--

Quoted 13 lines

Bjorn

Quoted 10 lines

+ */

include/linux/pci.h +3 -0
+#define builtin_pci_driver(__pci_driver) \
+	builtin_driver(__pci_driver, pci_register_driver)
+
 struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
 int pci_add_dynid(struct pci_driver *drv,
 		  unsigned int vendor, unsigned int device,
Signature · 1 line
2.5.0
#3 lore raw
In reply to Paul Gortmaker
Quoted 11 lines · Paul Gortmaker

In commit f309d4443130bf814e991f836e919dca22df37ae ("platform_device:
better support builtin boilerplate avoidance") we introduced the builtin_driver macro.

Here we use that support and extend it to PCI driver registration, so where a driver is clearly non-modular and builtin-only, we can register it in a similar fashion. And existing code that is clearly non-modular can be updated with the simple mapping of

     module_pci_driver(...)  ---> builtin_pci_driver(...)
Quoted 7 lines

We've essentially cloned the former to make the latter, and taken out the remove/module_exit parts since those never get used in a non-modular build of the code.

Applied to pci/misc for v4.4, thanks, Paul!

Quoted 34 lines
---
 include/linux/pci.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/pci.h +11 -0
index 88bee285b93d..8da2758e7d0e 100644
@@ -1187,6 +1187,17 @@ void pci_unregister_driver(struct pci_driver *dev);
 	module_driver(__pci_driver, pci_register_driver, \
 		       pci_unregister_driver)
 
+/**
+ * builtin_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 their
+ * init code. This eliminates a lot of boilerplate. Each driver may only
+ * use this macro once, and calling it replaces device_initcall(...)
+ */
+#define builtin_pci_driver(__pci_driver) \
+	builtin_driver(__pci_driver, pci_register_driver)
+
 struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
 int pci_add_dynid(struct pci_driver *drv,
 		  unsigned int vendor, unsigned int device,
Signature · 7 lines
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/