Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265610

[PATCH] net: caif: check return value of alloc_netdev

From Rasmus Villemoes <linux@rasmusvillemoes.dk>
Newsgroups linux.kernel
Subject [PATCH] net: caif: check return value of alloc_netdev
Date 2015-11-09 13:20 +0100
Message-ID <qsTAu-6h4-27@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
Maybe the existing code was supposed to be "if (!ndev)", and dev
cannot be NULL, but then -ENODEV is a slightly odd return
value. Doing both tests seems to be the safe choice.

 drivers/net/caif/caif_spi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/caif/caif_spi.c b/drivers/net/caif/caif_spi.c
index de3962014af7..4721948a92f6 100644
--- a/drivers/net/caif/caif_spi.c
+++ b/drivers/net/caif/caif_spi.c
@@ -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;
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] net: caif: check return value of alloc_netdev Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-09 13:20 +0100
  Re: [PATCH] net: caif: check return value of alloc_netdev David Miller <davem@davemloft.net> - 2015-11-09 17:40 +0100

csiph-web