net: dsa: fix fixed-link-phy device leaks
authorJohan Hovold <johan@kernel.org>
Thu, 24 Nov 2016 18:21:27 +0000 (19:21 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Nov 2016 01:01:15 +0000 (20:01 -0500)
Make sure to drop the reference taken by of_phy_find_device() when
registering and deregistering the fixed-link PHY-device.

Fixes: 39b0c705195e ("net: dsa: Allow configuration of CPU & DSA port
speeds/duplex")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa.c

index a6902c1e2f28f79c609bf511de2781908e2e1abd..cb0091b9959235c7a4b272689c7b7b72c1198ce2 100644 (file)
@@ -233,6 +233,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
                genphy_read_status(phydev);
                if (ds->ops->adjust_link)
                        ds->ops->adjust_link(ds, port, phydev);
+
+               put_device(&phydev->mdio.dev);
        }
 
        return 0;
@@ -509,8 +511,9 @@ void dsa_cpu_dsa_destroy(struct device_node *port_dn)
        if (of_phy_is_fixed_link(port_dn)) {
                phydev = of_phy_find_device(port_dn);
                if (phydev) {
-                       phy_device_free(phydev);
                        fixed_phy_unregister(phydev);
+                       put_device(&phydev->mdio.dev);
+                       phy_device_free(phydev);
                }
        }
 }