[PATCH 09/17] linux/offsetof.h: Implement offsetof() in terms of memberof()

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


Use memberof() instead of explicitly dereferencing a null pointer.

Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---
include/linux/offsetof.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/offsetof.h b/include/linux/offsetof.h
index d0e2f1c34aae..809aed37ad29 100644
--- a/include/linux/offsetof.h
+++ b/include/linux/offsetof.h
@@ -3,13 +3,14 @@
#define _LINUX_OFFSETOF_H

#include <linux/compiler_types.h>
+#include <linux/memberof.h>


#undef offsetof
#ifdef __compiler_offsetof
#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
#else
-#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
+#define offsetof(TYPE, MEMBER) ((size_t)&memberof(TYPE, MEMBER))
#endif


--
2.33.1