[PATCH v2 07/20] linux/memberof.h: Add memberof(T, m) macro

From: Alejandro Colomar
Date: Sat Nov 20 2021 - 08:01:39 EST


(((T *)0)->m) if a typical construct used by some wrappers,
and also directly in many places.
Write a macro to encapsulate that construct,
and avoid repetition (and possible mistakes).

It also helps readability by reducing the complexity
of mentally parsing so many symbols together,
with a readable name.

Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---
include/linux/memberof.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 include/linux/memberof.h

diff --git a/include/linux/memberof.h b/include/linux/memberof.h
new file mode 100644
index 000000000000..6d8cb3dabbf9
--- /dev/null
+++ b/include/linux/memberof.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_MEMBEROF_H
+#define _LINUX_MEMBEROF_H
+
+
+#include <linux/NULL.h>
+
+
+#define memberof(T, m) (((T *)NULL)->m)
+
+
+#endif /* _LINUX_MEMBEROF_H */
--
2.33.1