RE: [PATCH net 1/2] net: fec: don't leave a stale PTP clock pointer after unregister
From: Wei Fang
Date: Thu Sep 03 2026 - 23:18:51 EST
> fec_drv_remove() calls fec_ptp_stop() before unregister_netdev(), and
> fec_ptp_stop() leaves fep->ptp_clock set after ptp_clock_unregister().
> An ethtool -T issued while the netdev is still registered then reaches
> fec_enet_get_ts_info(), which passes the stale pointer to
> ptp_clock_index() after the clock structure has been freed.
>
> Query the PHC index through ptp_clock_index_by_dev() instead. The lookup
> holds a reference to the matching PTP class device while reading its index,
> so concurrent unregister cannot free it underneath the lookup. It returns
> -1 once no clock is registered. Clear fep->ptp_clock after unregistering
> it as well, so the driver state no longer retains the invalid pointer.
Why not move fec_ptp_stop() after unregister_netdev()?