]> git.openfabrics.org - ~emulex/for-vlad/old/compat.git/commitdiff
compat: add module_usb_driver and module_platform_driver
authorHauke Mehrtens <hauke@hauke-m.de>
Sat, 3 Dec 2011 14:49:26 +0000 (15:49 +0100)
committerLuis R. Rodriguez <mcgrof@qca.qualcomm.com>
Mon, 5 Dec 2011 19:58:20 +0000 (11:58 -0800)
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
include/linux/compat-3.2.h
include/linux/compat-3.3.h

index db0f648a6c298bda0ec0eca217371aa6ec05dad7..fb9ef68b550de6deddfd681a49ff6f84ecf33c3f 100644 (file)
@@ -55,6 +55,15 @@ static inline char *hex_byte_pack(char *buf, u8 byte)
        return buf;
 }
 
+/* module_platform_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 module_init() and module_exit()
+ */
+#define module_platform_driver(__platform_driver) \
+        module_driver(__platform_driver, platform_driver_register, \
+                        platform_driver_unregister)
+
 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)) */
 
 #endif /* LINUX_3_2_COMPAT_H */
index 9383a6eac366d74bf21352c10b5bfeb321e9810d..821333c4e9385011d5727db544ed63482ec70b08 100644 (file)
@@ -33,6 +33,41 @@ static inline void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
 
 typedef u32 netdev_features_t;
 
+/* source include/linux/device.h */
+/**
+ * module_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
+ * module_init() and module_exit().
+ *
+ * Use this macro to construct bus specific macros for registering
+ * drivers, and do not use it on its own.
+ */
+#define module_driver(__driver, __register, __unregister) \
+static int __init __driver##_init(void) \
+{ \
+       return __register(&(__driver)); \
+} \
+module_init(__driver##_init); \
+static void __exit __driver##_exit(void) \
+{ \
+       __unregister(&(__driver)); \
+} \
+module_exit(__driver##_exit);
+
+/* source include/linux/usb.h */
+/**
+ * module_usb_driver() - Helper macro for registering a USB driver
+ * @__usb_driver: usb_driver struct
+ *
+ * Helper macro for USB 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_usb_driver(__usb_driver) \
+       module_driver(__usb_driver, usb_register, \
+                      usb_deregister)
+
 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)) */
 
 #endif /* LINUX_3_3_COMPAT_H */