mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-23 04:04:33 +08:00
btrfs-progs: kerncompat: update definition of container_of
Copy linux.git/include/linux/container_of.h definition of container_of and the const variant (currently unused) Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
a5b7e414da
commit
957b614088
@ -456,9 +456,39 @@ do { \
|
||||
|
||||
#define IS_ENABLED(c) 0
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
/* Are two types/vars the same type (ignoring qualifiers)? */
|
||||
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
|
||||
|
||||
#define typeof_member(T, m) typeof(((T*)0)->m)
|
||||
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
* WARNING: any const qualifier of @ptr is lost.
|
||||
*/
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
void *__mptr = (void *)(ptr); \
|
||||
static_assert(__same_type(*(ptr), ((type *)0)->member) || \
|
||||
__same_type(*(ptr), void), \
|
||||
"pointer type mismatch in container_of()"); \
|
||||
((type *)(__mptr - offsetof(type, member))); })
|
||||
|
||||
/**
|
||||
* container_of_const - cast a member of a structure out to the containing
|
||||
* structure and preserve the const-ness of the pointer
|
||||
* @ptr: the pointer to the member
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*/
|
||||
#define container_of_const(ptr, type, member) \
|
||||
_Generic(ptr, \
|
||||
const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\
|
||||
default: ((type *)container_of(ptr, type, member)) \
|
||||
)
|
||||
|
||||
#ifndef __bitwise
|
||||
#ifdef __CHECKER__
|
||||
#define __bitwise __bitwise__
|
||||
|
Loading…
Reference in New Issue
Block a user