Introduce container_from() as a generic helper instead of
sub-systems defining a private from_* API
(Eg: from_tasklets recently introduced in
12cc923f1ccc: Tasklet: Introduce new initialization API)

The helper is similar to container_of() in argument order
with the difference of naming the containing structure instead
of having to specify its type.

Suggested-by: James E.J. Bottomley <james.bottom...@hansenpartnership.com>
Suggested-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Suggested-by: Jens Axboe <ax...@kernel.dk>
Signed-off-by: Allen Pais <allen.l...@gmail.com>
---
 include/linux/kernel.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 500def620d8f..9d446324a8be 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1019,6 +1019,15 @@ static inline void ftrace_dump(enum ftrace_dump_mode 
oops_dump_mode) { }
                         "pointer type mismatch in container_of()");    \
        IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :                     \
                ((type *)(__mptr - offsetof(type, member))); })
+/**
+ * container_from - cast a member of a structure out to the containing 
structure
+ * @ptr:       the pointer to the member.
+ * @container: the type of the container struct.
+ * @member:    the name of the member within the struct.
+ *
+ */
+#define container_from(ptr, container, member) \
+       container_of(ptr, typeof(*container), member)
 
 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
-- 
2.25.1

Reply via email to