All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Alejandro Colomar <alx.manpages@gmail.com>,
	Ajit Khaparde <ajit.khaparde@broadcom.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Borislav Petkov <bp@suse.de>, Corey Minyard <cminyard@mvista.com>,
	Chris Mason <clm@fb.com>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	David Sterba <dsterba@suse.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Jason Wang <jasowang@redhat.com>,
	Jitendra Bhivare <jitendra.bhivare@broadcom.com>,
	John Hubbard <jhubbard@nvidia.com>,
	"John S . Gruber" <JohnSGruber@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Josef Bacik <josef@toxicpanda.com>,
	Kees Cook <keescook@chromium.org>,
	Ketan Mukadam <ketan.mukadam@broadcom.com>,
	Len Brown <lenb@kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Russell King <linux@armlinux.org.uk>,
	Somnath Kotur <somnath.kotur@broadcom.com>,
	Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>,
	Subbu Seetharaman <subbu.seetharaman@broadcom.com>,
	intel-gfx@lists.freedesktop.org, linux-acpi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-btrfs@vger.kernel.org, linux-scsi@vger.kernel.org,
	netdev@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH 02/17] Use memberof(T, m) instead of explicit NULL dereference
Date: Fri, 19 Nov 2021 12:36:30 +0100	[thread overview]
Message-ID: <20211119113644.1600-3-alx.manpages@gmail.com> (raw)
In-Reply-To: <20211119113644.1600-1-alx.manpages@gmail.com>

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Cc: Ajit Khaparde <ajit.khaparde@broadcom.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: Corey Minyard <cminyard@mvista.com>
Cc: Chris Mason <clm@fb.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: David Sterba <dsterba@suse.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jitendra Bhivare <jitendra.bhivare@broadcom.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: John S. Gruber <JohnSGruber@gmail.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Ketan Mukadam <ketan.mukadam@broadcom.com>
Cc: Len Brown <lenb@kernel.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Somnath Kotur <somnath.kotur@broadcom.com>
Cc: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Cc: Subbu Seetharaman <subbu.seetharaman@broadcom.com>
Cc: <intel-gfx@lists.freedesktop.org>
Cc: <linux-acpi@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-btrfs@vger.kernel.org>
Cc: <linux-scsi@vger.kernel.org>
Cc: <netdev@vger.kernel.org>
Cc: <virtualization@lists.linux-foundation.org>
---
 arch/x86/include/asm/bootparam_utils.h  |  3 ++-
 arch/x86/kernel/signal_compat.c         |  5 +++--
 drivers/gpu/drm/i915/i915_utils.h       |  5 ++---
 drivers/gpu/drm/i915/intel_runtime_pm.h |  2 +-
 drivers/net/ethernet/emulex/benet/be.h  |  7 ++++---
 drivers/net/ethernet/i825xx/ether1.c    |  7 +++++--
 drivers/scsi/be2iscsi/be.h              |  7 ++++---
 drivers/scsi/be2iscsi/be_cmds.h         |  5 ++++-
 fs/btrfs/ctree.h                        |  5 +++--
 include/acpi/actypes.h                  |  4 +++-
 include/linux/container_of.h            |  6 +++---
 include/linux/virtio_config.h           | 14 +++++++-------
 12 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/arch/x86/include/asm/bootparam_utils.h b/arch/x86/include/asm/bootparam_utils.h
index 981fe923a59f..71b28b5fb088 100644
--- a/arch/x86/include/asm/bootparam_utils.h
+++ b/arch/x86/include/asm/bootparam_utils.h
@@ -3,6 +3,7 @@
 #define _ASM_X86_BOOTPARAM_UTILS_H
 
 #include <asm/bootparam.h>
+#include <linux/container_of.h>
 
 /*
  * This file is included from multiple environments.  Do not
@@ -19,7 +20,7 @@
  * private magic, so it is better to leave it unchanged.
  */
 
-#define sizeof_mbr(type, member) ({ sizeof(((type *)0)->member); })
+#define sizeof_mbr(type, member) ({ sizeof(memberof(type, member)); })
 
 #define BOOT_PARAM_PRESERVE(struct_member)				\
 	{								\
diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index b52407c56000..28420a7df056 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/compat.h>
+#include <linux/container_of.h>
 #include <linux/uaccess.h>
 #include <linux/ptrace.h>
 
@@ -69,8 +70,8 @@ static inline void signal_compat_build_tests(void)
 	 * structure stays within the padding size (checked
 	 * above).
 	 */
-#define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((compat_siginfo_t *)0)->_sifields.name))
-#define CHECK_SI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((siginfo_t *)0)->_sifields.name))
+#define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(memberof(compat_siginfo_t ,_sifields.name)))
+#define CHECK_SI_SIZE(name, size)  BUILD_BUG_ON(size != sizeof(memberof(siginfo_t, _sifields.name)))
 
 	CHECK_CSI_OFFSET(_kill);
 	CHECK_CSI_SIZE  (_kill, 2*sizeof(int));
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 7a5925072466..2e3ec28f4f1b 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -25,6 +25,7 @@
 #ifndef __I915_UTILS_H
 #define __I915_UTILS_H
 
+#include <linux/container_of.h>
 #include <linux/list.h>
 #include <linux/overflow.h>
 #include <linux/sched.h>
@@ -192,8 +193,6 @@ __check_struct_size(size_t base, size_t arr, size_t count, size_t *size)
 #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
 #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
 
-#define struct_member(T, member) (((T *)0)->member)
-
 #define ptr_offset(ptr, member) offsetof(typeof(*(ptr)), member)
 
 #define fetch_and_zero(ptr) ({						\
@@ -215,7 +214,7 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
  */
 #define container_of_user(ptr, type, member) ({				\
 	void __user *__mptr = (void __user *)(ptr);			\
-	BUILD_BUG_ON_MSG(!__same_type(*(ptr), struct_member(type, member)) && \
+	BUILD_BUG_ON_MSG(!__same_type(*(ptr), memberof(type, member)) && \
 			 !__same_type(*(ptr), void),			\
 			 "pointer type mismatch in container_of()");	\
 	((type __user *)(__mptr - offsetof(type, member))); })
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.h b/drivers/gpu/drm/i915/intel_runtime_pm.h
index 47a85fab4130..6cb04bef62ad 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.h
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.h
@@ -73,7 +73,7 @@ struct intel_runtime_pm {
 };
 
 #define BITS_PER_WAKEREF	\
-	BITS_PER_TYPE(struct_member(struct intel_runtime_pm, wakeref_count))
+	BITS_PER_TYPE(memberof(struct intel_runtime_pm, wakeref_count))
 #define INTEL_RPM_WAKELOCK_SHIFT	(BITS_PER_WAKEREF / 2)
 #define INTEL_RPM_WAKELOCK_BIAS		(1 << INTEL_RPM_WAKELOCK_SHIFT)
 #define INTEL_RPM_RAW_WAKEREF_MASK	(INTEL_RPM_WAKELOCK_BIAS - 1)
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index 8689d4a51fe5..dc790bae2451 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -14,6 +14,7 @@
 #ifndef BE_H
 #define BE_H
 
+#include <linux/container_of.h>
 #include <linux/pci.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
@@ -824,7 +825,7 @@ extern const struct ethtool_ops be_ethtool_ops;
 
 /* Returns bit offset within a DWORD of a bitfield */
 #define AMAP_BIT_OFFSET(_struct, field)  				\
-		(((size_t)&(((_struct *)0)->field))%32)
+		(((size_t)&(memberof(_struct, field)))%32)
 
 /* Returns the bit mask of the field that is NOT shifted into location. */
 static inline u32 amap_mask(u32 bitsize)
