Skip to content

Commit 42e2a9e

Browse files
hkallweitkuba-moo
authored andcommitted
net: phy: dp83640: improve phydev and driver removal handling
Once the last user of a clock 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. Signed-off-by: Heiner Kallweit <[email protected]> Reviewed-by: Maxime Chevallier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7e554f3 commit 42e2a9e

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
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
{ }

0 commit comments

Comments
 (0)