]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
net: dsa: loop: Check for memory allocation failure
authorChristophe Jaillet <christophe.jaillet@wanadoo.fr>
Sat, 6 May 2017 05:29:45 +0000 (07:29 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 May 2017 18:58:36 +0000 (14:58 -0400)
If 'devm_kzalloc' fails, a NULL pointer will be dereferenced.
Return -ENOMEM instead, as done for some other memory allocation just a
few lines above.

Fixes: 98cd1552ea27 ("net: dsa: Mock-up driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/dsa_loop.c

index f0fc4de4fc9a4854ac6b2d6926ed549fed71ce26..a19e1781e9bbf353bf747d238249f0795f2f59cd 100644 (file)
@@ -256,6 +256,9 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
                return -ENOMEM;
 
        ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
+       if (!ps)
+               return -ENOMEM;
+
        ps->netdev = dev_get_by_name(&init_net, pdata->netdev);
        if (!ps->netdev)
                return -EPROBE_DEFER;