Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Bence Csokas
Thu, 12 Nov 2026 09:29
[PATCH v2 1/2] stddef: Add offsetofend() variant of struct_offset()
Author: Bence Csokas
Date: Thu, 12 Nov 2026 09:29
Date: Thu, 12 Nov 2026 09:29
44 lines
23474 bytes
23474 bytes
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)) + /** * __DEFINE_FLEX() - helper macro for DEFINE_FLEX() family. * Enables caller macro to pass arbitrary trailing expressions -- 2.56.1
Re: [PATCH v2 1/2] stddef: Add offsetofend() variant of struct_offset()
Author: Alejandro Colomar
Date: Thu, 12 Nov 2026 10:47
Date: Thu, 12 Nov 2026 10:47
132 lines
16293 bytes
16293 bytes
--hmbonzz4lyxux25l Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =?utf-8?B?S8O2bmln?= <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() Message-ID: <avWY8kNFlkLyxIrX@devuan> References: <20261112-offsetof-v2-0-276ede839967@arm.com> <20261112-offsetof-v2-1-276ede839967@arm.com> MIME-Version: 1.0 In-Reply-To: <20261112-offsetof-v2-1-276ede839967@arm.com> 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: >=20 > offsetofend(typeof(*ptr), member) >=20 > 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. >=20 > A similar struct_offset() macro already exists, so add an offsetof() > variant in the same spirit. >=20 > Signed-off-by: Bence Csokas <bence.csokas@arm.com> > --- > include/linux/overflow.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) >=20 > 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)) > =20 > +/** > + * 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 struc= ture > + * 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 >=20 > --=20 > 2.56.1 >=20 >=20 --=20 <https://www.alejandro-colomar.es> --hmbonzz4lyxux25l Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmr1mUAACgkQ64mZXMKQ wqniCg//WgRXXz7luTnHUaMXrHNthttFpY3wBO557jzGIfLwMa+0tJqYgSh8MGS8 7F44pQ7lX8E0qC+aMkDd3ItqdrKeD3McIbqqgpr8iU1VT0ljohr8pnTU7UIyIP/u bX/o22pWYohJFt/xcJcLxQ63rHmjcfjH2ug2i8ZgZHh/YGX+Biah79nfkcAB+uYX NI+43mSTP1aHvUK3Jf/z7PJF/v1/vyv1zJ/nsoN74w3JhlYGMggMcXHSu+dp0jmX qJUkyYJ5SQEzMdU/n2pSgOJFIZl6YS957I6fhU3GxEPXSldcnd/VIH/QRKMpSyjM jWzBsyjyyink+9RSw7AcmU46DJ28GeWMW5jZdg7jXq6ZGjO0/AKleOtMrevQLN4s hB7CzUrtofXBv5Oa5javphhfKIEoawgDsDch5eXFQW/Rm9rSflWysbPTCST5n/h0 GfKbUEzD+COFj6I+Y8COEceKp4Xv8Y08A3r6CyyNIPzPwcc0CulK6xAmHbsMxIXZ c6uz3LLfqukMfbuquIZE4KhlNt+ZLRtnxL6rFfFkvLYdz4KwIsljmiPqoyPQxp9A OX5vOdZ9ulzmuuNoTY5OeJWSlsI6edzNc17hE6jjR1+wFfJSzVF2cvvv6mRGnpY/ bGpmsQZFuH/KWJutZlHbsMGYEKF7lo42UH0Tqx57oaglMss89x4= =8quq -----END PGP SIGNATURE----- --hmbonzz4lyxux25l--
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads