net: macb: initialize PTP state before registering clock
Subsystems (4)
PATCH v3 1/1 net: macb: initialize PTP state before registering clock
gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready.
In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it.
This race is theoretical and has not been observed in practice.
Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock.
---
v3:
- State that the race is theoretical and has not been observed in practice.
- Add Reviewed-by trailers from Théo Lebrun and Vadim Fedorenko.
- Use the documented Assisted-by format.
drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5881,6 +5881,7 @@ static int macb_probe(struct platform_device *pdev) }spin_lock_init (&bp->lock);spin_lock_init (&bp->stats_lock); +spin_lock_init (&bp->tsu_clk_lock);/* setup capabilities */ macb_configure_caps (bp, macb_config);
drivers/net/ethernet/cadence/macb_ptp.c +1 -5
@@ -334,6 +334,7 @@ void gem_ptp_init(struct net_device *netdev) bp->tsu_rate = bp->ptp_info->get_tsu_rate (bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj ();gem_ptp_init_timer (bp); +gem_ptp_init_tsu (bp); bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &netdev->dev);if (IS_ERR (bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n",
@@ -345,10 +346,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" ,GEM_PTP_TIMER_NAME ); }
@@ -467,4 +464,3 @@ int gem_set_hwtst(struct net_device *netdev,return 0 ; } -
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Tue, 8 Sep 2026 18:39:24 +0800 you wrote:
gem_ptp_init()registers the PTP clock before initializingbp->tsu_clk_lockand the TSU hardware. Sinceptp_clock_register()publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready.In addition,
gem_ptp_init()is called from both the interface open and resume paths. Reinitializingtsu_clk_lockthere can reset the lock while timestamp processing is using it.[...]
Here is the summary with links:
- [net,v3] net: macb: initialize PTP state before registering clock
https://git.kernel.org/netdev/net/c/e1406330d70e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html