diff mbox series

[v4,07/16] net: dsa: Fix segmentation fault if master fails to probe

Message ID 20220505171146.557773-8-sean.anderson@seco.com
State Accepted
Commit 2a5af4049ccef538095bff67ce9770711db5ed58
Delegated to: Tom Rini
Headers show
Series Add support for NVMEM API | expand

Commit Message

Sean Anderson May 5, 2022, 5:11 p.m. UTC
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>
---

Changes in v4:
- New

 net/dsa-uclass.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Vladimir Oltean May 18, 2022, 2:29 p.m. UTC | #1
On Thu, May 05, 2022 at 01:11:36PM -0400, Sean Anderson wrote:
> 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>
diff mbox series

Patch

diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index 9ff55a02fb..3bf4351c84 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -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) {