[PATCH v4 0/2] Add struct_offsetofend() for pointer arithmetic
From: Bence Csokas
Date: Wed Nov 18 2026 - 06:56:25 EST
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 <bence.csokas@xxxxxxx>
---
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/20261113-offsetof-v3-0-714df7053893@xxxxxxx
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/20261112-offsetof-v2-0-276ede839967@xxxxxxx
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/20261105-offsetof-v1-0-4153f5c10edc@xxxxxxx
To: Kees Cook <kees@xxxxxxxxxx>
To: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>
To: Marcel Holtmann <marcel@xxxxxxxxxxxx>
To: Luiz Augusto von Dentz <luiz.dentz@xxxxxxxxx>
To: Sumit Semwal <sumit.semwal@xxxxxxxxxx>
To: Christian König <christian.koenig@xxxxxxx>
To: Philipp Stanner <phasta@xxxxxxxxxx>
To: Sudeep Holla <sudeep.holla@xxxxxxxxxx>
To: Cristian Marussi <cristian.marussi@xxxxxxx>
To: Maarten Lankhorst <maarten.lankhorst@xxxxxxxxxxxxxxx>
To: Maxime Ripard <mripard@xxxxxxxxxx>
To: Thomas Zimmermann <tzimmermann@xxxxxxx>
To: David Airlie <airlied@xxxxxxxxx>
To: Simona Vetter <simona@xxxxxxxx>
To: Jani Nikula <jani.nikula@xxxxxxxxxxxxxxx>
To: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
To: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>
To: Tvrtko Ursulin <tursulin@xxxxxxxxxxx>
To: Lyude Paul <lyude@xxxxxxxxxx>
To: Danilo Krummrich <dakr@xxxxxxxxxx>
To: Zack Rusin <zack.rusin@xxxxxxxxxxxx>
To: Broadcom internal kernel review list <bcm-kernel-feedback-list@xxxxxxxxxxxx>
To: Selvin Xavier <selvin.xavier@xxxxxxxxxxxx>
To: Kalesh AP <kalesh-anakkur.purayil@xxxxxxxxxxxx>
To: Jason Gunthorpe <jgg@xxxxxxxx>
To: Leon Romanovsky <leon@xxxxxxxxxx>
To: Chengchang Tang <tangchengchang@xxxxxxxxxx>
To: Junxian Huang <huangjunxian6@xxxxxxxxxxxxx>
To: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
To: Hans de Goede <hansg@xxxxxxxxxx>
To: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>
To: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>
To: Wei Liu <wei.liu@xxxxxxxxxx>
To: Dexuan Cui <decui@xxxxxxxxxxxxx>
To: Andrew Lunn <andrew+netdev@xxxxxxx>
To: "David S. Miller" <davem@xxxxxxxxxxxxx>
To: Eric Dumazet <edumazet@xxxxxxxxxx>
To: Jakub Kicinski <kuba@xxxxxxxxxx>
To: Paolo Abeni <pabeni@xxxxxxxxxx>
To: Miri Korenblit <miriam.rachel.korenblit@xxxxxxxxx>
To: Jes Sorensen <Jes.Sorensen@xxxxxxxxx>
To: Ping-Ke Shih <pkshih@xxxxxxxxxxx>
To: Johannes Berg <johannes@xxxxxxxxxxxxxxxx>
To: Benson Leung <bleung@xxxxxxxxxxxx>
To: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
To: Guenter Roeck <groeck@xxxxxxxxxxxx>
To: Nilesh Javali <njavali@xxxxxxxxxxx>
To: GR-QLogic-Storage-Upstream@xxxxxxxxxxx
To: "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>
To: "Martin K. Petersen" <mkp@xxxxxxxxxx>
To: Julia Lawall <Julia.Lawall@xxxxxxxx>
To: Nicolas Palix <nicolas.palix@xxxxxxx>
To: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
To: Christian Brauner <brauner@xxxxxxxxxx>
To: Jan Kara <jack@xxxxxxx>
To: Paulo Alcantara <pc@xxxxxxxxxxxxx>
To: Namjae Jeon <linkinjeon@xxxxxxxxxx>
To: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
To: Shyam Prasad N <sprasad@xxxxxxxxxxxxx>
To: Tom Talpey <tom@xxxxxxxxxx>
To: Bharath SM <bharathsm@xxxxxxxxxxxxx>
To: Carlos Maiolino <cem@xxxxxxxxxx>
To: Thomas Gleixner <tglx@xxxxxxxxxx>
To: Ingo Molnar <mingo@xxxxxxxxxx>
To: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
To: Darren Hart <dvhart@xxxxxxxxxxxxx>
To: Davidlohr Bueso <dave@xxxxxxxxxxxx>
To: André Almeida <andrealmeid@xxxxxxxxxx>
To: Alexei Starovoitov <ast@xxxxxxxxxx>
To: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
To: Andrii Nakryiko <andrii@xxxxxxxxxx>
To: Eduard Zingerman <eddyz87@xxxxxxxxx>
To: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
To: Martin KaFai Lau <martin.lau@xxxxxxxxx>
To: Song Liu <song@xxxxxxxxxx>
To: Yonghong Song <yonghong.song@xxxxxxxxx>
To: Jiri Olsa <jolsa@xxxxxxxxxx>
To: Emil Tsalapatis <emil@xxxxxxxxxxxxxxx>
To: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
To: Simon Horman <horms@xxxxxxxxxx>
To: David Ahern <dsahern@xxxxxxxxxx>
To: Ido Schimmel <idosch@xxxxxxxxxx>
To: Willem de Bruijn <willemdebruijn.kernel@xxxxxxxxx>
To: Steffen Klassert <steffen.klassert@xxxxxxxxxxx>
To: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
To: Mickaël Salaün <mic@xxxxxxxxxxx>
To: Günther Noack <gnoack@xxxxxxxxxx>
To: Paul Moore <paul@xxxxxxxxxxxxxx>
To: James Morris <jmorris@xxxxxxxxx>
To: "Serge E. Hallyn" <serge@xxxxxxxxxx>
To: "Geoffrey D. Bennett" <g@xxxxx>
To: Jaroslav Kysela <perex@xxxxxxxx>
To: Takashi Iwai <tiwai@xxxxxxxx>
Cc: linux-hardening@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-bluetooth@xxxxxxxxxxxxxxx
Cc: linux-media@xxxxxxxxxxxxxxx
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
Cc: linaro-mm-sig@xxxxxxxxxxxxxxxx
Cc: arm-scmi@xxxxxxxxxxxxxxx
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: intel-gfx@xxxxxxxxxxxxxxxxxxxxx
Cc: nouveau@xxxxxxxxxxxxxxxxxxxxx
Cc: linux-rdma@xxxxxxxxxxxxxxx
Cc: linux-hyperv@xxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx
Cc: linux-wireless@xxxxxxxxxxxxxxx
Cc: chrome-platform@xxxxxxxxxxxxxxx
Cc: linux-scsi@xxxxxxxxxxxxxxx
Cc: cocci@xxxxxxxx
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Cc: linux-cifs@xxxxxxxxxxxxxxx
Cc: samba-technical@xxxxxxxxxxxxxxx
Cc: linux-xfs@xxxxxxxxxxxxxxx
Cc: bpf@xxxxxxxxxxxxxxx
Cc: ipsec@xxxxxxxxxxxxxxx
Cc: linux-security-module@xxxxxxxxxxxxxxx
Cc: linux-sound@xxxxxxxxxxxxxxx
---
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 <bence.csokas@xxxxxxx>