1 #ifndef COMMON_H 2 #define COMMON_H 3 4 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 5 6 #ifndef offsetof 7 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 8 #endif 9 10 /** 11 * container_of - cast a member of a structure out to the containing structure 12 * @ptr: the pointer to the member. 13 * @type: the type of the container struct this is embedded in. 14 * @member: the name of the member within the struct. 15 * 16 */ 17 #define container_of(ptr, type, member) ({ \ 18 const typeof(((type *)0)->member) * __mptr = (ptr); \ 19 (type *)((char *)__mptr - offsetof(type, member)); }) 20 21 #define UNUSED(var) {(void)var;} 22 23 #endif /*COMMON_H*/ 24