summaryrefslogtreecommitdiff
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
authorNeil Brown <neilb@cse.unsw.edu.au>2002-07-23 20:40:09 -0700
committerLinus Torvalds <torvalds@home.transmeta.com>2002-07-23 20:40:09 -0700
commitec4f214232cfb99913308c20b9a3381e5fe1f04f (patch)
tree240db31f29876e5f0ac1a59dc9fb27abb9c29a61 /include/linux/kernel.h
parent6f84f62a3c3b45c73180c0886571b2e02773eead (diff)
[PATCH] type safe(r) list_entry repacement: container_of
Define container_of which cast from member to struct with some type checking. This is much like list_entry but is cearly for things other than lists. List_entry now uses container_of.
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2204760615d8..9fe11d9b6dc4 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -150,6 +150,19 @@ extern const char *print_tainted(void);
#define max_t(type,x,y) \
({ type __x = (x); type __y = (y); __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) );})
+
#endif /* __KERNEL__ */
#define SI_LOAD_SHIFT 16