net: caif: check return value of alloc_netdev
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Mon, 9 Nov 2015 12:19:10 +0000 (13:19 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Nov 2015 16:31:13 +0000 (11:31 -0500)
I don't know if dev can actually be NULL here, but the test should be
above alloc_netdev(), to avoid leaking the struct net_device in case
dev is actually NULL. And of course the return value from alloc_netdev
should be tested.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/caif/caif_spi.c

index de3962014af70c8a979f4cb63b063583ba4927a9..4721948a92f6a1db9cea13d66810041be5ec88e4 100644 (file)
@@ -730,11 +730,14 @@ int cfspi_spi_probe(struct platform_device *pdev)
        int res;
        dev = (struct cfspi_dev *)pdev->dev.platform_data;
 
-       ndev = alloc_netdev(sizeof(struct cfspi), "cfspi%d",
-                           NET_NAME_UNKNOWN, cfspi_setup);
        if (!dev)
                return -ENODEV;
 
+       ndev = alloc_netdev(sizeof(struct cfspi), "cfspi%d",
+                           NET_NAME_UNKNOWN, cfspi_setup);
+       if (!ndev)
+               return -ENOMEM;
+
        cfspi = netdev_priv(ndev);
        netif_stop_queue(ndev);
        cfspi->ndev = ndev;