Message ID | 20240731045346.4087-1-dmantipov@yandex.ru (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [v2] net: core: annotate socks of struct sock_reuseport with __counted_by | expand |
On Wed, 31 Jul 2024 07:53:46 +0300 Dmitry Antipov wrote: > + reuse = kzalloc(struct_size(reuse, socks, max_socks), GFP_ATOMIC); > > if (!reuse) another nit -- no empty lines between function call and its error check :) Two bits of docs to look at before sending v3: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#resending-after-review https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#changes-requested
diff --git a/include/net/sock_reuseport.h b/include/net/sock_reuseport.h index 6ec140b0a61b..6e4faf3ee76f 100644 --- a/include/net/sock_reuseport.h +++ b/include/net/sock_reuseport.h @@ -26,7 +26,7 @@ struct sock_reuseport { unsigned int bind_inany:1; unsigned int has_conns:1; struct bpf_prog __rcu *prog; /* optional BPF sock selector */ - struct sock *socks[]; /* array of sock pointers */ + struct sock *socks[] __counted_by(max_socks); }; extern int reuseport_alloc(struct sock *sk, bool bind_inany); diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c index 5a165286e4d8..79f2456e27a5 100644 --- a/net/core/sock_reuseport.c +++ b/net/core/sock_reuseport.c @@ -173,9 +173,9 @@ static bool __reuseport_detach_closed_sock(struct sock *sk, static struct sock_reuseport *__reuseport_alloc(unsigned int max_socks) { - unsigned int size = sizeof(struct sock_reuseport) + - sizeof(struct sock *) * max_socks; - struct sock_reuseport *reuse = kzalloc(size, GFP_ATOMIC); + struct sock_reuseport *reuse; + + reuse = kzalloc(struct_size(reuse, socks, max_socks), GFP_ATOMIC); if (!reuse) return NULL;
According to '__reuseport_alloc()', annotate flexible array member 'sock' of 'struct sock_reuseport' with '__counted_by()' and use convenient 'struct_size()' to simplify the math used in 'kzalloc()'. Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> --- v2: style (Jakub), title and commit message (Gustavo) adjustments --- include/net/sock_reuseport.h | 2 +- net/core/sock_reuseport.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)