A common usage pattern for offsetof() is the following: offsetof(typeof(*ptr), member)
This is exactly the definition of struct_offset(). Some call sites use offsetofend() instead of offsetof(). Add this variant, then replace all call sites with the corresponding macros. Signed-off-by: Bence Csokas <[email protected]> --- Changes in v4: - Fix more Sashiko issues - Add `virtual patch` to cocci file - Skip tools/ directory - Remove redundant parens - Regen treewide patch with coccicheck - Except arch/arc, as I can't test that - Fix (preexisting) style issues in treewide patch too - Except for CAMELCASE, which cannot be trivially fixed - Link to v3: https://patch.msgid.link/[email protected] Changes in v3: - Add Coccinelle patch to tree instead of just the commit msg - Fix Sashiko issues in prefix, commit msg and doc-comment - Link to v2: https://patch.msgid.link/[email protected] Changes in v2: - Use struct_offset() instead of reinventing it - Rename offsetofendp() to struct_offsetofend() - Merge the two treewide patches - Link to v1: https://patch.msgid.link/[email protected] To: Kees Cook <[email protected]> To: "Gustavo A. R. Silva" <[email protected]> To: Marcel Holtmann <[email protected]> To: Luiz Augusto von Dentz <[email protected]> To: Sumit Semwal <[email protected]> To: Christian König <[email protected]> To: Philipp Stanner <[email protected]> To: Sudeep Holla <[email protected]> To: Cristian Marussi <[email protected]> To: Maarten Lankhorst <[email protected]> To: Maxime Ripard <[email protected]> To: Thomas Zimmermann <[email protected]> To: David Airlie <[email protected]> To: Simona Vetter <[email protected]> To: Jani Nikula <[email protected]> To: Joonas Lahtinen <[email protected]> To: Rodrigo Vivi <[email protected]> To: Tvrtko Ursulin <[email protected]> To: Lyude Paul <[email protected]> To: Danilo Krummrich <[email protected]> To: Zack Rusin <[email protected]> To: Broadcom internal kernel review list <[email protected]> To: Selvin Xavier <[email protected]> To: Kalesh AP <[email protected]> To: Jason Gunthorpe <[email protected]> To: Leon Romanovsky <[email protected]> To: Chengchang Tang <[email protected]> To: Junxian Huang <[email protected]> To: Laurent Pinchart <[email protected]> To: Hans de Goede <[email protected]> To: Mauro Carvalho Chehab <[email protected]> To: Haiyang Zhang <[email protected]> To: Wei Liu <[email protected]> To: Dexuan Cui <[email protected]> To: Andrew Lunn <[email protected]> To: "David S. Miller" <[email protected]> To: Eric Dumazet <[email protected]> To: Jakub Kicinski <[email protected]> To: Paolo Abeni <[email protected]> To: Miri Korenblit <[email protected]> To: Jes Sorensen <[email protected]> To: Ping-Ke Shih <[email protected]> To: Johannes Berg <[email protected]> To: Benson Leung <[email protected]> To: Tzung-Bi Shih <[email protected]> To: Guenter Roeck <[email protected]> To: Nilesh Javali <[email protected]> To: [email protected] To: "James E.J. Bottomley" <[email protected]> To: "Martin K. Petersen" <[email protected]> To: Julia Lawall <[email protected]> To: Nicolas Palix <[email protected]> To: Alexander Viro <[email protected]> To: Christian Brauner <[email protected]> To: Jan Kara <[email protected]> To: Paulo Alcantara <[email protected]> To: Namjae Jeon <[email protected]> To: Ronnie Sahlberg <[email protected]> To: Shyam Prasad N <[email protected]> To: Tom Talpey <[email protected]> To: Bharath SM <[email protected]> To: Carlos Maiolino <[email protected]> To: Thomas Gleixner <[email protected]> To: Ingo Molnar <[email protected]> To: Peter Zijlstra <[email protected]> To: Darren Hart <[email protected]> To: Davidlohr Bueso <[email protected]> To: André Almeida <[email protected]> To: Alexei Starovoitov <[email protected]> To: Daniel Borkmann <[email protected]> To: Andrii Nakryiko <[email protected]> To: Eduard Zingerman <[email protected]> To: Kumar Kartikeya Dwivedi <[email protected]> To: Martin KaFai Lau <[email protected]> To: Song Liu <[email protected]> To: Yonghong Song <[email protected]> To: Jiri Olsa <[email protected]> To: Emil Tsalapatis <[email protected]> To: Ihor Solodrai <[email protected]> To: Simon Horman <[email protected]> To: David Ahern <[email protected]> To: Ido Schimmel <[email protected]> To: Willem de Bruijn <[email protected]> To: Steffen Klassert <[email protected]> To: Herbert Xu <[email protected]> To: Mickaël Salaün <[email protected]> To: Günther Noack <[email protected]> To: Paul Moore <[email protected]> To: James Morris <[email protected]> To: "Serge E. Hallyn" <[email protected]> To: "Geoffrey D. Bennett" <[email protected]> To: Jaroslav Kysela <[email protected]> To: Takashi Iwai <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] --- Bence Csokas (2): overflow: Add offsetofend() variant of struct_offset() treewide: Use struct_offset() drivers/bluetooth/btmrvl_main.c | 12 +++++----- drivers/dma-buf/dma-resv.c | 2 +- drivers/firmware/arm_scmi/base.c | 2 +- drivers/gpu/drm/drm_edid.c | 28 ++++++++++++---------- drivers/gpu/drm/i915/gem/i915_gem_object.c | 4 ++-- drivers/gpu/drm/i915/i915_active.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence_work.c | 2 +- .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 12 +++++----- drivers/infiniband/hw/bnxt_re/qplib_fp.c | 2 +- drivers/infiniband/hw/hns/hns_roce_cq.c | 4 ++-- drivers/infiniband/hw/hns/hns_roce_qp.c | 6 ++--- drivers/media/usb/uvc/uvc_v4l2.c | 4 ++-- drivers/net/hyperv/rndis_filter.c | 2 +- drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/rs-fw.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/rs.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c | 5 ++-- drivers/net/wireless/realtek/rtl8xxxu/core.c | 2 +- drivers/net/wireless/realtek/rtw88/fw.c | 2 +- drivers/net/wireless/realtek/rtw89/core.c | 2 +- drivers/net/wireless/realtek/rtw89/fw.c | 8 +++---- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 4 ++-- drivers/platform/chrome/cros_ec_lightbar.c | 4 ++-- drivers/scsi/qla2xxx/qla_gs.c | 2 +- drivers/scsi/qla2xxx/qla_mbx.c | 2 +- drivers/scsi/qla2xxx/qla_os.c | 2 +- drivers/scsi/qla2xxx/qla_tmpl.c | 4 ++-- drivers/scsi/scsi_transport_fc.c | 2 +- fs/readdir.c | 2 +- fs/smb/client/cifssmb.c | 4 ++-- fs/smb/client/reparse.c | 3 ++- fs/xfs/scrub/attr.c | 4 ++-- fs/xfs/scrub/attr_repair.c | 4 ++-- fs/xfs/scrub/dir.c | 4 ++-- fs/xfs/scrub/dir_repair.c | 4 ++-- include/linux/overflow.h | 12 ++++++++++ kernel/futex/core.c | 3 ++- net/bpf/test_run.c | 2 +- net/ipv4/ip_output.c | 4 ++-- net/ipv4/udp.c | 4 ++-- net/ipv6/udp.c | 4 ++-- net/key/af_key.c | 2 +- net/mac80211/agg-rx.c | 3 +-- net/mac80211/agg-tx.c | 3 +-- net/mac80211/parse.c | 2 +- net/mac80211/tdls.c | 4 ++-- net/wireless/nl80211.c | 2 +- net/wireless/reg.c | 2 +- net/wireless/scan.c | 2 +- scripts/coccinelle/api/struct_offsetof.cocci | 18 ++++++++++++++ security/landlock/net.c | 4 ++-- sound/usb/mixer_scarlett2.c | 2 +- 53 files changed, 129 insertions(+), 98 deletions(-) --- base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca change-id: 20261105-offsetof-f62aa6348f0d Best regards, -- Bence Csokas <[email protected]>
