net: dsa: Fix segmentation fault if master fails to probe
authorSean Anderson <sean.anderson@seco.com>
Thu, 5 May 2022 17:11:36 +0000 (13:11 -0400)
committerTom Rini <trini@konsulko.com>
Wed, 8 Jun 2022 17:59:53 +0000 (13:59 -0400)
If the DSA master fails to probe for whatever reason, then DSA devices
will continue on as if nothing is wrong. This can cause incorrect
behavior. In particular, on sandbox, dsa_sandbox_probe attempts to
access the master's private data. This is only safe to do if the master
has been probed first. Fix this by probing the master after we look it
up, and bailing out if we get an error.

Fixes: fc054d563b ("net: Introduce DSA class for Ethernet switches")
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
net/dsa-uclass.c

index 9ff55a0..3bf4351 100644 (file)
@@ -477,8 +477,10 @@ static int dsa_pre_probe(struct udevice *dev)
                return -ENODEV;
        }
 
-       uclass_find_device_by_ofnode(UCLASS_ETH, pdata->master_node,
-                                    &priv->master_dev);
+       err = uclass_get_device_by_ofnode(UCLASS_ETH, pdata->master_node,
+                                         &priv->master_dev);
+       if (err)
+               return err;
 
        /* Simulate a probing event for the CPU port */
        if (ops->port_probe) {