if (strcmp(slave_node->name, "slave"))
                        continue;
 
-               if (of_phy_is_fixed_link(slave_node)) {
-                       struct phy_device *phydev;
-
-                       phydev = of_phy_find_device(slave_node);
-                       if (phydev) {
-                               fixed_phy_unregister(phydev);
-                               /* Put references taken by
-                                * of_phy_find_device() and
-                                * of_phy_register_fixed_link().
-                                */
-                               phy_device_free(phydev);
-                               phy_device_free(phydev);
-                       }
-               }
+               if (of_phy_is_fixed_link(slave_node))
+                       of_phy_deregister_fixed_link(slave_node);
 
                of_node_put(slave_data->phy_node);
 
 
        return -ENODEV;
 }
 EXPORT_SYMBOL(of_phy_register_fixed_link);
+
+void of_phy_deregister_fixed_link(struct device_node *np)
+{
+       struct phy_device *phydev;
+
+       phydev = of_phy_find_device(np);
+       if (!phydev)
+               return;
+
+       fixed_phy_unregister(phydev);
+
+       put_device(&phydev->mdio.dev);  /* of_phy_find_device() */
+       phy_device_free(phydev);        /* fixed_phy_register() */
+}
+EXPORT_SYMBOL(of_phy_deregister_fixed_link);
 
 extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
 extern int of_mdio_parse_addr(struct device *dev, const struct device_node *np);
 extern int of_phy_register_fixed_link(struct device_node *np);
+extern void of_phy_deregister_fixed_link(struct device_node *np);
 extern bool of_phy_is_fixed_link(struct device_node *np);
 
 #else /* CONFIG_OF */
 {
        return -ENOSYS;
 }
+static inline void of_phy_deregister_fixed_link(struct device_node *np)
+{
+}
 static inline bool of_phy_is_fixed_link(struct device_node *np)
 {
        return false;
 
 
 void dsa_cpu_dsa_destroy(struct device_node *port_dn)
 {
-       struct phy_device *phydev;
-
-       if (of_phy_is_fixed_link(port_dn)) {
-               phydev = of_phy_find_device(port_dn);
-               if (phydev) {
-                       fixed_phy_unregister(phydev);
-                       put_device(&phydev->mdio.dev);
-                       phy_device_free(phydev);
-               }
-       }
+       if (of_phy_is_fixed_link(port_dn))
+               of_phy_deregister_fixed_link(port_dn);
 }
 
 static void dsa_switch_destroy(struct dsa_switch *ds)