netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] nfp: Use static_assert() to check struct sizes
@ 2024-08-08 22:08 Gustavo A. R. Silva
  2024-08-12 10:22 ` Simon Horman
  2024-08-13  2:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2024-08-08 22:08 UTC (permalink / raw)
  To: Louis Peens, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni
  Cc: oss-drivers, netdev, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

Commit d88cabfd9abc ("nfp: Avoid -Wflex-array-member-not-at-end
warnings") introduced tagged `struct nfp_dump_tl_hdr`. We want
to ensure that when new members need to be added to the flexible
structure, they are always included within this tagged struct.

So, we use `static_assert()` to ensure that the memory layout for
both the flexible structure and the tagged struct is the same after
any changes.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/net/ethernet/netronome/nfp/nfp_net_debugdump.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_debugdump.c b/drivers/net/ethernet/netronome/nfp/nfp_net_debugdump.c
index 2dd37557185e..7276e44a21d0 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_debugdump.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_debugdump.c
@@ -41,6 +41,8 @@ struct nfp_dump_tl {
 	);
 	char data[];
 };
+static_assert(offsetof(struct nfp_dump_tl, data) == sizeof(struct nfp_dump_tl_hdr),
+	      "struct member likely outside of struct_group_tagged()");
 
 /* NFP CPP parameters */
 struct nfp_dumpspec_cpp_isl_id {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] nfp: Use static_assert() to check struct sizes
  2024-08-08 22:08 [PATCH][next] nfp: Use static_assert() to check struct sizes Gustavo A. R. Silva
@ 2024-08-12 10:22 ` Simon Horman
  2024-08-13  2:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-08-12 10:22 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Louis Peens, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni, oss-drivers, netdev, linux-kernel, linux-hardening

On Thu, Aug 08, 2024 at 04:08:35PM -0600, Gustavo A. R. Silva wrote:
> Commit d88cabfd9abc ("nfp: Avoid -Wflex-array-member-not-at-end
> warnings") introduced tagged `struct nfp_dump_tl_hdr`. We want
> to ensure that when new members need to be added to the flexible
> structure, they are always included within this tagged struct.
> 
> So, we use `static_assert()` to ensure that the memory layout for
> both the flexible structure and the tagged struct is the same after
> any changes.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] nfp: Use static_assert() to check struct sizes
  2024-08-08 22:08 [PATCH][next] nfp: Use static_assert() to check struct sizes Gustavo A. R. Silva
  2024-08-12 10:22 ` Simon Horman
@ 2024-08-13  2:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-13  2:10 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: louis.peens, kuba, davem, edumazet, pabeni, oss-drivers, netdev,
	linux-kernel, linux-hardening

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 8 Aug 2024 16:08:35 -0600 you wrote:
> Commit d88cabfd9abc ("nfp: Avoid -Wflex-array-member-not-at-end
> warnings") introduced tagged `struct nfp_dump_tl_hdr`. We want
> to ensure that when new members need to be added to the flexible
> structure, they are always included within this tagged struct.
> 
> So, we use `static_assert()` to ensure that the memory layout for
> both the flexible structure and the tagged struct is the same after
> any changes.
> 
> [...]

Here is the summary with links:
  - [next] nfp: Use static_assert() to check struct sizes
    https://git.kernel.org/netdev/net-next/c/46dd90fe51f3

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-13  2:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 22:08 [PATCH][next] nfp: Use static_assert() to check struct sizes Gustavo A. R. Silva
2024-08-12 10:22 ` Simon Horman
2024-08-13  2:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).