list.h: implement type safety for container_of()

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2013-03-18 05:54:44 +01:00
parent cdb9f71971
commit 009b4d574e

7
list.h
View file

@ -35,8 +35,11 @@
#define prefetch(x) #define prefetch(x)
#ifndef container_of #ifndef container_of
#define container_of(ptr, type, member) ( \ #define container_of(ptr, type, member) \
(type *)( (char *)ptr - offsetof(type,member) )) ({ \
const typeof(((type *) NULL)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member)); \
})
#endif #endif
struct list_head { struct list_head {