Skip to content

Commit 09bd2d7

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
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: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://lore.kernel.org/r/E1qNxvu-00111m-1V@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8540336 commit 09bd2d7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/net/phy/mdio_bus.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,21 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev)
107107
}
108108
EXPORT_SYMBOL(mdiobus_unregister_device);
109109

110-
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
110+
static struct mdio_device *mdiobus_find_device(struct mii_bus *bus, int addr)
111111
{
112112
bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map);
113-
struct mdio_device *mdiodev;
114113

115114
if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr))
116115
return NULL;
117116

118-
mdiodev = bus->mdio_map[addr];
117+
return bus->mdio_map[addr];
118+
}
119119

120+
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
121+
{
122+
struct mdio_device *mdiodev;
123+
124+
mdiodev = mdiobus_find_device(bus, addr);
120125
if (!mdiodev)
121126
return NULL;
122127

@@ -129,7 +134,7 @@ EXPORT_SYMBOL(mdiobus_get_phy);
129134

130135
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr)
131136
{
132-
return bus->mdio_map[addr];
137+
return mdiobus_find_device(bus, addr) != NULL;
133138
}
134139
EXPORT_SYMBOL(mdiobus_is_registered_device);
135140

0 commit comments

Comments
 (0)