container_of.h 583 B

123456789101112131415161718
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _TOOLS_LINUX_CONTAINER_OF_H
  3. #define _TOOLS_LINUX_CONTAINER_OF_H
  4. #ifndef container_of
  5. /**
  6. * container_of - cast a member of a structure out to the containing structure
  7. * @ptr: the pointer to the member.
  8. * @type: the type of the container struct this is embedded in.
  9. * @member: the name of the member within the struct.
  10. *
  11. */
  12. #define container_of(ptr, type, member) ({ \
  13. const typeof(((type *)0)->member) * __mptr = (ptr); \
  14. (type *)((char *)__mptr - offsetof(type, member)); })
  15. #endif
  16. #endif /* _TOOLS_LINUX_CONTAINER_OF_H */