@@ -843,7 +844,7 @@ amap_set(void *ptr, u32 dw_offset, u32 mask, u32 offset, u32 value)
 #define AMAP_SET_BITS(_struct, field, ptr, val)				\
 		amap_set(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field),		\
 			val)
 
@@ -856,7 +857,7 @@ static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
 #define AMAP_GET_BITS(_struct, field, ptr)				\
 		amap_get(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field))
 
 #define GET_RX_COMPL_V0_BITS(field, ptr)				\
diff --git a/drivers/net/ethernet/i825xx/ether1.c b/drivers/net/ethernet/i825xx/ether1.c
index c612ef526d16..4dece3476d31 100644
--- a/drivers/net/ethernet/i825xx/ether1.c
+++ b/drivers/net/ethernet/i825xx/ether1.c
@@ -28,6 +28,7 @@
  * 1.07	RMK	13/05/2000	Updated for 2.3.99-pre8
  */
 
+#include <linux/containerof.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -80,8 +81,10 @@ static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
 #define DISABLEIRQS 1
 #define NORMALIRQS  0
 
-#define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
-#define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
+#define ether1_readw(dev, addr, type, offset, svflgs) \
+	ether1_inw_p(dev, addr + (int)(&(memberof(type, offset))), svflgs)
+#define ether1_writew(dev, val, addr, type, offset, svflgs) \
+	ether1_outw_p(dev, val, addr + (int)(&(memberof(type, offset))), svflgs)
 
 static inline unsigned short
 ether1_inw_p (struct net_device *dev, int addr, int svflgs)
diff --git a/drivers/scsi/be2iscsi/be.h b/drivers/scsi/be2iscsi/be.h
index 4c58a02590c7..6830e07fd37a 100644
--- a/drivers/scsi/be2iscsi/be.h
+++ b/drivers/scsi/be2iscsi/be.h
@@ -10,6 +10,7 @@
 #ifndef BEISCSI_H
 #define BEISCSI_H
 
+#include <linux/container_of.h>
 #include <linux/pci.h>
 #include <linux/if_vlan.h>
 #include <linux/irq_poll.h>
@@ -153,7 +154,7 @@ struct be_ctrl_info {
 
 /* Returns bit offset within a DWORD of a bitfield */
 #define AMAP_BIT_OFFSET(_struct, field)					\
-		(((size_t)&(((_struct *)0)->field))%32)
+		(((size_t)&(memberof(_struct, field)))%32)
 
 /* Returns the bit mask of the field that is NOT shifted into location. */
 static inline u32 amap_mask(u32 bitsize)
@@ -172,7 +173,7 @@ static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
 #define AMAP_SET_BITS(_struct, field, ptr, val)				\
 		amap_set(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field),		\
 			val)
 
@@ -185,7 +186,7 @@ static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
 #define AMAP_GET_BITS(_struct, field, ptr)				\
 		amap_get(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field))
 
 #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
diff --git a/drivers/scsi/be2iscsi/be_cmds.h b/drivers/scsi/be2iscsi/be_cmds.h
index 5f9f0b18ddf3..bb6ee43769d5 100644
--- a/drivers/scsi/be2iscsi/be_cmds.h
+++ b/drivers/scsi/be2iscsi/be_cmds.h
@@ -10,6 +10,9 @@
 #ifndef BEISCSI_CMDS_H
 #define BEISCSI_CMDS_H
 
+
+#include <linux/container_of.h>
+
 /**
  * The driver sends configuration and managements command requests to the
  * firmware in the BE. These requests are communicated to the processor
@@ -1300,7 +1303,7 @@ struct be_cmd_get_port_name {
 
 /* Returns the number of items in the field array. */
 #define BE_NUMBER_OF_FIELD(_type_, _field_)	\
-	(sizeof_field(_type_, _field_)/sizeof((((_type_ *)0)->_field_[0])))\
+	(sizeof_field(_type_, _field_) / sizeof(memberof(_type_, _field_[0])))
 
 /**
  * Different types of iSCSI completions to host driver for both initiator
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7553e9dc5f93..442b6f937b22 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -6,6 +6,7 @@
 #ifndef BTRFS_CTREE_H
 #define BTRFS_CTREE_H
 
+#include <linux/container_of.h>
 #include <linux/mm.h>
 #include <linux/sched/signal.h>
 #include <linux/highmem.h>
@@ -1575,13 +1576,13 @@ static inline void put_unaligned_le8(u8 val, void *p)
 	read_extent_buffer(eb, (char *)(result),			\
 			   ((unsigned long)(ptr)) +			\
 			    offsetof(type, member),			\
-			   sizeof(((type *)0)->member)))
+			   sizeof(memberof(type, member))))
 
 #define write_eb_member(eb, ptr, type, member, result) (\
 	write_extent_buffer(eb, (char *)(result),			\
 			   ((unsigned long)(ptr)) +			\
 			    offsetof(type, member),			\
-			   sizeof(((type *)0)->member)))
+			   sizeof(memberof(type, member))))
 
 #define DECLARE_BTRFS_SETGET_BITS(bits)					\
 u##bits btrfs_get_token_##bits(struct btrfs_map_token *token,		\
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index ff8b3c913f21..c3b0eccb3377 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -10,6 +10,8 @@
 #ifndef __ACTYPES_H__
 #define __ACTYPES_H__
 
+#include <linux/container_of.h>
+
 /* acpisrc:struct_defs -- for acpisrc conversion */
 
 /*
@@ -508,7 +510,7 @@ typedef u64 acpi_integer;
 
 #define ACPI_TO_POINTER(i)              ACPI_CAST_PTR (void, (acpi_size) (i))
 #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p, (void *) 0)
-#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
+#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(memberof(d, f)), (void *) 0)
 #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
 #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
 
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 199c78a3bf29..227418cb8c99 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -8,7 +8,7 @@
 
 #define memberof(T, m)   (((T *) NULL)->m)
 
-#define typeof_member(T, m)	typeof(((T*)0)->m)
+#define typeof_member(T, m)	typeof(memberof(T, m))
 
 /**
  * container_of - cast a member of a structure out to the containing structure
@@ -19,7 +19,7 @@
  */
 #define container_of(ptr, type, member) ({				\
 	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+	static_assert(__same_type(*(ptr), memberof(type, member)) ||	\
 		      __same_type(*(ptr), void),			\
 		      "pointer type mismatch in container_of()");	\
 	((type *)(__mptr - offsetof(type, member))); })
@@ -34,7 +34,7 @@
  */
 #define container_of_safe(ptr, type, member) ({				\
 	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+	static_assert(__same_type(*(ptr), memberof(type, member)) ||	\
 		      __same_type(*(ptr), void),			\
 		      "pointer type mismatch in container_of_safe()");	\
 	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 4d107ad31149..a1e656c0d94a 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -328,12 +328,12 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 		)
 
 #define __virtio_native_type(structname, member) \
-	typeof(virtio_to_cpu(NULL, ((structname*)0)->member))
+	typeof(virtio_to_cpu(NULL, memberof(structname, member)))
 
 /* Config space accessors. */
 #define virtio_cread(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cread_v;	\
+		typeof(memberof(structname, member)) virtio_cread_v;	\
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -362,8 +362,8 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 /* Config space accessors. */
 #define virtio_cwrite(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cwrite_v =	\
-			cpu_to_virtio(vdev, *(ptr), ((structname*)0)->member); \
+		typeof(memberof(structname, member)) virtio_cwrite_v =	\
+			cpu_to_virtio(vdev, *(ptr), memberof(structname, member)); \
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -397,7 +397,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 /* LE (e.g. modern) Config space accessors. */
 #define virtio_cread_le(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cread_v;	\
