public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux/kernel.h: add container_from()
@ 2020-08-27  1:36 Allen Pais
  2020-08-27  2:31 ` Kees Cook
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Allen Pais @ 2020-08-27  1:36 UTC (permalink / raw)
  To: torvalds
  Cc: akpm, keescook, tglx, linux-kernel, Allen Pais,
	James E . J . Bottomley, Greg Kroah-Hartman, Jens Axboe

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.Bottomley@HansenPartnership.com>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Allen Pais <allen.lkml@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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-08-28  7:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-27  1:36 [PATCH] linux/kernel.h: add container_from() Allen Pais
2020-08-27  2:31 ` Kees Cook
2020-08-27 12:19   ` Greg Kroah-Hartman
2020-08-27 17:50     ` Kees Cook
2020-08-27 18:04 ` Linus Torvalds
2020-08-27 18:32   ` James Bottomley
2020-08-27 18:40     ` Linus Torvalds
2020-08-27 18:48       ` Linus Torvalds
2020-08-27 19:28         ` Kees Cook
2020-08-27 20:46           ` Linus Torvalds
2020-08-27 21:36             ` Al Viro
2020-08-27 22:14               ` Kees Cook
2020-08-28  7:09                 ` Allen
2020-08-28  7:07             ` Allen
2020-08-27 18:07 ` Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox