Skip to content

Commit

Permalink
cxgb3/l2t: Fix undefined behaviour
Browse files Browse the repository at this point in the history
The use of zero-sized array causes undefined behaviour when it is not
the last member in a structure. As it happens to be in this case.

Also, the current code makes use of a language extension to the C90
standard, but the preferred mechanism to declare variable-length
types such as this one is a flexible array member, introduced in
C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last. Which is beneficial
to cultivate a high-quality code.

Fixes: e48f129 ("[SCSI] cxgb3i: convert cdev->l2opt to use rcu to prevent NULL dereference")
Signed-off-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
GustavoARSilva authored and davem330 committed Apr 1, 2019
1 parent a2c7023 commit 7649773
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/chelsio/cxgb3/l2t.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ struct l2t_data {
struct l2t_entry *rover; /* starting point for next allocation */
atomic_t nfree; /* number of free entries */
rwlock_t lock;
struct l2t_entry l2tab[0];
struct rcu_head rcu_head; /* to handle rcu cleanup */
struct l2t_entry l2tab[];
};

typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
Expand Down

0 comments on commit 7649773

Please sign in to comment.