1 From foo@baz Thu Jan 12 21:37:26 CET 2017
2 From: Florian Fainelli <f.fainelli@gmail.com>
3 Date: Mon, 9 Jan 2017 11:58:34 -0800
4 Subject: net: dsa: Ensure validity of dst->ds[0]
6 From: Florian Fainelli <f.fainelli@gmail.com>
9 [ Upstream commit faf3a932fbeb77860226a8323eacb835edc98648 ]
11 It is perfectly possible to have non zero indexed switches being present
12 in a DSA switch tree, in such a case, we will be deferencing a NULL
13 pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive
14 and ensure that dst->ds[0] is valid before doing anything with it.
16 Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree")
17 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
18 Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 net/dsa/dsa2.c | 11 +++++++----
23 1 file changed, 7 insertions(+), 4 deletions(-)
27 @@ -394,9 +394,11 @@ static int dsa_dst_apply(struct dsa_swit
31 - err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
35 + err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
40 /* If we use a tagging format that doesn't have an ethertype
41 * field, make sure that all packets from this point on get
42 @@ -433,7 +435,8 @@ static void dsa_dst_unapply(struct dsa_s
43 dsa_ds_unapply(dst, ds);
46 - dsa_cpu_port_ethtool_restore(dst->ds[0]);
48 + dsa_cpu_port_ethtool_restore(dst->ds[0]);
50 pr_info("DSA: tree %d unapplied\n", dst->tree);