Ignoring the part about how to cleanup this internal phydev for the moment.
> int ksz9477_switch_register(struct ksz_device *dev) > { > - return ksz_switch_register(dev, &ksz9477_dev_ops); > + int ret, i; > + struct phy_device *phydev; > + > + ret = ksz_switch_register(dev, &ksz9477_dev_ops); > + if (ret) > + return ret; > + > + for (i = 0; i < dev->phy_port_cnt; ++i) { > + phydev = dsa_to_port(dev->ds, i)->slave->phydev; There is no guarantee this phydev actually exists, as far as i remember. It will only be allocated for user ports. If a port is not used, i.e. not listed in DT, it won't have a phydev. So you should add a test: if (!dsa_is_user(ds, i)) continue; Otherwise, this now seems correct. Andrew