Skip to content

Commit

Permalink
staging: ks7010_sdio: fix NULL pointer dereference and memory leak
Browse files Browse the repository at this point in the history
priv is being explicitly dereferenced when it is still null, when
jumping to goto label err_free_netdev, before it is properly
updated with a valid memory address.

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

The current code looks a bit too complicated and can be replaced
by just directly freeing netdev before return.

Notice that card->priv = NULL isn't required because the next thing
we do to card is kfree(card).

Addresses-Coverity-ID: 1467844 ("Explicit null dereferenced")
Suggested-by: Dan Carpenter <[email protected]>
Signed-off-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
GustavoARSilva authored and gregkh committed Apr 23, 2018
1 parent 95751f1 commit 9962d86
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/staging/ks7010/ks7010_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,7 @@ static int ks7010_sdio_probe(struct sdio_func *func,
return 0;

err_free_netdev:
free_netdev(priv->net_dev);
card->priv = NULL;
free_netdev(netdev);
err_release_irq:
sdio_claim_host(func);
sdio_release_irq(func);
Expand Down

0 comments on commit 9962d86

Please sign in to comment.