Re: [PATCH net-next v3 1/3] rust: core abstractions for network PHY drivers
From: Andrew Lunn <andrew@lunn.ch>
Date: 2023-10-14 22:33:55
Also in:
rust-for-linux
From: Andrew Lunn <andrew@lunn.ch>
Date: 2023-10-14 22:33:55
Also in:
rust-for-linux
On Sat, Oct 14, 2023 at 10:18:58PM +0000, Benno Lossin wrote:
On 14.10.23 23:55, Andrew Lunn wrote:quoted
quoted
quoted
The PHY driver asks the state from the abstractions then the abstractions ask the state from PHYLIB. So when the abstractions get a bad value from PHYLIB, the abstractions must return something to the PHY driver. As I wrote, the abstractions return a random value or an error. In either way, probably the system cannot continue.Sure then let the system BUG if it cannot continue. I think that allowing UB is worse than BUGing.There is nothing a PHY driver can do which justifies calling BUG().I was mostly replying to Tomonori's comment "In either way, probably the system cannot continue.". I think that defaulting the value to `PHY_ERROR` when it is out of range to be a lot better way of handling this.
You could actually call phy_error(phydev); That will set the state to PHY_ERROR and transition the state machine to put the link down. https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/phy.c#L1213 Its not documented for this use case, its more intended for the hardware has a problem, and stopped talking to us. But if phylib itself is messed up, it would seem like a reasonable way to try to recover. It will dump the stack as well. Andrew