* [PATCH] net: caif: check return value of alloc_netdev
@ 2015-11-09 12:19 Rasmus Villemoes
2015-11-09 16:31 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Villemoes @ 2015-11-09 12:19 UTC (permalink / raw)
To: Dmitry Tarnyagin; +Cc: Rasmus Villemoes, netdev, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: caif: check return value of alloc_netdev
2015-11-09 12:19 [PATCH] net: caif: check return value of alloc_netdev Rasmus Villemoes
@ 2015-11-09 16:31 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2015-11-09 16:31 UTC (permalink / raw)
To: linux; +Cc: dmitry.tarnyagin, netdev, linux-kernel
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Date: Mon, 9 Nov 2015 13:19:10 +0100
> 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.
This is made painfully impossible to figure out because there seems
to be no in-tree code instantiating platform_device objects for
this caif_spi framework, nor are there even in-tree implementations
of the init_xfer et al. required methods.
So your fix is as good as any, applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-09 16:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 12:19 [PATCH] net: caif: check return value of alloc_netdev Rasmus Villemoes
2015-11-09 16:31 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).