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

Merge branch 'net-phy-stop-exporting-phy_driver_register'

Heiner Kallweit says:

====================
net: phy: stop exporting phy_driver_register

Once the last user of a clock in dp83640 has been removed, the clock should
be removed. So far orphaned clocks are cleaned up in dp83640_free_clocks()
only. Add the logic to remove orphaned clocks in dp83640_remove().
This allows to simplify the code, and use standard macro
module_phy_driver(). dp83640 was the last external user of
phy_driver_register(), so we can stop exporting this function afterwards.
====================

Link: https://patch.msgid.link/b86c2ecc-41f6-4f7f-85db-b7fa684d1fb7@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+22 -41
+20 -38
drivers/net/phy/dp83640.c
··· 953 953 } 954 954 } 955 955 956 - static void dp83640_free_clocks(void) 957 - { 958 - struct dp83640_clock *clock; 959 - struct list_head *this, *next; 960 - 961 - mutex_lock(&phyter_clocks_lock); 962 - 963 - list_for_each_safe(this, next, &phyter_clocks) { 964 - clock = list_entry(this, struct dp83640_clock, list); 965 - if (!list_empty(&clock->phylist)) { 966 - pr_warn("phy list non-empty while unloading\n"); 967 - BUG(); 968 - } 969 - list_del(&clock->list); 970 - mutex_destroy(&clock->extreg_lock); 971 - mutex_destroy(&clock->clock_lock); 972 - put_device(&clock->bus->dev); 973 - kfree(clock->caps.pin_config); 974 - kfree(clock); 975 - } 976 - 977 - mutex_unlock(&phyter_clocks_lock); 978 - } 979 - 980 956 static void dp83640_clock_init(struct dp83640_clock *clock, struct mii_bus *bus) 981 957 { 982 958 INIT_LIST_HEAD(&clock->list); ··· 1455 1479 struct dp83640_clock *clock; 1456 1480 struct list_head *this, *next; 1457 1481 struct dp83640_private *tmp, *dp83640 = phydev->priv; 1482 + bool remove_clock = false; 1458 1483 1459 1484 if (phydev->mdio.addr == BROADCAST_ADDR) 1460 1485 return; ··· 1483 1506 } 1484 1507 } 1485 1508 1509 + if (!clock->chosen && list_empty(&clock->phylist)) 1510 + remove_clock = true; 1511 + 1486 1512 dp83640_clock_put(clock); 1487 1513 kfree(dp83640); 1514 + 1515 + if (remove_clock) { 1516 + mutex_lock(&phyter_clocks_lock); 1517 + list_del(&clock->list); 1518 + mutex_unlock(&phyter_clocks_lock); 1519 + 1520 + mutex_destroy(&clock->extreg_lock); 1521 + mutex_destroy(&clock->clock_lock); 1522 + put_device(&clock->bus->dev); 1523 + kfree(clock->caps.pin_config); 1524 + kfree(clock); 1525 + } 1488 1526 } 1489 1527 1490 - static struct phy_driver dp83640_driver = { 1528 + static struct phy_driver dp83640_driver[] = { 1529 + { 1491 1530 .phy_id = DP83640_PHY_ID, 1492 1531 .phy_id_mask = 0xfffffff0, 1493 1532 .name = "NatSemi DP83640", ··· 1514 1521 .config_init = dp83640_config_init, 1515 1522 .config_intr = dp83640_config_intr, 1516 1523 .handle_interrupt = dp83640_handle_interrupt, 1524 + }, 1517 1525 }; 1518 1526 1519 - static int __init dp83640_init(void) 1520 - { 1521 - return phy_driver_register(&dp83640_driver, THIS_MODULE); 1522 - } 1523 - 1524 - static void __exit dp83640_exit(void) 1525 - { 1526 - dp83640_free_clocks(); 1527 - phy_driver_unregister(&dp83640_driver); 1528 - } 1527 + module_phy_driver(dp83640_driver); 1529 1528 1530 1529 MODULE_DESCRIPTION("National Semiconductor DP83640 PHY driver"); 1531 1530 MODULE_AUTHOR("Richard Cochran <richardcochran@gmail.com>"); 1532 1531 MODULE_LICENSE("GPL"); 1533 - 1534 - module_init(dp83640_init); 1535 - module_exit(dp83640_exit); 1536 1532 1537 1533 static const struct mdio_device_id __maybe_unused dp83640_tbl[] = { 1538 1534 { DP83640_PHY_ID, 0xfffffff0 },
+2 -2
drivers/net/phy/phy_device.c
··· 3544 3544 * @new_driver: new phy_driver to register 3545 3545 * @owner: module owning this PHY 3546 3546 */ 3547 - int phy_driver_register(struct phy_driver *new_driver, struct module *owner) 3547 + static int phy_driver_register(struct phy_driver *new_driver, 3548 + struct module *owner) 3548 3549 { 3549 3550 int retval; 3550 3551 ··· 3588 3587 3589 3588 return 0; 3590 3589 } 3591 - EXPORT_SYMBOL(phy_driver_register); 3592 3590 3593 3591 int phy_drivers_register(struct phy_driver *new_driver, int n, 3594 3592 struct module *owner)
-1
include/linux/phy.h
··· 2032 2032 2033 2033 void phy_driver_unregister(struct phy_driver *drv); 2034 2034 void phy_drivers_unregister(struct phy_driver *drv, int n); 2035 - int phy_driver_register(struct phy_driver *new_driver, struct module *owner); 2036 2035 int phy_drivers_register(struct phy_driver *new_driver, int n, 2037 2036 struct module *owner); 2038 2037 void phy_error(struct phy_device *phydev);