From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
"David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
netdev@vger.kernel.org
Subject: Re: [PATCH net-next] udp_tunnel: Use flex array to simplify code
Date: Sun, 24 Sep 2023 12:00:58 -0400 [thread overview]
Message-ID: <65105d3a8e70e_12c73e29410@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <4a096ba9cf981a588aa87235bb91e933ee162b3d.1695542544.git.christophe.jaillet@wanadoo.fr>
Christophe JAILLET wrote:
> 'n_tables' is small, UDP_TUNNEL_NIC_MAX_TABLES = 4 as a maximum. So there
> is no real point to allocate the 'entries' pointers array with a dedicate
> memory allocation.
>
> Using a flexible array for struct udp_tunnel_nic->entries avoids the
> overhead of an additional memory allocation.
>
> This also saves an indirection when the array is accessed.
>
> Finally, __counted_by() can be used for run-time bounds checking if
> configured and supported by the compiler.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> net/ipv4/udp_tunnel_nic.c | 11 ++---------
> 1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/net/ipv4/udp_tunnel_nic.c b/net/ipv4/udp_tunnel_nic.c
> index 029219749785..b6d2d16189c0 100644
> --- a/net/ipv4/udp_tunnel_nic.c
> +++ b/net/ipv4/udp_tunnel_nic.c
> @@ -47,7 +47,7 @@ struct udp_tunnel_nic {
>
> unsigned int n_tables;
> unsigned long missed;
> - struct udp_tunnel_nic_table_entry **entries;
> + struct udp_tunnel_nic_table_entry *entries[] __counted_by(n_tables);
> };
>
> /* We ensure all work structs are done using driver state, but not the code.
> @@ -725,16 +725,12 @@ udp_tunnel_nic_alloc(const struct udp_tunnel_nic_info *info,
> struct udp_tunnel_nic *utn;
> unsigned int i;
>
> - utn = kzalloc(sizeof(*utn), GFP_KERNEL);
> + utn = kzalloc(struct_size(utn, entries, n_tables), GFP_KERNEL);
> if (!utn)
> return NULL;
> utn->n_tables = n_tables;
Should utn->n_tables be initialized before first use of
struct_size(utn, entries, n_tables)?
next prev parent reply other threads:[~2023-09-24 16:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-24 8:03 [PATCH net-next] udp_tunnel: Use flex array to simplify code Christophe JAILLET
2023-09-24 16:00 ` Willem de Bruijn [this message]
2023-09-25 16:26 ` Christophe JAILLET
2023-09-25 20:50 ` Willem de Bruijn
2023-10-03 9:50 ` patchwork-bot+netdevbpf
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=65105d3a8e70e_12c73e29410@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).