Merge branch 'master' of git://www.denx.de/git/u-boot-sh
[platform/kernel/u-boot.git] / include / common.h
index d0f5704..26e1b46 100644 (file)
@@ -176,6 +176,17 @@ typedef void (interrupt_handler_t)(void *);
                (__x > __y) ? __x : __y; })
 
 
+/**
+ * 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.
+ *
+ */
+#define container_of(ptr, type, member) ({                     \
+       const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+       (type *)( (char *)__mptr - offsetof(type,member) );})
+
 /*
  * Function Prototypes
  */