Message ID | daec3f08-6192-ba79-f74b-5beb436cab6c@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 8a8b70b3f2cf1155b164ddf649b3c033085451e4 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next] net: mdio: warn once if addr parameter is invalid in mdiobus_get_phy() | expand |
On Fri, Jan 20, 2023 at 11:18:32PM +0100, Heiner Kallweit wrote: > If mdiobus_get_phy() is called with an invalid addr parameter, then the > caller has a bug. Print a call trace to help identifying the caller. > > Suggested-by: Paolo Abeni <pabeni@redhat.com> > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
Hello: This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <kuba@kernel.org>: On Fri, 20 Jan 2023 23:18:32 +0100 you wrote: > If mdiobus_get_phy() is called with an invalid addr parameter, then the > caller has a bug. Print a call trace to help identifying the caller. > > Suggested-by: Paolo Abeni <pabeni@redhat.com> > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> > --- > drivers/net/phy/mdio_bus.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Here is the summary with links: - [net-next] net: mdio: warn once if addr parameter is invalid in mdiobus_get_phy() https://git.kernel.org/netdev/net-next/c/8a8b70b3f2cf You are awesome, thank you!
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 16e021b47..ed66a1986 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -108,9 +108,10 @@ EXPORT_SYMBOL(mdiobus_unregister_device); struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr) { + bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map); struct mdio_device *mdiodev; - if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map)) + if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr)) return NULL; mdiodev = bus->mdio_map[addr];
If mdiobus_get_phy() is called with an invalid addr parameter, then the caller has a bug. Print a call trace to help identifying the caller. Suggested-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/net/phy/mdio_bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)