On Thu, Nov 12, 2026 at 10:29:32AM +0100, Bence Csokas wrote:
> 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.

Yeah, I think this is reasonable. I'd prefer to see the Coccinelle
script explicitly added to tools/coccinelle/api/ though, so it can be
trivially re-run as needed.

Also, while Alejandro is right about the needless outer parens, I think
I'd like to keep them just to match the other define, and they do no
harm.

-Kees

> 
> Signed-off-by: Bence Csokas <[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]>
> 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):
>       stddef: 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                         | 26 
> +++++++++++-----------
>  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 +-
>  include/linux/overflow.h                           | 12 ++++++++++
>  30 files changed, 75 insertions(+), 64 deletions(-)
> ---
> base-commit: 9d66f26fefacebfeed15de31c1123451a17ff119
> change-id: 20261105-offsetof-f62aa6348f0d
> 
> Best regards,
> --  
> Bence Csokas <[email protected]>
> 

-- 
Kees Cook

Reply via email to