* [PATCH] net: llc: drop VLA in llc_sap_mcast()
@ 2018-03-11 21:12 Salvatore Mesoraca
2018-03-12 15:14 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Salvatore Mesoraca @ 2018-03-11 21:12 UTC (permalink / raw)
To: linux-kernel
Cc: kernel-hardening, netdev, David S. Miller, Paul E. McKenney,
David Rientjes, Elena Reshetova, Hans Liljestrand, Kees Cook,
Salvatore Mesoraca
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>
---
net/llc/llc_sap.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
index d90928f..a7f7b8f 100644
--- a/net/llc/llc_sap.c
+++ b/net/llc/llc_sap.c
@@ -394,8 +394,9 @@ static void llc_sap_mcast(struct llc_sap *sap,
const struct llc_addr *laddr,
struct sk_buff *skb)
{
- int i = 0, count = 256 / sizeof(struct sock *);
- struct sock *sk, *stack[count];
+ int i = 0;
+ struct sock *sk;
+ struct sock *stack[256 / sizeof(struct sock *)];
struct llc_sock *llc;
struct hlist_head *dev_hb = llc_sk_dev_hash(sap, skb->dev->ifindex);
@@ -408,7 +409,7 @@ static void llc_sap_mcast(struct llc_sap *sap,
continue;
sock_hold(sk);
- if (i < count)
+ if (i < ARRAY_SIZE(stack))
stack[i++] = sk;
else {
llc_do_mcast(sap, skb, stack, i);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: llc: drop VLA in llc_sap_mcast()
2018-03-11 21:12 [PATCH] net: llc: drop VLA in llc_sap_mcast() Salvatore Mesoraca
@ 2018-03-12 15:14 ` David Miller
2018-03-12 16:47 ` Salvatore Mesoraca
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-03-12 15:14 UTC (permalink / raw)
To: s.mesoraca16
Cc: linux-kernel, kernel-hardening, netdev, paulmck, rientjes,
elena.reshetova, ishkamiel, keescook
From: Salvatore Mesoraca <s.mesoraca16@gmail.com>
Date: Sun, 11 Mar 2018 22:12:04 +0100
> 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>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: llc: drop VLA in llc_sap_mcast()
2018-03-12 15:14 ` David Miller
@ 2018-03-12 16:47 ` Salvatore Mesoraca
0 siblings, 0 replies; 3+ messages in thread
From: Salvatore Mesoraca @ 2018-03-12 16:47 UTC (permalink / raw)
To: David Miller
Cc: linux-kernel, Kernel Hardening, netdev, paulmck, rientjes,
elena.reshetova, ishkamiel, keescook
2018-03-12 16:14 GMT+01:00 David Miller <davem@davemloft.net>:
> From: Salvatore Mesoraca <s.mesoraca16@gmail.com>
> Date: Sun, 11 Mar 2018 22:12:04 +0100
>
>> 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>
>
> Applied.
Thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-12 16:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-11 21:12 [PATCH] net: llc: drop VLA in llc_sap_mcast() Salvatore Mesoraca
2018-03-12 15:14 ` David Miller
2018-03-12 16:47 ` Salvatore Mesoraca
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).