[PATCH] staging: ks7010_sdio: fix NULL pointer dereference and memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



priv is being dereferenced when it is still null, hence there is an
explicit null pointer dereference at line 935: free_netdev(priv->net_dev)

Also, memory allocated for netdev at line 854:
netdev = alloc_etherdev(sizeof(*priv));
is not being free'd, hence there is a memory leak.

Fix this by null checking priv before dererefencing it and free netdev
before return.

Addresses-Coverity-ID: 1467844 ("Explicit null dereferenced")
Signed-off-by: Gustavo A. R. Silva <gustavo@xxxxxxxxxxxxxx>
---
 drivers/staging/ks7010/ks7010_sdio.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
index b8f55a1..f5d4c62 100644
--- a/drivers/staging/ks7010/ks7010_sdio.c
+++ b/drivers/staging/ks7010/ks7010_sdio.c
@@ -932,8 +932,12 @@ static int ks7010_sdio_probe(struct sdio_func *func,
 	return 0;
 
  err_free_netdev:
-	free_netdev(priv->net_dev);
-	card->priv = NULL;
+	if (priv) {
+		free_netdev(priv->net_dev);
+		card->priv = NULL;
+	} else {
+		free_netdev(netdev);
+	}
  err_release_irq:
 	sdio_claim_host(func);
 	sdio_release_irq(func);
-- 
2.7.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux