list.h: implement type safety for container_of()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
cdb9f71971
commit
009b4d574e
1 changed files with 5 additions and 2 deletions
7
list.h
7
list.h
|
@ -35,8 +35,11 @@
|
|||
#define prefetch(x)
|
||||
|
||||
#ifndef container_of
|
||||
#define container_of(ptr, type, member) ( \
|
||||
(type *)( (char *)ptr - offsetof(type,member) ))
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const typeof(((type *) NULL)->member) *__mptr = (ptr); \
|
||||
(type *) ((char *) __mptr - offsetof(type, member)); \
|
||||
})
|
||||
#endif
|
||||
|
||||
struct list_head {
|
||||
|
|
Loading…
Reference in a new issue