+		typeof(memberof(structname, member)) virtio_cread_v;	\
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -425,8 +425,8 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 
 #define virtio_cwrite_le(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cwrite_v =	\
-			virtio_cpu_to_le(*(ptr), ((structname*)0)->member); \
+		typeof(memberof(structname, member)) virtio_cwrite_v =	\
+			virtio_cpu_to_le(*(ptr), memberof(structname, member)); \
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
-- 
2.33.1


WARNING: multiple messages have this Message-ID (diff)
From: Alejandro Colomar <alx.manpages@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Alejandro Colomar <alx.manpages@gmail.com>,
	Ajit Khaparde <ajit.khaparde@broadcom.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Borislav Petkov <bp@suse.de>, Corey Minyard <cminyard@mvista.com>,
	Chris Mason <clm@fb.com>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	David Sterba <dsterba@suse.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Jason Wang <jasowang@redhat.com>,
	Jitendra Bhivare <jitendra.bhivare@broadcom.com>,
	John Hubbard <jhubbard@nvidia.com>,
	"John S . Gruber" <JohnSGruber@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Josef Bacik <josef@toxicpanda.com>,
	Kees Cook <keescook@chromium.org>,
	Ketan Mukadam <ketan.mukadam@broadcom.com>,
	Len Brown <lenb@kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Russell King <linux@armlinux.org.uk>,
	Somnath Kotur <somnath.kotur@broadcom.com>,
	Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>,
	Subbu Seetharaman <subbu.seetharaman@broadcom.com>,
	intel-gfx@lists.freedesktop.org, linux-acpi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-btrfs@vger.kernel.org, linux-scsi@vger.kernel.org,
	netdev@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH 02/17] Use memberof(T, m) instead of explicit NULL dereference
Date: Fri, 19 Nov 2021 12:36:30 +0100	[thread overview]
Message-ID: <20211119113644.1600-3-alx.manpages@gmail.com> (raw)
In-Reply-To: <20211119113644.1600-1-alx.manpages@gmail.com>

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Cc: Ajit Khaparde <ajit.khaparde@broadcom.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: Corey Minyard <cminyard@mvista.com>
Cc: Chris Mason <clm@fb.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: David Sterba <dsterba@suse.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jitendra Bhivare <jitendra.bhivare@broadcom.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: John S. Gruber <JohnSGruber@gmail.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Ketan Mukadam <ketan.mukadam@broadcom.com>
Cc: Len Brown <lenb@kernel.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Somnath Kotur <somnath.kotur@broadcom.com>
Cc: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Cc: Subbu Seetharaman <subbu.seetharaman@broadcom.com>
Cc: <intel-gfx@lists.freedesktop.org>
Cc: <linux-acpi@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-btrfs@vger.kernel.org>
Cc: <linux-scsi@vger.kernel.org>
Cc: <netdev@vger.kernel.org>
Cc: <virtualization@lists.linux-foundation.org>
---
 arch/x86/include/asm/bootparam_utils.h  |  3 ++-
 arch/x86/kernel/signal_compat.c         |  5 +++--
 drivers/gpu/drm/i915/i915_utils.h       |  5 ++---
 drivers/gpu/drm/i915/intel_runtime_pm.h |  2 +-
 drivers/net/ethernet/emulex/benet/be.h  |  7 ++++---
 drivers/net/ethernet/i825xx/ether1.c    |  7 +++++--
 drivers/scsi/be2iscsi/be.h              |  7 ++++---
 drivers/scsi/be2iscsi/be_cmds.h         |  5 ++++-
 fs/btrfs/ctree.h                        |  5 +++--
 include/acpi/actypes.h                  |  4 +++-
 include/linux/container_of.h            |  6 +++---
 include/linux/virtio_config.h           | 14 +++++++-------
 12 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/arch/x86/include/asm/bootparam_utils.h b/arch/x86/include/asm/bootparam_utils.h
index 981fe923a59f..71b28b5fb088 100644
--- a/arch/x86/include/asm/bootparam_utils.h
+++ b/arch/x86/include/asm/bootparam_utils.h
@@ -3,6 +3,7 @@
 #define _ASM_X86_BOOTPARAM_UTILS_H
 
 #include <asm/bootparam.h>
+#include <linux/container_of.h>
 
 /*
  * This file is included from multiple environments.  Do not
@@ -19,7 +20,7 @@
  * private magic, so it is better to leave it unchanged.
  */
 
-#define sizeof_mbr(type, member) ({ sizeof(((type *)0)->member); })
+#define sizeof_mbr(type, member) ({ sizeof(memberof(type, member)); })
 
 #define BOOT_PARAM_PRESERVE(struct_member)				\
 	{								\
diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index b52407c56000..28420a7df056 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/compat.h>
+#include <linux/container_of.h>
 #include <linux/uaccess.h>
 #include <linux/ptrace.h>
 
@@ -69,8 +70,8 @@ static inline void signal_compat_build_tests(void)
 	 * structure stays within the padding size (checked
 	 * above).
 	 */
-#define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((compat_siginfo_t *)0)->_sifields.name))
-#define CHECK_SI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((siginfo_t *)0)->_sifields.name))
+#define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(memberof(compat_siginfo_t ,_sifields.name)))
+#define CHECK_SI_SIZE(name, size)  BUILD_BUG_ON(size != sizeof(memberof(siginfo_t, _sifields.name)))
 
 	CHECK_CSI_OFFSET(_kill);
 	CHECK_CSI_SIZE  (_kill, 2*sizeof(int));
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 7a5925072466..2e3ec28f4f1b 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -25,6 +25,7 @@
 #ifndef __I915_UTILS_H
 #define __I915_UTILS_H
 
+#include <linux/container_of.h>
 #include <linux/list.h>
 #include <linux/overflow.h>
 #include <linux/sched.h>
@@ -192,8 +193,6 @@ __check_struct_size(size_t base, size_t arr, size_t count, size_t *size)
 #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
 #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
 
-#define struct_member(T, member) (((T *)0)->member)
-
 #define ptr_offset(ptr, member) offsetof(typeof(*(ptr)), member)
 
 #define fetch_and_zero(ptr) ({						\
@@ -215,7 +214,7 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
  */
 #define container_of_user(ptr, type, member) ({				\
 	void __user *__mptr = (void __user *)(ptr);			\
-	BUILD_BUG_ON_MSG(!__same_type(*(ptr), struct_member(type, member)) && \
+	BUILD_BUG_ON_MSG(!__same_type(*(ptr), memberof(type, member)) && \
 			 !__same_type(*(ptr), void),			\
 			 "pointer type mismatch in container_of()");	\
 	((type __user *)(__mptr - offsetof(type, member))); })
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.h b/drivers/gpu/drm/i915/intel_runtime_pm.h
index 47a85fab4130..6cb04bef62ad 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.h
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.h
@@ -73,7 +73,7 @@ struct intel_runtime_pm {
 };
 
 #define BITS_PER_WAKEREF	\
-	BITS_PER_TYPE(struct_member(struct intel_runtime_pm, wakeref_count))
+	BITS_PER_TYPE(memberof(struct intel_runtime_pm, wakeref_count))
 #define INTEL_RPM_WAKELOCK_SHIFT	(BITS_PER_WAKEREF / 2)
 #define INTEL_RPM_WAKELOCK_BIAS		(1 << INTEL_RPM_WAKELOCK_SHIFT)
 #define INTEL_RPM_RAW_WAKEREF_MASK	(INTEL_RPM_WAKELOCK_BIAS - 1)
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index 8689d4a51fe5..dc790bae2451 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -14,6 +14,7 @@
 #ifndef BE_H
 #define BE_H
 
