From: Allen Pais <allen.lkml@gmail.com>
To: torvalds@linux-foundation.org
Cc: akpm@linux-foundation.org, keescook@chromium.org,
tglx@linutronix.de, linux-kernel@vger.kernel.org,
Allen Pais <allen.lkml@gmail.com>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH] linux/kernel.h: add container_from()
Date: Thu, 27 Aug 2020 07:06:36 +0530 [thread overview]
Message-ID: <20200827013636.149307-1-allen.lkml@gmail.com> (raw)
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
next reply other threads:[~2020-08-27 1:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 1:36 Allen Pais [this message]
2020-08-27 2:31 ` [PATCH] linux/kernel.h: add container_from() 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200827013636.149307-1-allen.lkml@gmail.com \
--to=allen.lkml@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox