net: phy: mdio-mux: Check return value of mdiobus_alloc()

mdiobus_alloc() might return NULL, but its return value is not
checked in mdio_mux_init(). This could potentially lead to a NULL
pointer dereference. Fix it by checking the return value

Fixes: 0ca2997d14 ("netdev/of/phy: Add MDIO bus multiplexer support.")
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Tobias Klauser 2015-12-14 13:51:51 +01:00 committed by David S. Miller
parent e5f5d74747
commit 20b08e1a79
1 changed files with 7 additions and 2 deletions

View File

@ -149,9 +149,14 @@ int mdio_mux_init(struct device *dev,
} }
cb->bus_number = v; cb->bus_number = v;
cb->parent = pb; cb->parent = pb;
cb->mii_bus = mdiobus_alloc();
cb->mii_bus->priv = cb;
cb->mii_bus = mdiobus_alloc();
if (!cb->mii_bus) {
ret_val = -ENOMEM;
of_node_put(child_bus_node);
break;
}
cb->mii_bus->priv = cb;
cb->mii_bus->irq = cb->phy_irq; cb->mii_bus->irq = cb->phy_irq;
cb->mii_bus->name = "mdio_mux"; cb->mii_bus->name = "mdio_mux";
snprintf(cb->mii_bus->id, MII_BUS_ID_SIZE, "%x.%x", snprintf(cb->mii_bus->id, MII_BUS_ID_SIZE, "%x.%x",