+#include <linux/container_of.h>
 #include <linux/pci.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
@@ -824,7 +825,7 @@ extern const struct ethtool_ops be_ethtool_ops;
 
 /* Returns bit offset within a DWORD of a bitfield */
 #define AMAP_BIT_OFFSET(_struct, field)  				\
-		(((size_t)&(((_struct *)0)->field))%32)
+		(((size_t)&(memberof(_struct, field)))%32)
 
 /* Returns the bit mask of the field that is NOT shifted into location. */
 static inline u32 amap_mask(u32 bitsize)
@@ -843,7 +844,7 @@ amap_set(void *ptr, u32 dw_offset, u32 mask, u32 offset, u32 value)
 #define AMAP_SET_BITS(_struct, field, ptr, val)				\
 		amap_set(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field),		\
 			val)
 
@@ -856,7 +857,7 @@ static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
 #define AMAP_GET_BITS(_struct, field, ptr)				\
 		amap_get(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field))
 
 #define GET_RX_COMPL_V0_BITS(field, ptr)				\
diff --git a/drivers/net/ethernet/i825xx/ether1.c b/drivers/net/ethernet/i825xx/ether1.c
index c612ef526d16..4dece3476d31 100644
--- a/drivers/net/ethernet/i825xx/ether1.c
+++ b/drivers/net/ethernet/i825xx/ether1.c
@@ -28,6 +28,7 @@
  * 1.07	RMK	13/05/2000	Updated for 2.3.99-pre8
  */
 
+#include <linux/containerof.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -80,8 +81,10 @@ static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
 #define DISABLEIRQS 1
 #define NORMALIRQS  0
 
-#define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
-#define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
+#define ether1_readw(dev, addr, type, offset, svflgs) \
+	ether1_inw_p(dev, addr + (int)(&(memberof(type, offset))), svflgs)
+#define ether1_writew(dev, val, addr, type, offset, svflgs) \
+	ether1_outw_p(dev, val, addr + (int)(&(memberof(type, offset))), svflgs)
 
 static inline unsigned short
 ether1_inw_p (struct net_device *dev, int addr, int svflgs)
diff --git a/drivers/scsi/be2iscsi/be.h b/drivers/scsi/be2iscsi/be.h
index 4c58a02590c7..6830e07fd37a 100644
--- a/drivers/scsi/be2iscsi/be.h
+++ b/drivers/scsi/be2iscsi/be.h
@@ -10,6 +10,7 @@
 #ifndef BEISCSI_H
 #define BEISCSI_H
 
+#include <linux/container_of.h>
 #include <linux/pci.h>
 #include <linux/if_vlan.h>
 #include <linux/irq_poll.h>
@@ -153,7 +154,7 @@ struct be_ctrl_info {
 
 /* Returns bit offset within a DWORD of a bitfield */
 #define AMAP_BIT_OFFSET(_struct, field)					\
-		(((size_t)&(((_struct *)0)->field))%32)
+		(((size_t)&(memberof(_struct, field)))%32)
 
 /* Returns the bit mask of the field that is NOT shifted into location. */
 static inline u32 amap_mask(u32 bitsize)
@@ -172,7 +173,7 @@ static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
 #define AMAP_SET_BITS(_struct, field, ptr, val)				\
 		amap_set(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field),		\
 			val)
 
@@ -185,7 +186,7 @@ static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
 #define AMAP_GET_BITS(_struct, field, ptr)				\
 		amap_get(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field))
 
 #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
diff --git a/drivers/scsi/be2iscsi/be_cmds.h b/drivers/scsi/be2iscsi/be_cmds.h
index 5f9f0b18ddf3..bb6ee43769d5 100644
--- a/drivers/scsi/be2iscsi/be_cmds.h
+++ b/drivers/scsi/be2iscsi/be_cmds.h
@@ -10,6 +10,9 @@
 #ifndef BEISCSI_CMDS_H
 #define BEISCSI_CMDS_H
 
+
+#include <linux/container_of.h>
+
 /**
  * The driver sends configuration and managements command requests to the
  * firmware in the BE. These requests are communicated to the processor
@@ -1300,7 +1303,7 @@ struct be_cmd_get_port_name {
 
 /* Returns the number of items in the field array. */
 #define BE_NUMBER_OF_FIELD(_type_, _field_)	\
-	(sizeof_field(_type_, _field_)/sizeof((((_type_ *)0)->_field_[0])))\
+	(sizeof_field(_type_, _field_) / sizeof(memberof(_type_, _field_[0])))
 
 /**
  * Different types of iSCSI completions to host driver for both initiator
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7553e9dc5f93..442b6f937b22 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -6,6 +6,7 @@
 #ifndef BTRFS_CTREE_H
 #define BTRFS_CTREE_H
 
+#include <linux/container_of.h>
 #include <linux/mm.h>
 #include <linux/sched/signal.h>
 #include <linux/highmem.h>
@@ -1575,13 +1576,13 @@ static inline void put_unaligned_le8(u8 val, void *p)
 	read_extent_buffer(eb, (char *)(result),			\
 			   ((unsigned long)(ptr)) +			\
 			    offsetof(type, member),			\
-			   sizeof(((type *)0)->member)))
+			   sizeof(memberof(type, member))))
 
 #define write_eb_member(eb, ptr, type, member, result) (\
 	write_extent_buffer(eb, (char *)(result),			\
 			   ((unsigned long)(ptr)) +			\
 			    offsetof(type, member),			\
-			   sizeof(((type *)0)->member)))
+			   sizeof(memberof(type, member))))
 
 #define DECLARE_BTRFS_SETGET_BITS(bits)					\
 u##bits btrfs_get_token_##bits(struct btrfs_map_token *token,		\
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index ff8b3c913f21..c3b0eccb3377 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -10,6 +10,8 @@
 #ifndef __ACTYPES_H__
 #define __ACTYPES_H__
 
+#include <linux/container_of.h>
+
 /* acpisrc:struct_defs -- for acpisrc conversion */
 
 /*
@@ -508,7 +510,7 @@ typedef u64 acpi_integer;
 
 #define ACPI_TO_POINTER(i)              ACPI_CAST_PTR (void, (acpi_size) (i))
 #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p, (void *) 0)
-#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
+#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(memberof(d, f)), (void *) 0)
 #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
 #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
 
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 199c78a3bf29..227418cb8c99 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -8,7 +8,7 @@
 
 #define memberof(T, m)   (((T *) NULL)->m)
 
-#define typeof_member(T, m)	typeof(((T*)0)->m)
+#define typeof_member(T, m)	typeof(memberof(T, m))
 
 /**
  * container_of - cast a member of a structure out to the containing structure
@@ -19,7 +19,7 @@
  */
 #define container_of(ptr, type, member) ({				\
 	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+	static_assert(__same_type(*(ptr), memberof(type, member)) ||	\
 		      __same_type(*(ptr), void),			\
 		      "pointer type mismatch in container_of()");	\
 	((type *)(__mptr - offsetof(type, member))); })
@@ -34,7 +34,7 @@
  */
 #define container_of_safe(ptr, type, member) ({				\
 	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+	static_assert(__same_type(*(ptr), memberof(type, member)) ||	\
 		      __same_type(*(ptr), void),			\
 		      "pointer type mismatch in container_of_safe()");	\
 	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 4d107ad31149..a1e656c0d94a 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -328,12 +328,12 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 		)
 
 #define __virtio_native_type(structname, member) \
