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

of_mdio: add helper to deregister fixed-link PHYs

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>

authored by

Johan Hovold and committed by
David S. Miller
3f65047c 0d8f3c67

+23 -24
+2 -14
drivers/net/ethernet/ti/cpsw.c
··· 2459 2459 if (strcmp(slave_node->name, "slave")) 2460 2460 continue; 2461 2461 2462 - if (of_phy_is_fixed_link(slave_node)) { 2463 - struct phy_device *phydev; 2464 - 2465 - phydev = of_phy_find_device(slave_node); 2466 - if (phydev) { 2467 - fixed_phy_unregister(phydev); 2468 - /* Put references taken by 2469 - * of_phy_find_device() and 2470 - * of_phy_register_fixed_link(). 2471 - */ 2472 - phy_device_free(phydev); 2473 - phy_device_free(phydev); 2474 - } 2475 - } 2462 + if (of_phy_is_fixed_link(slave_node)) 2463 + of_phy_deregister_fixed_link(slave_node); 2476 2464 2477 2465 of_node_put(slave_data->phy_node); 2478 2466
+15
drivers/of/of_mdio.c
··· 490 490 return -ENODEV; 491 491 } 492 492 EXPORT_SYMBOL(of_phy_register_fixed_link); 493 + 494 + void of_phy_deregister_fixed_link(struct device_node *np) 495 + { 496 + struct phy_device *phydev; 497 + 498 + phydev = of_phy_find_device(np); 499 + if (!phydev) 500 + return; 501 + 502 + fixed_phy_unregister(phydev); 503 + 504 + put_device(&phydev->mdio.dev); /* of_phy_find_device() */ 505 + phy_device_free(phydev); /* fixed_phy_register() */ 506 + } 507 + EXPORT_SYMBOL(of_phy_deregister_fixed_link);
+4
include/linux/of_mdio.h
··· 29 29 extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np); 30 30 extern int of_mdio_parse_addr(struct device *dev, const struct device_node *np); 31 31 extern int of_phy_register_fixed_link(struct device_node *np); 32 + extern void of_phy_deregister_fixed_link(struct device_node *np); 32 33 extern bool of_phy_is_fixed_link(struct device_node *np); 33 34 34 35 #else /* CONFIG_OF */ ··· 83 82 static inline int of_phy_register_fixed_link(struct device_node *np) 84 83 { 85 84 return -ENOSYS; 85 + } 86 + static inline void of_phy_deregister_fixed_link(struct device_node *np) 87 + { 86 88 } 87 89 static inline bool of_phy_is_fixed_link(struct device_node *np) 88 90 {
+2 -10
net/dsa/dsa.c
··· 506 506 507 507 void dsa_cpu_dsa_destroy(struct device_node *port_dn) 508 508 { 509 - struct phy_device *phydev; 510 - 511 - if (of_phy_is_fixed_link(port_dn)) { 512 - phydev = of_phy_find_device(port_dn); 513 - if (phydev) { 514 - fixed_phy_unregister(phydev); 515 - put_device(&phydev->mdio.dev); 516 - phy_device_free(phydev); 517 - } 518 - } 509 + if (of_phy_is_fixed_link(port_dn)) 510 + of_phy_deregister_fixed_link(port_dn); 519 511 } 520 512 521 513 static void dsa_switch_destroy(struct dsa_switch *ds)