Re: [PATCH net 1/2] net: phy: restore timestamping state on probe failure

From: Andrew Lunn

Date: Thu Nov 19 2026 - 08:24:02 EST


On Wed, Nov 18, 2026 at 05:34:05AM -0500, Kimberly Morris wrote:
> A PHY driver can install a devm-backed mii_timestamper and select it as
> the default before its probe sequence has completed. If a later probe
> step fails, the driver core releases the driver's devres, but the
> phy_device retains both timestamping fields.
>
> If the generic PHY driver later attaches, skb_defer_rx_timestamp() can
> dereference the freed mii_timestamper. This also affects non-PTP packets
> because the receive path tests hwtstamp_set before classifying the
> packet.

This is very theoretical. It means root has unloaded the device
specific driver leaving just genphy. Very unlikely.

> Fixes: 39db6be781cd ("net: phy: broadcom: Add PTP support for some
> Broadcom PHYs.")
> Cc: stable@xxxxxxxxxxxxxxx

Since this never happens, it bothers nobody, net-next.

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -3812,8 +3812,10 @@ EXPORT_SYMBOL_GPL(fwnode_get_phy_node);
> static int phy_probe(struct device *dev)
> {
> struct phy_device *phydev = to_phy_device(dev);
> + struct mii_timestamper *mii_ts = phydev->mii_ts;
> struct device_driver *drv = phydev->mdio.dev.driver;
> struct phy_driver *phydrv = to_phy_driver(drv);
> + bool default_timestamp = phydev->default_timestamp;
> int err = 0;
>
> phydev->drv = phydrv;
> @@ -3951,6 +3953,9 @@ static int phy_probe(struct device *dev)
> phydev->drv->remove(phydev);
>
> out_reset:
> + phydev->mii_ts = mii_ts;
> + phydev->default_timestamp = default_timestamp;
> +

The basic fix is wrong. If probe fails, everything done so far should
be undone. When probe is entered, there is no stamper. If probe exists
with an error, there should be no stamper.

Andrew