-	typeof(virtio_to_cpu(NULL, ((structname*)0)->member))
+	typeof(virtio_to_cpu(NULL, memberof(structname, member)))
 
 /* Config space accessors. */
 #define virtio_cread(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cread_v;	\
+		typeof(memberof(structname, member)) virtio_cread_v;	\
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -362,8 +362,8 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 /* Config space accessors. */
 #define virtio_cwrite(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cwrite_v =	\
-			cpu_to_virtio(vdev, *(ptr), ((structname*)0)->member); \
+		typeof(memberof(structname, member)) virtio_cwrite_v =	\
+			cpu_to_virtio(vdev, *(ptr), memberof(structname, member)); \
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -397,7 +397,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 /* LE (e.g. modern) Config space accessors. */
 #define virtio_cread_le(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cread_v;	\
+		typeof(memberof(structname, member)) virtio_cread_v;	\
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -425,8 +425,8 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 
 #define virtio_cwrite_le(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cwrite_v =	\
-			virtio_cpu_to_le(*(ptr), ((structname*)0)->member); \
+		typeof(memberof(structname, member)) virtio_cwrite_v =	\
+			virtio_cpu_to_le(*(ptr), memberof(structname, member)); \
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
-- 
2.33.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Alejandro Colomar <alx.manpages@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Alejandro Colomar <alx.manpages@gmail.com>,
	Corey Minyard <cminyard@mvista.com>,
	Ajit Khaparde <ajit.khaparde@broadcom.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Chris Mason <clm@fb.com>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Ketan Mukadam <ketan.mukadam@broadcom.com>,
	Somnath Kotur <somnath.kotur@broadcom.com>,
	linux-scsi@vger.kernel.org,
	Subbu Seetharaman <subbu.seetharaman@broadcom.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Mike Rapoport <rppt@linux.ibm.com>,
	linux-acpi@vger.kernel.org, Miguel Ojeda <ojeda@kernel.org>,
	Borislav Petkov <bp@suse.de>,
	virtualization@lists.linux-foundation.org,
	Len Brown <lenb@kernel.org>, Kees Cook <keescook@chromium.org>,
	Arnd Bergmann <arnd@arndb.de>, John Hubbard <jhubbard@nvidia.com>,
	intel-gfx@lists.freedesktop.org,
	Josef Bacik <josef@toxicpanda.com>,
	Jitendra Bhivare <jitendra.bhivare@broadcom.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	David Sterba <dsterba@suse.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-arm-kernel@lists.infradead.org,
	Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>,
	netdev@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	"John S . Gruber" <JohnSGruber@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-btrfs@vger.kernel.org
Subject: [Intel-gfx] [PATCH 02/17] Use memberof(T, m) instead of explicit NULL dereference
Date: Fri, 19 Nov 2021 12:36:30 +0100	[thread overview]
Message-ID: <20211119113644.1600-3-alx.manpages@gmail.com> (raw)
In-Reply-To: <20211119113644.1600-1-alx.manpages@gmail.com>

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Cc: Ajit Khaparde <ajit.khaparde@broadcom.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: Corey Minyard <cminyard@mvista.com>
Cc: Chris Mason <clm@fb.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: David Sterba <dsterba@suse.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jitendra Bhivare <jitendra.bhivare@broadcom.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: John S. Gruber <JohnSGruber@gmail.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Ketan Mukadam <ketan.mukadam@broadcom.com>
Cc: Len Brown <lenb@kernel.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Somnath Kotur <somnath.kotur@broadcom.com>
Cc: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Cc: Subbu Seetharaman <subbu.seetharaman@broadcom.com>
Cc: <intel-gfx@lists.freedesktop.org>
Cc: <linux-acpi@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-btrfs@vger.kernel.org>
Cc: <linux-scsi@vger.kernel.org>
Cc: <netdev@vger.kernel.org>
Cc: <virtualization@lists.linux-foundation.org>
---
 arch/x86/include/asm/bootparam_utils.h  |  3 ++-
 arch/x86/kernel/signal_compat.c         |  5 +++--
 drivers/gpu/drm/i915/i915_utils.h       |  5 ++---
 drivers/gpu/drm/i915/intel_runtime_pm.h |  2 +-
 drivers/net/ethernet/emulex/benet/be.h  |  7 ++++---
 drivers/net/ethernet/i825xx/ether1.c    |  7 +++++--
 drivers/scsi/be2iscsi/be.h              |  7 ++++---
 drivers/scsi/be2iscsi/be_cmds.h         |  5 ++++-
 fs/btrfs/ctree.h                        |  5 +++--
 include/acpi/actypes.h                  |  4 +++-
 include/linux/container_of.h            |  6 +++---
 include/linux/virtio_config.h           | 14 +++++++-------
 12 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/arch/x86/include/asm/bootparam_utils.h b/arch/x86/include/asm/bootparam_utils.h
index 981fe923a59f..71b28b5fb088 100644
--- a/arch/x86/include/asm/bootparam_utils.h
+++ b/arch/x86/include/asm/bootparam_utils.h
@@ -3,6 +3,7 @@
 #define _ASM_X86_BOOTPARAM_UTILS_H
 
 #include <asm/bootparam.h>
+#include <linux/container_of.h>
 
 /*
  * This file is included from multiple environments.  Do not
@@ -19,7 +20,7 @@
  * private magic, so it is better to leave it unchanged.
  */
 
-#define sizeof_mbr(type, member) ({ sizeof(((type *)0)->member); })
+#define sizeof_mbr(type, member) ({ sizeof(memberof(type, member)); })
 
 #define BOOT_PARAM_PRESERVE(struct_member)				\
 	{								\
diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index b52407c56000..28420a7df056 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/compat.h>
+#include <linux/container_of.h>
 #include <linux/uaccess.h>
 #include <linux/ptrace.h>
 
@@ -69,8 +70,8 @@ static inline void signal_compat_build_tests(void)
 	 * structure stays within the padding size (checked
 	 * above).
 	 */
-#define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((compat_siginfo_t *)0)->_sifields.name))
-#define CHECK_SI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((siginfo_t *)0)->_sifields.name))
+#define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(memberof(compat_siginfo_t ,_sifields.name)))
+#define CHECK_SI_SIZE(name, size)  BUILD_BUG_ON(size != sizeof(memberof(siginfo_t, _sifields.name)))
 
 	CHECK_CSI_OFFSET(_kill);
 	CHECK_CSI_SIZE  (_kill, 2*sizeof(int));
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 7a5925072466..2e3ec28f4f1b 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -25,6 +25,7 @@
 #ifndef __I915_UTILS_H
 #define __I915_UTILS_H
 
+#include <linux/container_of.h>
 #include <linux/list.h>
 #include <linux/overflow.h>
 #include <linux/sched.h>
@@ -192,8 +193,6 @@ __check_struct_size(size_t base, size_t arr, size_t count, size_t *size)
 #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
 #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
 
-#define struct_member(T, member) (((T *)0)->member)
-
 #define ptr_offset(ptr, member) offsetof(typeof(*(ptr)), member)
 
 #define fetch_and_zero(ptr) ({						\
@@ -215,7 +214,7 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
  */
 #define container_of_user(ptr, type, member) ({				\
 	void __user *__mptr = (void __user *)(ptr);			\
-	BUILD_BUG_ON_MSG(!__same_type(*(ptr), struct_member(type, member)) && \
+	BUILD_BUG_ON_MSG(!__same_type(*(ptr), memberof(type, member)) && \
 			 !__same_type(*(ptr), void),			\
 			 "pointer type mismatch in container_of()");	\
 	((type __user *)(__mptr - offsetof(type, member))); })
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.h b/drivers/gpu/drm/i915/intel_runtime_pm.h
index 47a85fab4130..6cb04bef62ad 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.h
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.h
@@ -73,7 +73,7 @@ struct intel_runtime_pm {
 };
 
 #define BITS_PER_WAKEREF	\
