[PATCH net] net: macb: initialize PTP lock before registering clock

From: Runyu Xiao

Date: Sun Aug 30 2026 - 11:35:58 EST


gem_ptp_init() registers the PTP clock before initializing
bp->tsu_clk_lock. ptp_clock_register() publishes the PTP character
device, so a userspace operation can enter a PTP callback as soon as
registration completes. Those callbacks use tsu_clk_lock and can therefore
observe the lock before it has been initialized.

Initialize the lock before registering the PTP clock so all published
callbacks see valid synchronization state.

Fixes: ab91f0a9b5f4 ("net: macb: Add hardware PTP support")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: Codex:GPT-5
Signed-off-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
---
drivers/net/ethernet/cadence/macb_ptp.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c
index e5195d7da..055160c42 100644
--- a/drivers/net/ethernet/cadence/macb_ptp.c
+++ b/drivers/net/ethernet/cadence/macb_ptp.c
@@ -330,6 +330,8 @@ void gem_ptp_init(struct net_device *netdev)

bp->ptp_clock_info = gem_ptp_caps_template;

+ spin_lock_init(&bp->tsu_clk_lock);
+
/* nominal frequency and maximum adjustment in ppb */
bp->tsu_rate = bp->ptp_info->get_tsu_rate(bp);
bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj();
@@ -345,8 +347,6 @@ void gem_ptp_init(struct net_device *netdev)
return;
}

- spin_lock_init(&bp->tsu_clk_lock);
-
gem_ptp_init_tsu(bp);

dev_info(&bp->pdev->dev, "%s ptp clock registered.\n",
@@ -467,4 +467,3 @@ int gem_set_hwtst(struct net_device *netdev,

return 0;
}
-
--
2.34.1