aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa/dsa2.c
diff options
context:
space:
mode:
authorFlorian Fainelli <f.fainelli@gmail.com>2017-01-09 14:58:34 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-10 20:18:52 -0500
commitfaf3a932fbeb77860226a8323eacb835edc98648 (patch)
tree89e9312654f638db3f1723446d57d57d231f74da /net/dsa/dsa2.c
parentd9584d8ccc06ba98f4fad8ec720de66b6659fd35 (diff)
net: dsa: Ensure validity of dst->ds[0]
It is perfectly possible to have non zero indexed switches being present in a DSA switch tree, in such a case, we will be deferencing a NULL pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive and ensure that dst->ds[0] is valid before doing anything with it. Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree") Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r--net/dsa/dsa2.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 5fff951a0a49..da3862124545 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -394,9 +394,11 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
394 return err; 394 return err;
395 } 395 }
396 396
397 err = dsa_cpu_port_ethtool_setup(dst->ds[0]); 397 if (dst->ds[0]) {
398 if (err) 398 err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
399 return err; 399 if (err)
400 return err;
401 }
400 402
401 /* If we use a tagging format that doesn't have an ethertype 403 /* If we use a tagging format that doesn't have an ethertype
402 * field, make sure that all packets from this point on get 404 * field, make sure that all packets from this point on get
@@ -433,7 +435,8 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
433 dsa_ds_unapply(dst, ds); 435 dsa_ds_unapply(dst, ds);
434 } 436 }
435 437
436 dsa_cpu_port_ethtool_restore(dst->ds[0]); 438 if (dst->ds[0])
439 dsa_cpu_port_ethtool_restore(dst->ds[0]);
437 440
438 pr_info("DSA: tree %d unapplied\n", dst->tree); 441 pr_info("DSA: tree %d unapplied\n", dst->tree);
439 dst->applied = false; 442 dst->applied = false;