-	BITS_PER_TYPE(struct_member(struct intel_runtime_pm, wakeref_count))
+	BITS_PER_TYPE(memberof(struct intel_runtime_pm, wakeref_count))
 #define INTEL_RPM_WAKELOCK_SHIFT	(BITS_PER_WAKEREF / 2)
 #define INTEL_RPM_WAKELOCK_BIAS		(1 << INTEL_RPM_WAKELOCK_SHIFT)
 #define INTEL_RPM_RAW_WAKEREF_MASK	(INTEL_RPM_WAKELOCK_BIAS - 1)
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index 8689d4a51fe5..dc790bae2451 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -14,6 +14,7 @@
 #ifndef BE_H
 #define BE_H
 
+#include <linux/container_of.h>
 #include <linux/pci.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
@@ -824,7 +825,7 @@ extern const struct ethtool_ops be_ethtool_ops;
 
 /* Returns bit offset within a DWORD of a bitfield */
 #define AMAP_BIT_OFFSET(_struct, field)  				\
-		(((size_t)&(((_struct *)0)->field))%32)
+		(((size_t)&(memberof(_struct, field)))%32)
 
 /* Returns the bit mask of the field that is NOT shifted into location. */
 static inline u32 amap_mask(u32 bitsize)
@@ -843,7 +844,7 @@ amap_set(void *ptr, u32 dw_offset, u32 mask, u32 offset, u32 value)
 #define AMAP_SET_BITS(_struct, field, ptr, val)				\
 		amap_set(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field),		\
 			val)
 
@@ -856,7 +857,7 @@ static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
 #define AMAP_GET_BITS(_struct, field, ptr)				\
 		amap_get(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field))
 
 #define GET_RX_COMPL_V0_BITS(field, ptr)				\
diff --git a/drivers/net/ethernet/i825xx/ether1.c b/drivers/net/ethernet/i825xx/ether1.c
index c612ef526d16..4dece3476d31 100644
--- a/drivers/net/ethernet/i825xx/ether1.c
+++ b/drivers/net/ethernet/i825xx/ether1.c
@@ -28,6 +28,7 @@
  * 1.07	RMK	13/05/2000	Updated for 2.3.99-pre8
  */
 
+#include <linux/containerof.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -80,8 +81,10 @@ static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
 #define DISABLEIRQS 1
 #define NORMALIRQS  0
 
-#define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
-#define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
+#define ether1_readw(dev, addr, type, offset, svflgs) \
+	ether1_inw_p(dev, addr + (int)(&(memberof(type, offset))), svflgs)
+#define ether1_writew(dev, val, addr, type, offset, svflgs) \
+	ether1_outw_p(dev, val, addr + (int)(&(memberof(type, offset))), svflgs)
 
 static inline unsigned short
 ether1_inw_p (struct net_device *dev, int addr, int svflgs)
diff --git a/drivers/scsi/be2iscsi/be.h b/drivers/scsi/be2iscsi/be.h
index 4c58a02590c7..6830e07fd37a 100644
--- a/drivers/scsi/be2iscsi/be.h
+++ b/drivers/scsi/be2iscsi/be.h
@@ -10,6 +10,7 @@
 #ifndef BEISCSI_H
 #define BEISCSI_H
 
+#include <linux/container_of.h>
 #include <linux/pci.h>
 #include <linux/if_vlan.h>
 #include <linux/irq_poll.h>
@@ -153,7 +154,7 @@ struct be_ctrl_info {
 
 /* Returns bit offset within a DWORD of a bitfield */
 #define AMAP_BIT_OFFSET(_struct, field)					\
-		(((size_t)&(((_struct *)0)->field))%32)
+		(((size_t)&(memberof(_struct, field)))%32)
 
 /* Returns the bit mask of the field that is NOT shifted into location. */
 static inline u32 amap_mask(u32 bitsize)
@@ -172,7 +173,7 @@ static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
 #define AMAP_SET_BITS(_struct, field, ptr, val)				\
 		amap_set(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field),		\
 			val)
 
@@ -185,7 +186,7 @@ static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
 #define AMAP_GET_BITS(_struct, field, ptr)				\
 		amap_get(ptr,						\
 			offsetof(_struct, field)/32,			\
-			amap_mask(sizeof(((_struct *)0)->field)),	\
+			amap_mask(sizeof(memberof(_struct, field))),	\
 			AMAP_BIT_OFFSET(_struct, field))
 
 #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
diff --git a/drivers/scsi/be2iscsi/be_cmds.h b/drivers/scsi/be2iscsi/be_cmds.h
index 5f9f0b18ddf3..bb6ee43769d5 100644
--- a/drivers/scsi/be2iscsi/be_cmds.h
+++ b/drivers/scsi/be2iscsi/be_cmds.h
@@ -10,6 +10,9 @@
 #ifndef BEISCSI_CMDS_H
 #define BEISCSI_CMDS_H
 
+
+#include <linux/container_of.h>
+
 /**
  * The driver sends configuration and managements command requests to the
  * firmware in the BE. These requests are communicated to the processor
@@ -1300,7 +1303,7 @@ struct be_cmd_get_port_name {
 
 /* Returns the number of items in the field array. */
 #define BE_NUMBER_OF_FIELD(_type_, _field_)	\
-	(sizeof_field(_type_, _field_)/sizeof((((_type_ *)0)->_field_[0])))\
+	(sizeof_field(_type_, _field_) / sizeof(memberof(_type_, _field_[0])))
 
 /**
  * Different types of iSCSI completions to host driver for both initiator
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7553e9dc5f93..442b6f937b22 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -6,6 +6,7 @@
 #ifndef BTRFS_CTREE_H
 #define BTRFS_CTREE_H
 
+#include <linux/container_of.h>
 #include <linux/mm.h>
 #include <linux/sched/signal.h>
 #include <linux/highmem.h>
@@ -1575,13 +1576,13 @@ static inline void put_unaligned_le8(u8 val, void *p)
 	read_extent_buffer(eb, (char *)(result),			\
 			   ((unsigned long)(ptr)) +			\
 			    offsetof(type, member),			\
-			   sizeof(((type *)0)->member)))
+			   sizeof(memberof(type, member))))
 
 #define write_eb_member(eb, ptr, type, member, result) (\
 	write_extent_buffer(eb, (char *)(result),			\
 			   ((unsigned long)(ptr)) +			\
 			    offsetof(type, member),			\
-			   sizeof(((type *)0)->member)))
+			   sizeof(memberof(type, member))))
 
 #define DECLARE_BTRFS_SETGET_BITS(bits)					\
 u##bits btrfs_get_token_##bits(struct btrfs_map_token *token,		\
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index ff8b3c913f21..c3b0eccb3377 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -10,6 +10,8 @@
 #ifndef __ACTYPES_H__
 #define __ACTYPES_H__
 
+#include <linux/container_of.h>
+
 /* acpisrc:struct_defs -- for acpisrc conversion */
 
 /*
@@ -508,7 +510,7 @@ typedef u64 acpi_integer;
 
 #define ACPI_TO_POINTER(i)              ACPI_CAST_PTR (void, (acpi_size) (i))
 #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p, (void *) 0)
-#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
+#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(memberof(d, f)), (void *) 0)
 #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
 #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
 
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 199c78a3bf29..227418cb8c99 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -8,7 +8,7 @@
 
 #define memberof(T, m)   (((T *) NULL)->m)
 
-#define typeof_member(T, m)	typeof(((T*)0)->m)
+#define typeof_member(T, m)	typeof(memberof(T, m))
 
 /**
  * container_of - cast a member of a structure out to the containing structure
@@ -19,7 +19,7 @@
  */
 #define container_of(ptr, type, member) ({				\
 	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+	static_assert(__same_type(*(ptr), memberof(type, member)) ||	\
 		      __same_type(*(ptr), void),			\
 		      "pointer type mismatch in container_of()");	\
 	((type *)(__mptr - offsetof(type, member))); })
