Skip to content

Commit bc992ab

Browse files
committed
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/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 7e554f3 + 092263a commit bc992ab

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

drivers/net/phy/dp83640.c

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -953,30 +953,6 @@ static void decode_status_frame(struct dp83640_private *dp83640,
953953
}
954954
}
955955

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-
980956
static void dp83640_clock_init(struct dp83640_clock *clock, struct mii_bus *bus)
981957
{
982958
INIT_LIST_HEAD(&clock->list);
@@ -1479,6 +1455,7 @@ static void dp83640_remove(struct phy_device *phydev)
14791455
struct dp83640_clock *clock;
14801456
struct list_head *this, *next;
14811457
struct dp83640_private *tmp, *dp83640 = phydev->priv;
1458+
bool remove_clock = false;
14821459

14831460
if (phydev->mdio.addr == BROADCAST_ADDR)
14841461
return;
@@ -1506,11 +1483,27 @@ static void dp83640_remove(struct phy_device *phydev)
15061483
}
15071484
}
15081485

1486+
if (!clock->chosen && list_empty(&clock->phylist))
1487+
remove_clock = true;
1488+
15091489
dp83640_clock_put(clock);
15101490
kfree(dp83640);
1491+
1492+
if (remove_clock) {
1493+
mutex_lock(&phyter_clocks_lock);
1494+
list_del(&clock->list);
1495+
mutex_unlock(&phyter_clocks_lock);
1496+
1497+
mutex_destroy(&clock->extreg_lock);
1498+
mutex_destroy(&clock->clock_lock);
1499+
put_device(&clock->bus->dev);
1500+
kfree(clock->caps.pin_config);
1501+
kfree(clock);
1502+
}
15111503
}
15121504

1513-
static struct phy_driver dp83640_driver = {
1505+
static struct phy_driver dp83640_driver[] = {
1506+
{
15141507
.phy_id = DP83640_PHY_ID,
15151508
.phy_id_mask = 0xfffffff0,
15161509
.name = "NatSemi DP83640",
@@ -1521,26 +1514,15 @@ static struct phy_driver dp83640_driver = {
15211514
.config_init = dp83640_config_init,
15221515
.config_intr = dp83640_config_intr,
15231516
.handle_interrupt = dp83640_handle_interrupt,
1517+
},
15241518
};
15251519

1526-
static int __init dp83640_init(void)
1527-
{
1528-
return phy_driver_register(&dp83640_driver, THIS_MODULE);
1529-
}
1530-
1531-
static void __exit dp83640_exit(void)
1532-
{
1533-
dp83640_free_clocks();
1534-
phy_driver_unregister(&dp83640_driver);
1535-
}
1520+
module_phy_driver(dp83640_driver);
15361521

15371522
MODULE_DESCRIPTION("National Semiconductor DP83640 PHY driver");
15381523
MODULE_AUTHOR("Richard Cochran <[email protected]>");
15391524
MODULE_LICENSE("GPL");
15401525

1541-
module_init(dp83640_init);
1542-
module_exit(dp83640_exit);
1543-
15441526
static const struct mdio_device_id __maybe_unused dp83640_tbl[] = {
15451527
{ DP83640_PHY_ID, 0xfffffff0 },
15461528
{ }

drivers/net/phy/phy_device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,8 @@ static int phy_remove(struct device *dev)
35443544
* @new_driver: new phy_driver to register
35453545
* @owner: module owning this PHY
35463546
*/
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)
35483549
{
35493550
int retval;
35503551

@@ -3587,7 +3588,6 @@ int phy_driver_register(struct phy_driver *new_driver, struct module *owner)
35873588

35883589
return 0;
35893590
}
3590-
EXPORT_SYMBOL(phy_driver_register);
35913591

35923592
int phy_drivers_register(struct phy_driver *new_driver, int n,
35933593
struct module *owner)

include/linux/phy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,6 @@ static inline int phy_read_status(struct phy_device *phydev)
20322032

20332033
void phy_driver_unregister(struct phy_driver *drv);
20342034
void phy_drivers_unregister(struct phy_driver *drv, int n);
2035-
int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
20362035
int phy_drivers_register(struct phy_driver *new_driver, int n,
20372036
struct module *owner);
20382037
void phy_error(struct phy_device *phydev);

0 commit comments

Comments
 (0)