XenevaOS
Loading...
Searching...
No Matches
container_of.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_CONTAINER_OF_H
3#define _LINUX_CONTAINER_OF_H
4
5#include <linux/build_bug.h>
6#include <linux/stddef.h>
7
8#define typeof_member(T, m) typeof(((T*)0)->m)
9
19#define container_of(ptr, type, member) ({ \
20 void *__mptr = (void *)(ptr); \
21 static_assert(__same_type(*(ptr), ((type *)0)->member) || \
22 __same_type(*(ptr), void), \
23 "pointer type mismatch in container_of()"); \
24 ((type *)(__mptr - offsetof(type, member))); })
25
35#define container_of_const(ptr, type, member) \
36 _Generic(ptr, \
37 const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\
38 default: ((type *)container_of(ptr, type, member)) \
39 )
40
41#endif /* _LINUX_CONTAINER_OF_H */