Linux bluetooth development
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx+linux-hardening@kernel.org>
To: Bence Csokas <bence.csokas@arm.com>
Cc: "Kees Cook" <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"Marcel Holtmann" <marcel@holtmann.org>,
	"Luiz Augusto von Dentz" <luiz.dentz@gmail.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Philipp Stanner" <phasta@kernel.org>,
	"Sudeep Holla" <sudeep.holla@kernel.org>,
	"Cristian Marussi" <cristian.marussi@arm.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"Lyude Paul" <lyude@redhat.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Zack Rusin" <zack.rusin@broadcom.com>,
	"Broadcom internal kernel review list"
	<bcm-kernel-feedback-list@broadcom.com>,
	"Selvin Xavier" <selvin.xavier@broadcom.com>,
	"Kalesh AP" <kalesh-anakkur.purayil@broadcom.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Chengchang Tang" <tangchengchang@huawei.com>,
	"Junxian Huang" <huangjunxian6@hisilicon.com>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Haiyang Zhang" <haiyangz@microsoft.com>,
	"Wei Liu" <wei.liu@kernel.org>,
	"Dexuan Cui" <decui@microsoft.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Miri Korenblit" <miriam.rachel.korenblit@intel.com>,
	"Jes Sorensen" <Jes.Sorensen@gmail.com>,
	"Ping-Ke Shih" <pkshih@realtek.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Benson Leung" <bleung@chromium.org>,
	"Tzung-Bi Shih" <tzungbi@kernel.org>,
	"Guenter Roeck" <groeck@chromium.org>,
	"Nilesh Javali" <njavali@marvell.com>,
	GR-QLogic-Storage-Upstream@marvell.com,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-bluetooth@vger.kernel.org, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
	arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org,
	netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
	chrome-platform@lists.linux.dev, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 1/2] stddef: Add offsetofend() variant of struct_offset()
Date: Thu, 12 Nov 2026 11:47:38 +0100	[thread overview]
Message-ID: <avWY8kNFlkLyxIrX@devuan> (raw)
In-Reply-To: <20261112-offsetof-v2-1-276ede839967@arm.com>

[-- Attachment #1: Type: text/plain, Size: 1906 bytes --]

Hi Bence,

> Date: 2026-11-12 10:29:33+0100
> From: Bence Csokas <bence.csokas@arm.com>
>
> Many call sites of offsetofend() use it for the purpose of pointer
> artihmetic. Thus, a common usage pattern is:
> 
>   offsetofend(typeof(*ptr), member)
> 
> Capturing this in one macro helps keep lines short and terse, while
> still making the purpose clear. It also helps discourage spelling out
> the type name on every callsite, leading to more maintainable code.
> 
> A similar struct_offset() macro already exists, so add an offsetof()
> variant in the same spirit.
> 
> Signed-off-by: Bence Csokas <bence.csokas@arm.com>
> ---
>  include/linux/overflow.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> index d0f04436343e..060dad4b6f3e 100644
> --- a/include/linux/overflow.h
> +++ b/include/linux/overflow.h
> @@ -464,6 +464,18 @@ static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtr
>   */
>  #define struct_offset(p, member) (offsetof(typeof(*(p)), member))
>  
> +/**
> + * struct_offsetofend() - Calculate the end of a member within a struct
> + * @p: Pointer to the struct
> + * @member: Name of the member to get the end offset of
> + *
> + * Calculates the offset of the end of a particular @member of the structure
> + * pointed to by @p.
> + *
> + * Return: number of bytes to the location of @member.
> + */
> +#define struct_offsetofend(p, member) (offsetofend(typeof(*(p)), member))

The outer parentheses are unnecessary (they are unnecessary in
struct_offset() too, but that already exists).


Have a lovely day!
Alex

> +
>  /**
>   * __DEFINE_FLEX() - helper macro for DEFINE_FLEX() family.
>   * Enables caller macro to pass arbitrary trailing expressions
> 
> -- 
> 2.56.1
> 
> 

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-11-12 10:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  9:29 [PATCH v2 0/2] Add struct_offsetofend() for pointer arithmetic Bence Csokas
2026-11-12  9:29 ` [PATCH v2 1/2] stddef: Add offsetofend() variant of struct_offset() Bence Csokas
2026-11-12 10:47   ` Alejandro Colomar [this message]
2026-11-12  9:29 ` [PATCH v2 2/2] treewide: Use struct_offset() Bence Csokas

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=avWY8kNFlkLyxIrX@devuan \
    --to=alx+linux-hardening@kernel.org \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=Jes.Sorensen@gmail.com \
    --cc=airlied@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=arm-scmi@vger.kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bence.csokas@arm.com \
    --cc=bleung@chromium.org \
    --cc=christian.koenig@amd.com \
    --cc=chrome-platform@lists.linux.dev \
    --cc=cristian.marussi@arm.com \
    --cc=dakr@kernel.org \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edumazet@kernel.org \
    --cc=groeck@chromium.org \
    --cc=gustavoars@kernel.org \
    --cc=haiyangz@microsoft.com \
    --cc=hansg@kernel.org \
    --cc=huangjunxian6@hisilicon.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jgg@ziepe.ca \
    --cc=johannes@sipsolutions.net \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=leon@kernel.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marcel@holtmann.org \
    --cc=mchehab@kernel.org \
    --cc=miriam.rachel.korenblit@intel.com \
    --cc=mkp@kernel.org \
    --cc=mripard@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=njavali@marvell.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=pabeni@redhat.com \
    --cc=phasta@kernel.org \
    --cc=pkshih@realtek.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=selvin.xavier@broadcom.com \
    --cc=simona@ffwll.ch \
    --cc=sudeep.holla@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=tangchengchang@huawei.com \
    --cc=tursulin@ursulin.net \
    --cc=tzimmermann@suse.de \
    --cc=tzungbi@kernel.org \
    --cc=wei.liu@kernel.org \
    --cc=zack.rusin@broadcom.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox