Skip to content

Commit f940746

Browse files
dmantipovkuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6555a2a commit f940746

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

include/net/sock_reuseport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct sock_reuseport {
2626
unsigned int bind_inany:1;
2727
unsigned int has_conns:1;
2828
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);
3030
};
3131

3232
extern int reuseport_alloc(struct sock *sk, bool bind_inany);

net/core/sock_reuseport.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ static bool __reuseport_detach_closed_sock(struct sock *sk,
173173

174174
static struct sock_reuseport *__reuseport_alloc(unsigned int max_socks)
175175
{
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;
179177

178+
reuse = kzalloc(struct_size(reuse, socks, max_socks), GFP_ATOMIC);
180179
if (!reuse)
181180
return NULL;
182181

0 commit comments

Comments
 (0)