Skip to content

Commit

Permalink
net: mdio: warn once if addr parameter is invalid in mdiobus_get_phy()
Browse files Browse the repository at this point in the history
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>
Link: https://lore.kernel.org/r/daec3f08-6192-ba79-f74b-5beb436cab6c@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Heiner Kallweit authored and Jakub Kicinski committed Jan 24, 2023
1 parent 62be693 commit 8a8b70b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/phy/mdio_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,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];
Expand Down

0 comments on commit 8a8b70b

Please sign in to comment.