[PATCH 01/17] linux/container_of.h: Add memberof(T, m)

From: Alejandro Colomar
Date: Fri Nov 19 2021 - 06:37:17 EST

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@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Cc: Miguel Ojeda <ojeda@xxxxxxxxxx>
Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
Cc: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
Cc: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
Cc: Bjorn Andersson <bjorn.andersson@xxxxxxxxxx>
Cc: Mike Rapoport <rppt@xxxxxxxxxxxxx>
Cc: Corey Minyard <cminyard@xxxxxxxxxx>
Cc: Christian Brauner <christian.brauner@xxxxxxxxxx>
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
include/linux/container_of.h | 3 +++
1 file changed, 3 insertions(+)

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)