Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ethernet: renesas: ravb: fix fixed-link phydev leaks

Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on initialisation errors and on device
close after having disconnected the PHY.

Fixes: b4bc88a868ed ("ravb: Add fixed-link support")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Johan Hovold and committed by
David S. Miller
9f70eb33 16a67eb3

+14 -3
+14 -3
drivers/net/ethernet/renesas/ravb_main.c
··· 1008 1008 of_node_put(pn); 1009 1009 if (!phydev) { 1010 1010 netdev_err(ndev, "failed to connect PHY\n"); 1011 - return -ENOENT; 1011 + err = -ENOENT; 1012 + goto err_deregister_fixed_link; 1012 1013 } 1013 1014 1014 1015 /* This driver only support 10/100Mbit speeds on Gen3 ··· 1021 1020 err = phy_set_max_speed(phydev, SPEED_100); 1022 1021 if (err) { 1023 1022 netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n"); 1024 - phy_disconnect(phydev); 1025 - return err; 1023 + goto err_phy_disconnect; 1026 1024 } 1027 1025 1028 1026 netdev_info(ndev, "limited PHY to 100Mbit/s\n"); ··· 1033 1033 phy_attached_info(phydev); 1034 1034 1035 1035 return 0; 1036 + 1037 + err_phy_disconnect: 1038 + phy_disconnect(phydev); 1039 + err_deregister_fixed_link: 1040 + if (of_phy_is_fixed_link(np)) 1041 + of_phy_deregister_fixed_link(np); 1042 + 1043 + return err; 1036 1044 } 1037 1045 1038 1046 /* PHY control start function */ ··· 1642 1634 /* Device close function for Ethernet AVB */ 1643 1635 static int ravb_close(struct net_device *ndev) 1644 1636 { 1637 + struct device_node *np = ndev->dev.parent->of_node; 1645 1638 struct ravb_private *priv = netdev_priv(ndev); 1646 1639 struct ravb_tstamp_skb *ts_skb, *ts_skb2; 1647 1640 ··· 1672 1663 if (ndev->phydev) { 1673 1664 phy_stop(ndev->phydev); 1674 1665 phy_disconnect(ndev->phydev); 1666 + if (of_phy_is_fixed_link(np)) 1667 + of_phy_deregister_fixed_link(np); 1675 1668 } 1676 1669 1677 1670 if (priv->chip_id != RCAR_GEN2) {