Skip to content

Commit 6a96878

Browse files
Tomas Winklerwenlingz
authored andcommitted
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 <tomas.winkler@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
1 parent 4e057c3 commit 6a96878

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

devicemodel/include/types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ typedef uint64_t cap_ioctl_t;
1818

1919
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
2020

21+
#define container_of(ptr, type, member) ({ \
22+
const typeof(((type *)0)->member) * __mptr = (ptr); \
23+
(type *)((char *)__mptr - (offsetof(type, member))); \
24+
})
25+
2126
#define __aligned(x) __attribute__((aligned(x)))
2227
#define __section(x) __attribute__((__section__(x)))
2328
#define __MAKE_SET(set, sym) \

0 commit comments

Comments
 (0)