1 #ifndef LINUX_3_0_COMPAT_H
2 #define LINUX_3_0_COMPAT_H
4 #include <linux/version.h>
6 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
8 #include <linux/rcupdate.h>
11 * since commit 1c5cae815d19ffe02bdfda1260949ef2b1806171
12 * "net: call dev_alloc_name from register_netdevice" dev_alloc_name is
13 * called automatically. This is not implemented in older kernel
14 * versions so it will result in device wrong names.
16 static inline int register_netdevice_name(struct net_device *dev)
20 if (strchr(dev->name, '%')) {
21 err = dev_alloc_name(dev, dev->name);
26 return register_netdevice(dev);
29 #define register_netdevice(dev) register_netdevice_name(dev)
31 /* BCMA core, see drivers/bcma/ */
33 /* Broadcom's specific AMBA core, see drivers/bcma/ */
34 struct bcma_device_id {
40 #define BCMA_CORE(_manuf, _id, _rev, _class) \
41 { .manuf = _manuf, .id = _id, .rev = _rev, .class = _class, }
42 #define BCMA_CORETABLE_END \
45 #define BCMA_ANY_MANUF 0xFFFF
46 #define BCMA_ANY_ID 0xFFFF
47 #define BCMA_ANY_REV 0xFF
48 #define BCMA_ANY_CLASS 0xFF
49 #endif /* BCMA_CORE */
51 int mac_pton(const char *s, u8 *mac);
53 int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res);
54 int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res);
55 int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res);
56 int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res);
57 int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res);
58 int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res);
59 int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res);
60 int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res);
61 int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res);
62 int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res);
64 static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res)
66 return kstrtoull_from_user(s, count, base, res);
69 static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res)
71 return kstrtoll_from_user(s, count, base, res);
74 static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res)
76 return kstrtouint_from_user(s, count, base, res);
79 static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res)
81 return kstrtoint_from_user(s, count, base, res);
85 * This adds a nested function everywhere kfree_rcu() was called. This
86 * function frees the memory and is given as a function to call_rcu().
87 * The rcu callback could happen every time also after the module was
88 * unloaded and this will cause problems.
90 #define kfree_rcu(data, rcuhead) do { \
91 void __kfree_rcu_fn(struct rcu_head *rcu_head) \
94 ___ptr = container_of(rcu_head, typeof(*(data)), rcuhead);\
97 call_rcu(&(data)->rcuhead, __kfree_rcu_fn); \
103 * The define overwriting module_exit is based on the original module_exit
104 * which looks like this:
105 * #define module_exit(exitfn) \
106 * static inline exitcall_t __exittest(void) \
107 * { return exitfn; } \
108 * void cleanup_module(void) __attribute__((alias(#exitfn)));
110 * We replaced the call to the actual function exitfn() with a call to our
111 * function which calls the original exitfn() and then rcu_barrier()
113 * As a module will not be unloaded that ofter it should not have a big
114 * performance impact when rcu_barrier() is called on every module exit,
115 * also when no kfree_rcu() backport is used in that module.
118 #define module_exit(exitfn) \
119 static void __exit __exit_compat(void) \
124 void cleanup_module(void) __attribute__((alias("__exit_compat")));
128 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)) */
130 #endif /* LINUX_3_0_COMPAT_H */