Skip to contentSkip to conversation

driver.h: add helper macro for module_exit() boilerplate

PATCH Superseded Gan, Yi Fang 2 participants 2 messages Dec 12, 2023 Driver core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver.h: add helper macro for module_exit() boilerplate

For the modules need a module_init() but don't need to do anything special in module_exit() might need to have an empty module_exit(). This patch add a new macro module_exit_stub() to replace the empty module_exit(). The macro is useful to remove the module_exit() boilerplate.

---
 include/linux/device/driver.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/device/driver.h +14 -0
index 7738f458995f..18e75c7b5c2f 100644
@@ -288,4 +288,18 @@ static int __init __driver##_init(void) \
 } \
 device_initcall(__driver##_init);
 
+/**
+ * module_exit_stub() - Helper macro for drivers that have init but don't
+ * do anything in exit. This eliminates some boilerplate.
+ * Each module may only use this macro one, and calling it replaces
+ * module_exit().
+ *
+ * @__driver: driver name
+ */
+#define module_exit_stub(__driver) \
+static void __exit __driver##_exit(void) \
+{ \
+} \
+module_exit(__driver##_exit)
+
 #endif	/* _DEVICE_DRIVER_H_ */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 10 lines · Yi Fang

For the modules need a module_init() but don't need to do anything special in module_exit() might need to have an empty module_exit(). This patch add a new macro module_exit_stub() to replace the empty module_exit(). The macro is useful to remove the module_exit() boilerplate.

---
 include/linux/device/driver.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Why would we take a macro that no one actually uses?

Please submit this with a user, you all know that this is the case, how did it pass your internal reviews (hint, I don't think it did...)

thanks,

greg k-h