Message ID | 20170424133108.31595-4-alexander@alemayhu.com |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
On 04/24/2017 03:31 PM, Alexander Alemayhu wrote: > Fixes the following warning > > samples/bpf/test_lru_dist.c:28:0: warning: "offsetof" redefined > #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) > > In file included from ./tools/lib/bpf/bpf.h:25:0, > from samples/bpf/libbpf.h:5, > from samples/bpf/test_lru_dist.c:24: > /usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/stddef.h:417:0: note: this is the location of the previous definition > #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) > > Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
From: Daniel Borkmann > Sent: 24 April 2017 15:41 > To: Alexander Alemayhu; netdev@vger.kernel.org > Cc: ast@fb.com > Subject: Re: [PATCH net-next 3/3] samples/bpf: check before defining offsetof > > On 04/24/2017 03:31 PM, Alexander Alemayhu wrote: > > Fixes the following warning > > > > samples/bpf/test_lru_dist.c:28:0: warning: "offsetof" redefined > > #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) > > > > In file included from ./tools/lib/bpf/bpf.h:25:0, > > from samples/bpf/libbpf.h:5, > > from samples/bpf/test_lru_dist.c:24: > > /usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/stddef.h:417:0: note: this is the location of the > previous definition > > #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) > > > > Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com> > > Acked-by: Daniel Borkmann <daniel@iogearbox.net> Isn't the correct fix to include stddef.h ? David
On Tue, Apr 25, 2017 at 02:27:16PM +0000, David Laight wrote: > > Isn't the correct fix to include stddef.h ? > If you think it's the correct fix, please send a patch to netdev. Thanks.
diff --git a/samples/bpf/test_lru_dist.c b/samples/bpf/test_lru_dist.c index d96dc88d3b04..73c357142268 100644 --- a/samples/bpf/test_lru_dist.c +++ b/samples/bpf/test_lru_dist.c @@ -25,7 +25,9 @@ #include "bpf_util.h" #define min(a, b) ((a) < (b) ? (a) : (b)) -#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) +#ifndef offsetof +# define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) +#endif #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})
Fixes the following warning samples/bpf/test_lru_dist.c:28:0: warning: "offsetof" redefined #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) In file included from ./tools/lib/bpf/bpf.h:25:0, from samples/bpf/libbpf.h:5, from samples/bpf/test_lru_dist.c:24: /usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/stddef.h:417:0: note: this is the location of the previous definition #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com> --- samples/bpf/test_lru_dist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)