of_mdio: add helper to deregister fixed-link PHYs
authorJohan Hovold <johan@kernel.org>
Mon, 28 Nov 2016 18:24:55 +0000 (19:24 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Nov 2016 04:17:02 +0000 (23:17 -0500)
Add helper to deregister fixed-link PHYs registered using
of_phy_register_fixed_link().

Convert the two drivers that care to deregister their fixed-link PHYs to
use the new helper, but note that most drivers currently fail to do so.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/cpsw.c
drivers/of/of_mdio.c
include/linux/of_mdio.h
net/dsa/dsa.c

index 58947aae31c7ecba94205838b633d2972d68cee2..9f06465126249cb27768fba8fd8e07a61e5e32c4 100644 (file)
@@ -2459,20 +2459,8 @@ static void cpsw_remove_dt(struct platform_device *pdev)
                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);
 
index 5a3145a025470dc4c86f8d191a139a8acb85394f..262281bd68fa3c4d39e13f52eeafea1948d1bd22 100644 (file)
@@ -490,3 +490,18 @@ int of_phy_register_fixed_link(struct device_node *np)
        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);
index 2ab233661ae5da49cac59c33c38433501b1af4b4..a58cca8bcb29d8c9bdcda71538cfa8f25c913916 100644 (file)
@@ -29,6 +29,7 @@ struct phy_device *of_phy_attach(struct net_device *dev,
 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 */
@@ -83,6 +84,9 @@ static inline int of_phy_register_fixed_link(struct device_node *np)
 {
        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;
index cb0091b9959235c7a4b272689c7b7b72c1198ce2..7899919cd9f0e3435828b1cca9e2ef897a75a3b7 100644 (file)
@@ -506,16 +506,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
 
 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)