net: dsa: return early if there is no master
authorMichael Walle <michael@walle.cc>
Wed, 24 Feb 2021 16:40:39 +0000 (17:40 +0100)
committerPriyanka Jain <priyanka.jain@nxp.com>
Fri, 5 Mar 2021 04:55:42 +0000 (10:25 +0530)
It doesn't make sense to have DSA without a master port. Error out early
if there is no master port.

Fixes: fc054d563bfb ("net: Introduce DSA class for Ethernet switches")
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
net/dsa-uclass.c

index 2ce9ddb..88a8ea9 100644 (file)
@@ -280,6 +280,10 @@ static int dsa_port_probe(struct udevice *pdev)
        if (!port_pdata->phy)
                return -ENODEV;
 
+       master = dsa_get_master(dev);
+       if (!master)
+               return -ENODEV;
+
        /*
         * Inherit port's hwaddr from the DSA master, unless the port already
         * has a unique MAC address specified in the environment.
@@ -288,10 +292,6 @@ static int dsa_port_probe(struct udevice *pdev)
        if (!is_zero_ethaddr(env_enetaddr))
                return 0;
 
-       master = dsa_get_master(dev);
-       if (!master)
-               return 0;
-
        master_pdata = dev_get_plat(master);
        eth_pdata = dev_get_plat(pdev);
        memcpy(eth_pdata->enetaddr, master_pdata->enetaddr, ARP_HLEN);