]>
Commit | Line | Data |
---|---|---|
1143c684 SL |
1 | From 153b291de4f8fe6edf2d9c4745c2763771fefcb2 Mon Sep 17 00:00:00 2001 |
2 | From: "Gustavo A. R. Silva" <gustavo@embeddedor.com> | |
3 | Date: Fri, 29 Mar 2019 10:27:26 -0500 | |
4 | Subject: cxgb3/l2t: Fix undefined behaviour | |
5 | ||
6 | [ Upstream commit 76497732932f15e7323dc805e8ea8dc11bb587cf ] | |
7 | ||
8 | The use of zero-sized array causes undefined behaviour when it is not | |
9 | the last member in a structure. As it happens to be in this case. | |
10 | ||
11 | Also, the current code makes use of a language extension to the C90 | |
12 | standard, but the preferred mechanism to declare variable-length | |
13 | types such as this one is a flexible array member, introduced in | |
14 | C99: | |
15 | ||
16 | struct foo { | |
17 | int stuff; | |
18 | struct boo array[]; | |
19 | }; | |
20 | ||
21 | By making use of the mechanism above, we will get a compiler warning | |
22 | in case the flexible array does not occur last. Which is beneficial | |
23 | to cultivate a high-quality code. | |
24 | ||
25 | Fixes: e48f129c2f20 ("[SCSI] cxgb3i: convert cdev->l2opt to use rcu to prevent NULL dereference") | |
26 | Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> | |
27 | Signed-off-by: David S. Miller <davem@davemloft.net> | |
28 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
29 | --- | |
30 | drivers/net/ethernet/chelsio/cxgb3/l2t.h | 2 +- | |
31 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
32 | ||
33 | diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h | |
34 | index 8cffcdfd56782..38b5858c335a9 100644 | |
35 | --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h | |
36 | +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h | |
37 | @@ -75,8 +75,8 @@ struct l2t_data { | |
38 | struct l2t_entry *rover; /* starting point for next allocation */ | |
39 | atomic_t nfree; /* number of free entries */ | |
40 | rwlock_t lock; | |
41 | - struct l2t_entry l2tab[0]; | |
42 | struct rcu_head rcu_head; /* to handle rcu cleanup */ | |
43 | + struct l2t_entry l2tab[]; | |
44 | }; | |
45 | ||
46 | typedef void (*arp_failure_handler_func)(struct t3cdev * dev, | |
47 | -- | |
48 | 2.20.1 | |
49 |