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

net: llc: drop VLA in llc_sap_mcast()

Avoid a VLA[1] by using a real constant expression instead of a variable.
The compiler should be able to optimize the original code and avoid using
an actual VLA. Anyway this change is useful because it will avoid a false
positive with -Wvla, it might also help the compiler generating better
code.

[1] https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Salvatore Mesoraca <s.mesoraca16@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Salvatore Mesoraca and committed by
David S. Miller
678f4bda c16b1a9c

+4 -3
+4 -3
net/llc/llc_sap.c
··· 394 394 const struct llc_addr *laddr, 395 395 struct sk_buff *skb) 396 396 { 397 - int i = 0, count = 256 / sizeof(struct sock *); 398 - struct sock *sk, *stack[count]; 397 + int i = 0; 398 + struct sock *sk; 399 + struct sock *stack[256 / sizeof(struct sock *)]; 399 400 struct llc_sock *llc; 400 401 struct hlist_head *dev_hb = llc_sk_dev_hash(sap, skb->dev->ifindex); 401 402 ··· 409 408 continue; 410 409 411 410 sock_hold(sk); 412 - if (i < count) 411 + if (i < ARRAY_SIZE(stack)) 413 412 stack[i++] = sk; 414 413 else { 415 414 llc_do_mcast(sap, skb, stack, i);