]> git.hungrycats.org Git - linux/commit
cxgb3/l2t: Fix undefined behaviour
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Fri, 29 Mar 2019 15:27:26 +0000 (10:27 -0500)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 23 Sep 2019 20:11:37 +0000 (21:11 +0100)
commit49187c9dbc34a6392b3fbbca3cb009f077d62d63
tree10eeb968e1bf20ef26d31f1a8a4601b204561e6a
parent1e073f27b47c6be13940c984c461d08129aeb7f2
cxgb3/l2t: Fix undefined behaviour

commit 76497732932f15e7323dc805e8ea8dc11bb587cf upstream.

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: e48f129c2f20 ("[SCSI] cxgb3i: convert cdev->l2opt to use rcu to prevent NULL dereference")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/net/ethernet/chelsio/cxgb3/l2t.h