realtek: fix kernel panic in DSA driver for 5.10
[openwrt/staging/hauke.git] / target / linux / realtek / files-5.10 / drivers / net / dsa / rtl83xx / common.c
index ad69debcc81c2c3142d837c42c950902afd96aa8..25ac2d4679f83dac3022951d69f01d8fb7e1da73 100644 (file)
@@ -302,8 +302,6 @@ static int __init rtl83xx_mdio_probe(struct rtl838x_switch_priv *priv)
                if (of_property_read_u32(dn, "reg", &pn))
                        continue;
 
-               priv->ports[pn].dp = dsa_to_port(priv->ds, pn);
-
                // Check for the integrated SerDes of the RTL8380M first
                if (of_property_read_bool(dn, "phy-is-integrated")
                        && priv->id == 0x8380 && pn >= 24) {
@@ -627,6 +625,14 @@ static int __init rtl83xx_sw_probe(struct platform_device *pdev)
                return err;
        }
 
+       /*
+        * dsa_to_port returns dsa_port from the port list in
+        * dsa_switch_tree, the tree is built when the switch
+        * is registered by dsa_register_switch
+        */
+       for (i = 0; i <= priv->cpu_port; i++)
+               priv->ports[i].dp = dsa_to_port(priv->ds, i);
+
        /* Enable link and media change interrupts. Are the SERDES masks needed? */
        sw_w32_mask(0, 3, priv->r->isr_glb_src);