[PATCH] net: phy: microchip_rds_ptp: unregister the PTP clock if init fails
From: Wentao Liang
Date: Tue Nov 03 2026 - 05:55:11 EST
mchp_rds_ptp_probe() registers the PTP clock with ptp_clock_register()
and then initializes the hardware with mchp_rds_ptp_init(). The
initialization performs several MDIO writes and can fail, in which case
the function returns an error to the caller without unregistering the
clock that was just registered.
Nothing else releases that clock: the callers abort the PHY probe, and
the clock object allocated by ptp_clock_register(), together with its
character device and sysfs entries, stays around forever.
Unregister the clock on the error path, mirroring what the remove
callbacks of the other PTP capable PHY drivers do.
Fixes: fa51199c5f34 ("net: phy: microchip_rds_ptp : Add rds ptp library for Microchip phys")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/net/phy/microchip_rds_ptp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/microchip_rds_ptp.c b/drivers/net/phy/microchip_rds_ptp.c
index 2ad95d5c9d86..0db6eeb2660c 100644
--- a/drivers/net/phy/microchip_rds_ptp.c
+++ b/drivers/net/phy/microchip_rds_ptp.c
@@ -1318,8 +1318,10 @@ struct mchp_rds_ptp_clock *mchp_rds_ptp_probe(struct phy_device *phydev, u8 mmd,
clock->phydev = phydev;
rc = mchp_rds_ptp_init(clock);
- if (rc < 0)
+ if (rc < 0) {
+ ptp_clock_unregister(clock->ptp_clock);
return ERR_PTR(rc);
+ }
return clock;
}
--
2.34.1