Commit 09bd2d7d authored by Russell King (Oracle)'s avatar Russell King (Oracle) Committed by Jakub Kicinski

net: mdio_bus: validate "addr" for mdiobus_is_registered_device()

mdiobus_is_registered_device() doesn't checking that "addr" was valid
before dereferencing bus->mdio_map[]. Extract the code that checks
this from mdiobus_get_phy(), and use it here as well.
Signed-off-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/E1qNxvu-00111m-1V@rmk-PC.armlinux.org.ukSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8540336a
...@@ -107,16 +107,21 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev) ...@@ -107,16 +107,21 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev)
} }
EXPORT_SYMBOL(mdiobus_unregister_device); EXPORT_SYMBOL(mdiobus_unregister_device);
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr) static struct mdio_device *mdiobus_find_device(struct mii_bus *bus, int addr)
{ {
bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map); bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map);
struct mdio_device *mdiodev;
if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr)) if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr))
return NULL; return NULL;
mdiodev = bus->mdio_map[addr]; return bus->mdio_map[addr];
}
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
{
struct mdio_device *mdiodev;
mdiodev = mdiobus_find_device(bus, addr);
if (!mdiodev) if (!mdiodev)
return NULL; return NULL;
...@@ -129,7 +134,7 @@ EXPORT_SYMBOL(mdiobus_get_phy); ...@@ -129,7 +134,7 @@ EXPORT_SYMBOL(mdiobus_get_phy);
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr) bool mdiobus_is_registered_device(struct mii_bus *bus, int addr)
{ {
return bus->mdio_map[addr]; return mdiobus_find_device(bus, addr) != NULL;
} }
EXPORT_SYMBOL(mdiobus_is_registered_device); EXPORT_SYMBOL(mdiobus_is_registered_device);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment