mdio_bus: NULL dereference on allocation error
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 12 Jan 2016 09:34:36 +0000 (12:34 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 12 Jan 2016 16:49:20 +0000 (11:49 -0500)
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: e7f4dc3536a4 ('mdio: Move allocation of interrupts into core')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/mdio_bus.c

index 0be7b3d65f0fd14742d66d3c2bb4439efcba87ef..0cba64f1ecf4089c9b2f95f0c35fa94a50d1cb55 100644 (file)
@@ -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) {
-               bus->state = MDIOBUS_ALLOCATED;
-               if (size)
-                       bus->priv = (void *)bus + aligned_size;
-       }
+       if (!bus)
+               return NULL;
+
+       bus->state = MDIOBUS_ALLOCATED;
+       if (size)
+               bus->priv = (void *)bus + aligned_size;
 
        /* Initialise the interrupts to polling */
        for (i = 0; i < PHY_MAX_ADDR; i++)