Message ID | 20170915123700.15890-1-bgalvani@redhat.com |
---|---|
State | Superseded |
Headers | show |
Series | common: avoid conflict with __bitwise and __force from linux/types.h | expand |
On Fri, 2017-09-15 at 14:37 +0200, Beniamino Galvani wrote: > Namespace the __bitwise and __force macros so that they don't > conflict > with the ones from linux/types.h: > > In file included from ../src/l2_packet/l2_packet_linux.c:15:0: > hostap/src/utils/common.h:438:0: warning: "__bitwise" redefined > #define __bitwise > > In file included from /usr/include/linux/filter.h:9:0, > from ../src/l2_packet/l2_packet_linux.c:13: > /usr/include/linux/types.h:21:0: note: this is the location of the > previous definition > #define __bitwise __bitwise__ I think we can just #ifdef them because it's a compatible, if not exactly identical, definition? johannes
On Fri, Sep 15, 2017 at 03:34:40PM +0200, Johannes Berg wrote: > On Fri, 2017-09-15 at 14:37 +0200, Beniamino Galvani wrote: > > Namespace the __bitwise and __force macros so that they don't > > conflict > > with the ones from linux/types.h: > > > > In file included from ../src/l2_packet/l2_packet_linux.c:15:0: > > hostap/src/utils/common.h:438:0: warning: "__bitwise" redefined > > #define __bitwise > > > > In file included from /usr/include/linux/filter.h:9:0, > > from ../src/l2_packet/l2_packet_linux.c:13: > > /usr/include/linux/types.h:21:0: note: this is the location of the > > previous definition > > #define __bitwise __bitwise__ > > I think we can just #ifdef them because it's a compatible, if not > exactly identical, definition? Yes, it's compatible. However, I think there could still be conflicts adding an #ifdef because in the kernel header those macros are not guarded and so it could happen that a file includes "common.h" and then includes another local header file that uses <linux/types.h>, causing a redefinition warning. Beniamino
On Fri, 2017-09-15 at 17:05 +0200, Beniamino Galvani wrote: > On Fri, Sep 15, 2017 at 03:34:40PM +0200, Johannes Berg wrote: > > On Fri, 2017-09-15 at 14:37 +0200, Beniamino Galvani wrote: > > > Namespace the __bitwise and __force macros so that they don't > > > conflict > > > with the ones from linux/types.h: > > > > > > In file included from ../src/l2_packet/l2_packet_linux.c:15:0: > > > hostap/src/utils/common.h:438:0: warning: "__bitwise" redefined > > > #define __bitwise > > > > > > In file included from /usr/include/linux/filter.h:9:0, > > > from ../src/l2_packet/l2_packet_linux.c:13: > > > /usr/include/linux/types.h:21:0: note: this is the location of > > > the > > > previous definition > > > #define __bitwise __bitwise__ > > > > I think we can just #ifdef them because it's a compatible, if not > > exactly identical, definition? > > Yes, it's compatible. However, I think there could still be conflicts > adding an #ifdef because in the kernel header those macros are not > guarded and so it could happen that a file includes "common.h" and > then includes another local header file that uses <linux/types.h>, > causing a redefinition warning. I guess I'd say you should include it the right way around - after all, there's already precedent for this (check the git history of these definitions) johannes
On Fri, Sep 15, 2017 at 05:07:31PM +0200, Johannes Berg wrote: > On Fri, 2017-09-15 at 17:05 +0200, Beniamino Galvani wrote: > > On Fri, Sep 15, 2017 at 03:34:40PM +0200, Johannes Berg wrote: > > > On Fri, 2017-09-15 at 14:37 +0200, Beniamino Galvani wrote: > > > > Namespace the __bitwise and __force macros so that they don't > > > > conflict > > > > with the ones from linux/types.h: > > > > > > > > In file included from ../src/l2_packet/l2_packet_linux.c:15:0: > > > > hostap/src/utils/common.h:438:0: warning: "__bitwise" redefined > > > > #define __bitwise > > > > > > > > In file included from /usr/include/linux/filter.h:9:0, > > > > from ../src/l2_packet/l2_packet_linux.c:13: > > > > /usr/include/linux/types.h:21:0: note: this is the location of > > > > the > > > > previous definition > > > > #define __bitwise __bitwise__ > > > > > > I think we can just #ifdef them because it's a compatible, if not > > > exactly identical, definition? > > > > Yes, it's compatible. However, I think there could still be conflicts > > adding an #ifdef because in the kernel header those macros are not > > guarded and so it could happen that a file includes "common.h" and > > then includes another local header file that uses <linux/types.h>, > > causing a redefinition warning. > > I guess I'd say you should include it the right way around - after all, > there's already precedent for this (check the git history of these > definitions) Okay then. Maybe we can just: #ifdef __CHECKER__ #define __force __attribute__((force)) #undef __bitwise #define __bitwise __attribute__((bitwise)) #else #define __force +#undef __bitwise #define __bitwise #endif as in the __CHECKER__ case? '__force' is not actually defined in uapi headers and doesn't require this workaround. Beniamino
diff --git a/src/utils/common.h b/src/utils/common.h index 46e96a65b..bc0633484 100644 --- a/src/utils/common.h +++ b/src/utils/common.h @@ -171,18 +171,18 @@ static inline unsigned int wpa_swap_32(unsigned int v) #endif /* __BYTE_ORDER */ #if __BYTE_ORDER == __LITTLE_ENDIAN -#define le_to_host16(n) ((__force u16) (le16) (n)) -#define host_to_le16(n) ((__force le16) (u16) (n)) -#define be_to_host16(n) bswap_16((__force u16) (be16) (n)) -#define host_to_be16(n) ((__force be16) bswap_16((n))) -#define le_to_host32(n) ((__force u32) (le32) (n)) -#define host_to_le32(n) ((__force le32) (u32) (n)) -#define be_to_host32(n) bswap_32((__force u32) (be32) (n)) -#define host_to_be32(n) ((__force be32) bswap_32((n))) -#define le_to_host64(n) ((__force u64) (le64) (n)) -#define host_to_le64(n) ((__force le64) (u64) (n)) -#define be_to_host64(n) bswap_64((__force u64) (be64) (n)) -#define host_to_be64(n) ((__force be64) bswap_64((n))) +#define le_to_host16(n) ((__wpa_force u16) (le16) (n)) +#define host_to_le16(n) ((__wpa_force le16) (u16) (n)) +#define be_to_host16(n) bswap_16((__wpa_force u16) (be16) (n)) +#define host_to_be16(n) ((__wpa_force be16) bswap_16((n))) +#define le_to_host32(n) ((__wpa_force u32) (le32) (n)) +#define host_to_le32(n) ((__wpa_force le32) (u32) (n)) +#define be_to_host32(n) bswap_32((__wpa_force u32) (be32) (n)) +#define host_to_be32(n) ((__wpa_force be32) bswap_32((n))) +#define le_to_host64(n) ((__wpa_force u64) (le64) (n)) +#define host_to_le64(n) ((__wpa_force le64) (u64) (n)) +#define be_to_host64(n) bswap_64((__wpa_force u64) (be64) (n)) +#define host_to_be64(n) ((__wpa_force be64) bswap_64((n))) #elif __BYTE_ORDER == __BIG_ENDIAN #define le_to_host16(n) bswap_16(n) #define host_to_le16(n) bswap_16(n) @@ -430,20 +430,20 @@ void perror(const char *s); * (http://kernel.org/pub/linux/kernel/people/josh/sparse/) */ #ifdef __CHECKER__ -#define __force __attribute__((force)) +#define __wpa_force __attribute__((force)) #undef __bitwise -#define __bitwise __attribute__((bitwise)) +#define __wpa_bitwise __attribute__((bitwise)) #else -#define __force -#define __bitwise +#define __wpa_force +#define __wpa_bitwise #endif -typedef u16 __bitwise be16; -typedef u16 __bitwise le16; -typedef u32 __bitwise be32; -typedef u32 __bitwise le32; -typedef u64 __bitwise be64; -typedef u64 __bitwise le64; +typedef u16 __wpa_bitwise be16; +typedef u16 __wpa_bitwise le16; +typedef u32 __wpa_bitwise be32; +typedef u32 __wpa_bitwise le32; +typedef u64 __wpa_bitwise be64; +typedef u64 __wpa_bitwise le64; #ifndef __must_check #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
Namespace the __bitwise and __force macros so that they don't conflict with the ones from linux/types.h: In file included from ../src/l2_packet/l2_packet_linux.c:15:0: hostap/src/utils/common.h:438:0: warning: "__bitwise" redefined #define __bitwise In file included from /usr/include/linux/filter.h:9:0, from ../src/l2_packet/l2_packet_linux.c:13: /usr/include/linux/types.h:21:0: note: this is the location of the previous definition #define __bitwise __bitwise__ Signed-off-by: Beniamino Galvani <bgalvani@redhat.com> --- src/utils/common.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)