Subject: Re: [PATCH net] net: dsa: Ensure validity of dst->ds[0]

From: Andrew Lunn <[email-masked]>
Date: Mon, 9 Jan 2017 22:01:37 +0100

On Mon, Jan 09, 2017 at 03:50:53PM -0500, Vivien Didelot wrote:
> Hi Florian,
> 
> Florian Fainelli <[email-masked]> writes:
> 
> > 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 <[email-masked]>
> 
> Reviewed-by: Vivien Didelot <[email-masked]>
> 
> The patch is correct since we are already using dst->ds[0] here.
> 
> But we should stop using that and use dst->cpu_switch instead, because
> the switch with ID 0 won't necessary be the CPU switch. Now that the
> Ethernet switch chips are true Linux devices, they are registered in
> order depending on their bus/address. So in a setup like this:
> 
>        ,--MDIO--@4--------@2--
>       |         |         |
>     [CPU] <-> [swA] <-> [swB]

> 
> swB will have index 0 and swA will have index 1. Please correct me if
> I'm wrong.

Correct, which DS has the CPU port is arbitrary.

It also gets messier when Johns finishes reworking my PoC patchset for
multiple CPU ports. You ideally want the correct CPU port for this
host interface.

     Andrew