@@ -34,7 +34,7 @@
  */
 #define container_of_safe(ptr, type, member) ({				\
 	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+	static_assert(__same_type(*(ptr), memberof(type, member)) ||	\
 		      __same_type(*(ptr), void),			\
 		      "pointer type mismatch in container_of_safe()");	\
 	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 4d107ad31149..a1e656c0d94a 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -328,12 +328,12 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 		)
 
 #define __virtio_native_type(structname, member) \
-	typeof(virtio_to_cpu(NULL, ((structname*)0)->member))
+	typeof(virtio_to_cpu(NULL, memberof(structname, member)))
 
 /* Config space accessors. */
 #define virtio_cread(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cread_v;	\
+		typeof(memberof(structname, member)) virtio_cread_v;	\
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -362,8 +362,8 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 /* Config space accessors. */
 #define virtio_cwrite(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cwrite_v =	\
-			cpu_to_virtio(vdev, *(ptr), ((structname*)0)->member); \
+		typeof(memberof(structname, member)) virtio_cwrite_v =	\
+			cpu_to_virtio(vdev, *(ptr), memberof(structname, member)); \
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -397,7 +397,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 /* LE (e.g. modern) Config space accessors. */
 #define virtio_cread_le(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cread_v;	\
+		typeof(memberof(structname, member)) virtio_cread_v;	\
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
@@ -425,8 +425,8 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
 
 #define virtio_cwrite_le(vdev, structname, member, ptr)			\
 	do {								\
-		typeof(((structname*)0)->member) virtio_cwrite_v =	\
-			virtio_cpu_to_le(*(ptr), ((structname*)0)->member); \
+		typeof(memberof(structname, member)) virtio_cwrite_v =	\
+			virtio_cpu_to_le(*(ptr), memberof(structname, member)); \
 									\
 		might_sleep();						\
 		/* Sanity check: must match the member's type */	\
-- 
2.33.1


  parent reply	other threads:[~2021-11-19 11:37 UTC|newest]

Thread overview: 144+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 11:36 [PATCH 00/17] Add memberof(), split some headers, and slightly simplify code Alejandro Colomar
2021-11-19 11:36 ` [Intel-gfx] " Alejandro Colomar
2021-11-19 11:36 ` Alejandro Colomar
2021-11-19 11:36 ` [PATCH 01/17] linux/container_of.h: Add memberof(T, m) Alejandro Colomar
2021-11-19 11:36 ` Alejandro Colomar [this message]
2021-11-19 11:36   ` [Intel-gfx] [PATCH 02/17] Use memberof(T, m) instead of explicit NULL dereference Alejandro Colomar
2021-11-19 11:36   ` Alejandro Colomar
2021-11-23 18:07   ` Rafael J. Wysocki
2021-11-23 18:07     ` Rafael J. Wysocki
2021-11-23 18:07     ` [Intel-gfx] " Rafael J. Wysocki
2021-11-23 18:07     ` Rafael J. Wysocki
2021-11-19 11:36 ` [PATCH 03/17] Replace some uses of memberof() by its wrappers Alejandro Colomar
2021-11-19 11:36 ` [PATCH 04/17] linux/memberof.h: Move memberof() to separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 05/17] linux/typeof_member.h: Move typeof_member() to a " Alejandro Colomar
2021-11-19 11:36 ` [PATCH 06/17] Simplify sizeof(typeof_member()) to sizeof_field() Alejandro Colomar
2021-11-19 11:36 ` [PATCH 07/17] linux/NULL.h: Move NULL to a separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 08/17] linux/offsetof.h: Move offsetof(T, m) " Alejandro Colomar
2021-11-19 11:36 ` [PATCH 09/17] linux/offsetof.h: Implement offsetof() in terms of memberof() Alejandro Colomar
2021-11-19 11:36 ` [PATCH 10/17] linux/container_of.h: Implement container_of_safe() in terms of container_of() Alejandro Colomar
2021-11-19 11:36 ` [PATCH 11/17] linux/container_of.h: Cosmetic Alejandro Colomar
2021-11-19 11:36 ` [PATCH 12/17] linux/container_of.h: Remove unnecessary cast to (void *) Alejandro Colomar
2021-11-19 11:36 ` [PATCH 13/17] linux/sizeof_field.h: Move sizeof_field(T, m) to a separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 14/17] include/linux/: Include a smaller header if just for NULL Alejandro Colomar
2021-11-19 11:36 ` [PATCH 15/17] linux/offsetofend.h: Move offsetofend(T, m) to a separate header Alejandro Colomar
2021-11-19 11:36 ` [PATCH 16/17] linux/array_size.h: Move ARRAY_SIZE(arr) " Alejandro Colomar
2021-11-19 11:36 ` [PATCH 17/17] include/: Include <linux/array_size.h> for ARRAY_SIZE() Alejandro Colomar
2021-11-19 12:47 ` [PATCH 00/17] Add memberof(), split some headers, and slightly simplify code Jani Nikula
2021-11-19 12:47   ` Jani Nikula
2021-11-19 12:47   ` [Intel-gfx] " Jani Nikula
2021-11-19 12:47   ` Jani Nikula
2021-11-19 13:16   ` Alejandro Colomar (man-pages)
2021-11-19 13:16     ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 13:16     ` Alejandro Colomar (man-pages)
2021-11-19 13:48     ` Jani Nikula
2021-11-19 13:48       ` Jani Nikula
2021-11-19 13:48       ` [Intel-gfx] " Jani Nikula
2021-11-19 13:48       ` Jani Nikula
2021-11-19 14:54     ` Andy Shevchenko
2021-11-19 14:54       ` Andy Shevchenko
2021-11-19 14:54       ` [Intel-gfx] " Andy Shevchenko
2021-11-19 14:54       ` Andy Shevchenko
2021-11-19 14:47 ` Arnd Bergmann
2021-11-19 14:47   ` [Intel-gfx] " Arnd Bergmann
2021-11-19 14:47   ` Arnd Bergmann
2021-11-19 14:47   ` Arnd Bergmann
2021-11-19 15:06   ` Alejandro Colomar (man-pages)
2021-11-19 15:06     ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 15:06     ` Alejandro Colomar (man-pages)
2021-11-19 15:34     ` Andy Shevchenko
2021-11-19 15:34       ` Andy Shevchenko
2021-11-19 15:34       ` [Intel-gfx] " Andy Shevchenko
2021-11-19 15:34       ` Andy Shevchenko
2021-11-19 15:38       ` Alejandro Colomar (man-pages)
2021-11-19 15:38         ` Alejandro Colomar (man-pages)
2021-11-19 15:38         ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 15:43         ` Alejandro Colomar (man-pages)
2021-11-19 15:49           ` Andy Shevchenko
2021-11-19 15:52             ` Alejandro Colomar (man-pages)
2021-11-19 16:07               ` Andy Shevchenko
2021-11-19 15:57     ` Arnd Bergmann
2021-11-19 15:57       ` [Intel-gfx] " Arnd Bergmann
2021-11-19 15:57       ` Arnd Bergmann
2021-11-19 15:57       ` Arnd Bergmann
2021-11-19 16:10       ` Andy Shevchenko
2021-11-19 16:10         ` Andy Shevchenko
2021-11-19 16:10         ` Andy Shevchenko
2021-11-19 16:10         ` [Intel-gfx] " Andy Shevchenko
2021-11-19 16:18         ` Arnd Bergmann
2021-11-19 16:18           ` Arnd Bergmann
2021-11-19 16:18           ` [Intel-gfx] " Arnd Bergmann
2021-11-19 16:18           ` Arnd Bergmann
2021-11-19 16:22           ` Alejandro Colomar (man-pages)
2021-11-19 16:22             ` Alejandro Colomar (man-pages)
2021-11-19 16:22             ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 16:27             ` Arnd Bergmann
2021-11-19 16:27               ` Arnd Bergmann
2021-11-19 16:27               ` [Intel-gfx] " Arnd Bergmann
2021-11-19 16:27               ` Arnd Bergmann
2021-11-19 16:35             ` Andy Shevchenko
2021-11-19 16:35               ` Andy Shevchenko
2021-11-19 16:35               ` [Intel-gfx] " Andy Shevchenko
2021-11-19 16:35               ` Andy Shevchenko
2021-11-22 12:36               ` Jonathan Cameron
2021-11-22 12:36                 ` [Intel-gfx] " Jonathan Cameron
2021-11-22 12:36                 ` Jonathan Cameron
2021-11-19 16:12       ` Alejandro Colomar (man-pages)
2021-11-19 16:12         ` Alejandro Colomar (man-pages)
2021-11-19 16:12         ` [Intel-gfx] " Alejandro Colomar (man-pages)
2021-11-19 16:25         ` Arnd Bergmann
2021-11-19 16:25           ` Arnd Bergmann
2021-11-19 16:25           ` Arnd Bergmann
2021-11-19 16:25           ` [Intel-gfx] " Arnd Bergmann
2021-11-19 16:37         ` Andy Shevchenko
2021-11-19 16:37           ` Andy Shevchenko
2021-11-19 16:37           ` [Intel-gfx] " Andy Shevchenko
2021-11-19 16:37           ` Andy Shevchenko
2021-11-19 16:49           ` Alejandro Colomar (man-pages)
2021-11-20 13:00 ` [PATCH v2 00/20] Add memberof(), split headers, and " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 01/20] linux/stddef.h, linux/offsetof.h: Split offsetof() into a separate header Alejandro Colomar
2021-11-20 16:14     ` Andy Shevchenko
2021-11-20 16:22       ` Alejandro Colomar (man-pages)
2021-11-20 13:00   ` [PATCH v2 02/20] linux/stddef.h, linux/sizeof_field.h: Split sizeof_field() " Alejandro Colomar
2021-11-20 16:16     ` Andy Shevchenko
2021-11-20 13:00   ` [PATCH v2 03/20] linux/stddef.h, linux/offsetofend.h: Split offsetofend() " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 04/20] linux/stddef.h, linux/NULL.h: Split NULL " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 05/20] linux/container_of.h, linux/typeof_member.h: Split typeof_member() " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 06/20] linux/kernel.h, linux/array_size.h: Split ARRAY_SIZE() " Alejandro Colomar
2021-11-22  7:36     ` kernel test robot
2021-11-22  7:36       ` kernel test robot
2021-11-20 13:00   ` [PATCH v2 07/20] linux/memberof.h: Add memberof(T, m) macro Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 08/20] Implement container_of_safe() in terms of container_of() Alejandro Colomar
2021-11-21 13:31     ` Arnd Bergmann
2021-11-20 13:00   ` [PATCH v2 09/20] Implement offsetof(), sizeof_member(), typeof_member(), and container_of() in terms of memberof() Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 10/20] linux/container_of.h: Remove unnecessary cast Alejandro Colomar
2021-11-20 19:05     ` kernel test robot
2021-11-20 19:05       ` kernel test robot
2021-11-22 17:39     ` kernel test robot
2021-11-22 17:39       ` kernel test robot
2021-11-20 13:00   ` [PATCH v2 11/20] linux/container_of.h: Cosmetic Alejandro Colomar
2021-11-20 16:12     ` Andy Shevchenko
2021-11-20 16:33       ` Joe Perches
2021-11-20 16:44         ` Alejandro Colomar (man-pages)
2021-11-20 13:00   ` [PATCH v2 12/20] linux/must_be.h: Add must_be() to improve readability of BUILD_BUG_ON_ZERO() Alejandro Colomar
2021-11-20 15:05     ` Alexey Dobriyan
2021-11-20 15:22       ` Alejandro Colomar (man-pages)
2021-11-21 13:18       ` Arnd Bergmann
2021-11-20 13:00   ` [PATCH v2 13/20] Move BUILD_BUG_ON_ZERO to <linux/must_be.h> Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 13/20] linux/build_bug.h, linux/must_be.h: " Alejandro Colomar
2021-11-20 13:00   ` [PATCH v2 14/20] linux/compiler_types.h, linux/same_type.h: Split __same_type() to a separate header Alejandro Colomar
2021-11-21 13:26     ` Arnd Bergmann
2021-11-20 13:00   ` [PATCH v2 15/20] linux/compiler.h: Implement __must_be_array() in terms of __must_be() Alejandro Colomar
2021-11-21 13:25     ` Arnd Bergmann
2021-11-20 13:01   ` [PATCH v2 16/20] linux/compiler.h, linux/array_size.h: Move __must_be_array() into <linux/array_size.h> Alejandro Colomar
2021-11-21 13:24     ` Arnd Bergmann
2021-11-22  8:51       ` Jani Nikula
2021-11-20 13:01   ` [PATCH v2 17/20] linux/array_size.h: Add __is_array(a) to help readability Alejandro Colomar
2021-11-21 13:22     ` Arnd Bergmann
2021-11-20 13:01   ` [PATCH v2 18/20] linux/power_of_2.h: Add __IS_POWER_OF_2(n) and __IS_POWER_OF_2_OR_0(n) macros Alejandro Colomar
2021-11-21 13:20     ` Arnd Bergmann
2021-11-22  8:55       ` Jani Nikula
2021-11-20 13:01   ` [PATCH v2 19/20] linux/build_bug.h, linux/power_of_2.h: Move [__]BUILD_BUG_ON_NOT_POWER_OF_2() to <linux/power_of_2.h> Alejandro Colomar
2021-11-20 13:01   ` [PATCH v2 20/20] linux/power_of_2.h: Implement [__]BUILD_BUG_ON_NOT_POWER_OF_2() in terms of __IS_POWER_OF_2[_OR_0]() Alejandro Colomar
2021-11-22 11:17   ` [PATCH v2 00/20] Add memberof(), split headers, and simplify code Andy Shevchenko
2021-11-22 12:07     ` Alejandro Colomar (man-pages)

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=20211119113644.1600-3-alx.manpages@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=JohnSGruber@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=bjorn.andersson@linaro.org \
    --cc=bp@suse.de \
    --cc=christian.brauner@ubuntu.com \
    --cc=clm@fb.com \
    --cc=cminyard@mvista.com \
    --cc=dsterba@suse.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jasowang@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=jitendra.bhivare@broadcom.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=josef@toxicpanda.com \
    --cc=keescook@chromium.org \
    --cc=ketan.mukadam@broadcom.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mst@redhat.com \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=rppt@linux.ibm.com \
    --cc=somnath.kotur@broadcom.com \
    --cc=sriharsha.basavapatna@broadcom.com \
    --cc=subbu.seetharaman@broadcom.com \
    --cc=virtualization@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.