Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit faf3a932 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller
Browse files

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: 0c73c523 ("net: dsa: Initialize CPU port ethtool ops per tree")
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d9584d8c
Loading
Loading
Loading
Loading
+7 −4
Original line number Original line Diff line number Diff line
@@ -394,9 +394,11 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
			return err;
			return err;
	}
	}


	if (dst->ds[0]) {
		err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
		err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
		if (err)
		if (err)
			return err;
			return err;
	}


	/* If we use a tagging format that doesn't have an ethertype
	/* If we use a tagging format that doesn't have an ethertype
	 * field, make sure that all packets from this point on get
	 * field, make sure that all packets from this point on get
@@ -433,6 +435,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
		dsa_ds_unapply(dst, ds);
		dsa_ds_unapply(dst, ds);
	}
	}


	if (dst->ds[0])
		dsa_cpu_port_ethtool_restore(dst->ds[0]);
		dsa_cpu_port_ethtool_restore(dst->ds[0]);


	pr_info("DSA: tree %d unapplied\n", dst->tree);
	pr_info("DSA: tree %d unapplied\n", dst->tree);