Commit db9107b4 authored by Dan Carpenter's avatar Dan Carpenter Committed by David S. Miller

mdio_bus: NULL dereference on allocation error

If bus = kzalloc() fails then we end up dereferencing bus when we do
"bus->irq[i] = PHY_POLL;".  The code is a little simpler if we reverse
the NULL check and return directly on failure.

Fixes: e7f4dc35 ('mdio: Move allocation of interrupts into core')
Signed-off-by: default avatarDan Carpenter <>
Reviewed-by: default avatarAndrew Lunn <>
Signed-off-by: default avatarDavid S. Miller <>
parent 9d367edd
......@@ -102,11 +102,12 @@ struct mii_bus *mdiobus_alloc_size(size_t size)
alloc_size = sizeof(*bus);
bus = kzalloc(alloc_size, GFP_KERNEL);
if (bus) {
if (size)
bus->priv = (void *)bus + aligned_size;
if (!bus)
return NULL;
if (size)
bus->priv = (void *)bus + aligned_size;
/* Initialise the interrupts to polling */
for (i = 0; i < PHY_MAX_ADDR; i++)
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