[1/3] include: linux: spi: more helpers for declaring spi drivers
diff mbox series

Message ID 1560796840-18207-1-git-send-email-info@metux.net
State New
Headers show
Series
  • [1/3] include: linux: spi: more helpers for declaring spi drivers
Related show

Commit Message

Enrico Weigelt, metux IT consult June 17, 2019, 6:40 p.m. UTC
From: Enrico Weigelt <info@metux.net>

Add more helper macros for trivial driver init cases, similar to the
already existing module_spi_driver()+friends - now for those which
are initialized at other stages (eg. by subsys_initcall()).

This helps to further reduce driver init boilerplate.

Signed-off-by: Enrico Weigelt <info@metux.net>
---
 include/linux/spi/spi.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Mark Brown June 19, 2019, 12:14 p.m. UTC | #1
On Mon, Jun 17, 2019 at 08:40:38PM +0200, Enrico Weigelt, metux IT consult wrote:

> +/* subsys_spi_driver() - Helper macro for drivers that don't 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 subsys_initcall() and module_exit()
> + */
> +#define subsys_spi_driver(__spi_driver) \

I'm not convinced we want to be encouraging anyone to be using
subsys_initcall() for SPI drivers in the first place - my guess would be
that with deferred probing none of that is needed anyway and the driver
could just use module_spi_driver().  Certainly if the drivers do
actually need subsys_initcall() I'd like to understand why before going
forward with something like this, and ideally we'd be able to remove the
need.

Patch
diff mbox series

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 053abd2..f55ba34 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -296,6 +296,23 @@  static inline void spi_unregister_driver(struct spi_driver *sdrv)
 	module_driver(__spi_driver, spi_register_driver, \
 			spi_unregister_driver)
 
+/* subsys_spi_driver() - Helper macro for drivers that don't 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 subsys_initcall() and module_exit()
+ */
+#define subsys_spi_driver(__spi_driver) \
+static int __init __spi_driver##_init(void) \
+{ \
+	return spi_register_driver(&(__spi_driver)); \
+} \
+subsys_initcall(__spi_driver##_init); \
+static void __exit __spi_driver##_exit(void) \
+{ \
+	spi_unregister_driver(&(__spi_driver)); \
+} \
+module_exit(__spi_driver##_exit);
+
 /**
  * struct spi_controller - interface to SPI master or slave controller
  * @dev: device interface to this driver