summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2021-11-18 18:55:47 +0100
committerAlejandro Colomar <alx.manpages@gmail.com>2021-11-18 21:00:01 +0100
commit28735ed756061b29d790fdd7846a351d379919fa (patch)
tree192d77569443929117891de029dceb6d16c6bc1e
parent42eb8fdac2fc5d62392dcfcf0253753e821a97b0 (diff)
linux/container_of.h: Add memberof(T, m)
Many xxxof_member() macros make use of the same construction to refer to a member of a struct without needing a variable of the struct type. memberof(T, m) simplifies all of those, avoids possible mistakes in repetition, adds a meaningful name to the construction, and improves readability by avoiding too many parentheses together. Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Bjorn Andersson <bjorn.andersson@linaro.org> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Corey Minyard <cminyard@mvista.com> Cc: Christian Brauner <christian.brauner@ubuntu.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Kees Cook <keescook@chromium.org>
-rw-r--r--include/linux/container_of.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 2f4944b791b8..199c78a3bf29 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -5,6 +5,9 @@
#include <linux/build_bug.h>
#include <linux/err.h>
+
+#define memberof(T, m) (((T *) NULL)->m)
+
#define typeof_member(T, m) typeof(((T*)0)->m)
/**