Re: [PATCH net] net: phy: Fix deadlocking in phy_error() invocation

From: Andrew Lunn
Date: Fri Aug 18 2023 - 09:08:57 EST


On Fri, Aug 18, 2023 at 03:54:45PM +0300, Serge Semin wrote:
> static void phy_process_error(struct phy_device *phydev)
> {
> - mutex_lock(&phydev->lock);
> + /* phydev->lock must be held for the state change to be safe */
> + if (!mutex_is_locked(&phydev->lock))
> + phydev_err(phydev, "PHY-device data unsafe context\n");
> +
> phydev->state = PHY_ERROR;
> - mutex_unlock(&phydev->lock);
>
> phy_trigger_machine(phydev);
> }

Thanks for the patch Serge. It looks like a good implementation of
what i suggested. But thinking about it further, if the error ever
appears in somebodies kernel log, there is probably not enough
information to actually fix it. There is no call path. So i think it
should actually use WARN_ON_ONCE() so we get a stack trace.

Sorry for changing my mind.

Andrew

---
pw-bot: cr