Skip to content

Commit 0452800

Browse files
981213davem330
authored andcommitted
net: dsa: mt7530: fix null pointer dereferencing in port5 setup
The 2nd gmac of mediatek soc ethernet may not be connected to a PHY and a phy-handle isn't always available. Unfortunately, mt7530 dsa driver assumes that the 2nd gmac is always connected to switch port 5 and setup mt7530 according to phy address of 2nd gmac node, causing null pointer dereferencing when phy-handle isn't defined in dts. This commit fix this setup code by checking return value of of_parse_phandle before using it. Fixes: 38f790a ("net: dsa: mt7530: Add support for port 5") Signed-off-by: Chuanhong Guo <[email protected]> Reviewed-by: Vivien Didelot <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Tested-by: René van Dorst <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c85adce commit 0452800

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/net/dsa/mt7530.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,9 @@ mt7530_setup(struct dsa_switch *ds)
14031403
continue;
14041404

14051405
phy_node = of_parse_phandle(mac_np, "phy-handle", 0);
1406+
if (!phy_node)
1407+
continue;
1408+
14061409
if (phy_node->parent == priv->dev->of_node->parent) {
14071410
ret = of_get_phy_mode(mac_np, &interface);
14081411
if (ret && ret != -ENODEV)

0 commit comments

Comments
 (0)