From 6a96878e0bef47cd705634bd532fc304e884c228 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Fri, 19 Oct 2018 09:20:49 +0300 Subject: [PATCH] dm: types: add container_of macro Add standard container_of macro to access the parent struct pointer. Tracked-On: #1536 Signed-off-by: Tomas Winkler Acked-by: Wang, Yu1 --- devicemodel/include/types.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/devicemodel/include/types.h b/devicemodel/include/types.h index ed442a5e9..d3b2bf4ec 100644 --- a/devicemodel/include/types.h +++ b/devicemodel/include/types.h @@ -18,6 +18,11 @@ typedef uint64_t cap_ioctl_t; #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#define container_of(ptr, type, member) ({ \ + const typeof(((type *)0)->member) * __mptr = (ptr); \ + (type *)((char *)__mptr - (offsetof(type, member))); \ +}) + #define __aligned(x) __attribute__((aligned(x))) #define __section(x) __attribute__((__section__(x))) #define __MAKE_SET(set, sym) \