From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16427606A32E for ; Fri, 13 Nov 2026 14:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bhRW52/O Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9AFC01123D1; Fri, 13 Nov 2026 14:28:14 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3A26510FFFD; Thu, 12 Nov 2026 10:47:54 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 2309263629; Thu, 12 Nov 2026 10:47:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D85FD1F00A05; Thu, 12 Nov 2026 10:47:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794480472; bh=LaAKKhAngwkFxDGEu7glsCDhQDKP6or5IXQD5q9C6lk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bhRW52/OaiERqOjVo+YsX7WenTAM+RkUSYdDbFFgDeELIFl5MCvdrQ4/lrfg3PaBP OJEvlXHrGI0KP6Sf7isOdA90CQUC1tSnbnlL7KMlGmOGy1uOT4Tps4k2NALfzc5lt4 GBKdaLdl6Hn4QG7D1jOt3xg+R2SbDhwXqrQ5QTOpBVzV6PCDTf9sB1jcXxmSVYEwEX 9k1ve7B7mHoKt9f85FezBUXVhvbLCq9DZT0dTEHtWXQsiFKFjjwdYqhwDGS2C9B8hk PMIxYSXrd0qwW336ZZGtXr/22P+Xd17f+e0rYlMLg9nZUtItJXlZjgdtGYx+r60Y9l +6iWNMqoSTUaQ== Date: Thu, 12 Nov 2026 11:47:38 +0100 From: Alejandro Colomar To: Bence Csokas Cc: Kees Cook , "Gustavo A. R. Silva" , Marcel Holtmann , Luiz Augusto von Dentz , Sumit Semwal , Christian =?utf-8?B?S8O2bmln?= , Philipp Stanner , Sudeep Holla , Cristian Marussi , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Lyude Paul , Danilo Krummrich , Zack Rusin , Broadcom internal kernel review list , Selvin Xavier , Kalesh AP , Jason Gunthorpe , Leon Romanovsky , Chengchang Tang , Junxian Huang , Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Haiyang Zhang , Wei Liu , Dexuan Cui , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Miri Korenblit , Jes Sorensen , Ping-Ke Shih , Johannes Berg , Benson Leung , Tzung-Bi Shih , Guenter Roeck , Nilesh Javali , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , 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: References: <20261112-offsetof-v2-0-276ede839967@arm.com> <20261112-offsetof-v2-1-276ede839967@arm.com> X-Archived-By: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hmbonzz4lyxux25l" Content-Disposition: inline In-Reply-To: <20261112-offsetof-v2-1-276ede839967@arm.com> X-Mailman-Approved-At: Fri, 13 Nov 2026 14:28:12 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-gfx" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 --hmbonzz4lyxux25l Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable From: Alejandro Colomar To: Bence Csokas Cc: Kees Cook , "Gustavo A. R. Silva" , Marcel Holtmann , Luiz Augusto von Dentz , Sumit Semwal , Christian =?utf-8?B?S8O2bmln?= , Philipp Stanner , Sudeep Holla , Cristian Marussi , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Lyude Paul , Danilo Krummrich , Zack Rusin , Broadcom internal kernel review list , Selvin Xavier , Kalesh AP , Jason Gunthorpe , Leon Romanovsky , Chengchang Tang , Junxian Huang , Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Haiyang Zhang , Wei Liu , Dexuan Cui , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Miri Korenblit , Jes Sorensen , Ping-Ke Shih , Johannes Berg , Benson Leung , Tzung-Bi Shih , Guenter Roeck , Nilesh Javali , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , 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: 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 > > 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 > --- > 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 --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--