Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: core: annotate socks of struct sock_reuseport with __counted_by

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>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20240801142311.42837-1-dmantipov@yandex.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Dmitry Antipov and committed by
Jakub Kicinski
f9407468 6555a2a9

+3 -4
+1 -1
include/net/sock_reuseport.h
··· 26 26 unsigned int bind_inany:1; 27 27 unsigned int has_conns:1; 28 28 struct bpf_prog __rcu *prog; /* optional BPF sock selector */ 29 - struct sock *socks[]; /* array of sock pointers */ 29 + struct sock *socks[] __counted_by(max_socks); 30 30 }; 31 31 32 32 extern int reuseport_alloc(struct sock *sk, bool bind_inany);
+2 -3
net/core/sock_reuseport.c
··· 173 173 174 174 static struct sock_reuseport *__reuseport_alloc(unsigned int max_socks) 175 175 { 176 - unsigned int size = sizeof(struct sock_reuseport) + 177 - sizeof(struct sock *) * max_socks; 178 - struct sock_reuseport *reuse = kzalloc(size, GFP_ATOMIC); 176 + struct sock_reuseport *reuse; 179 177 178 + reuse = kzalloc(struct_size(reuse, socks, max_socks), GFP_ATOMIC); 180 179 if (!reuse) 181 180 return NULL; 182 181