Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: caif: check return value of alloc_netdev

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>

authored by

Rasmus Villemoes and committed by
David S. Miller
cfb76d77 3870502a

+5 -2
+5 -2
drivers/net/caif/caif_spi.c
··· 730 730 int res; 731 731 dev = (struct cfspi_dev *)pdev->dev.platform_data; 732 732 733 - ndev = alloc_netdev(sizeof(struct cfspi), "cfspi%d", 734 - NET_NAME_UNKNOWN, cfspi_setup); 735 733 if (!dev) 736 734 return -ENODEV; 735 + 736 + ndev = alloc_netdev(sizeof(struct cfspi), "cfspi%d", 737 + NET_NAME_UNKNOWN, cfspi_setup); 738 + if (!ndev) 739 + return -ENOMEM; 737 740 738 741 cfspi = netdev_priv(ndev); 739 742 netif_stop_queue(ndev);