staging: ks7010: fix error paths in ks7010_sdio_remove function
authorSergio Paracuellos <sergio.paracuellos@gmail.com>
Mon, 23 Apr 2018 13:44:45 +0000 (15:44 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Apr 2018 13:47:23 +0000 (15:47 +0200)
This commit reviews and fixes error paths in ks7010_sdio_remove
driver function. It change logic to handle error directly
after priv dereference to avoid one level indentation. It also
removes a temporal netdev variable which wasn't being used in all
of the function calls. Also if send_stop_request call fails it
was making a direct 'return' instead of doing a properly cleaning.
Because of this a new 'err_free_card' label has been added.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ks7010/ks7010_sdio.c

index 1d569ef96f45de248e1ea52997d0a7976b9c98e3..5293b48c3086317b1e9a3701c71a71d460d24337 100644 (file)
@@ -1112,39 +1112,39 @@ static void ks7010_sdio_remove(struct sdio_func *func)
                return;
 
        priv = card->priv;
-       if (priv) {
-               struct net_device *netdev = priv->net_dev;
+       if (!priv)
+               goto err_free_card;
 
-               ks_wlan_net_stop(netdev);
+       ks_wlan_net_stop(priv->net_dev);
 
-               /* interrupt disable */
-               sdio_claim_host(func);
-               sdio_writeb(func, 0, INT_ENABLE_REG, &ret);
-               sdio_writeb(func, 0xff, INT_PENDING_REG, &ret);
-               sdio_release_host(func);
+       /* interrupt disable */
+       sdio_claim_host(func);
+       sdio_writeb(func, 0, INT_ENABLE_REG, &ret);
+       sdio_writeb(func, 0xff, INT_PENDING_REG, &ret);
+       sdio_release_host(func);
 
-               ret = send_stop_request(func);
-               if (ret)        /* memory allocation failure */
-                       return;
+       ret = send_stop_request(func);
+       if (ret)        /* memory allocation failure */
+               goto err_free_card;
 
-               if (priv->wq) {
-                       flush_workqueue(priv->wq);
-                       destroy_workqueue(priv->wq);
-               }
+       if (priv->wq) {
+               flush_workqueue(priv->wq);
+               destroy_workqueue(priv->wq);
+       }
 
-               hostif_exit(priv);
+       hostif_exit(priv);
 
-               unregister_netdev(netdev);
+       unregister_netdev(priv->net_dev);
 
-               trx_device_exit(priv);
-               free_netdev(priv->net_dev);
-               card->priv = NULL;
-       }
+       trx_device_exit(priv);
+       free_netdev(priv->net_dev);
+       card->priv = NULL;
 
        sdio_claim_host(func);
        sdio_release_irq(func);
        sdio_disable_func(func);
        sdio_release_host(func);
+err_free_card:
        sdio_set_drvdata(func, NULL);
        kfree(card);
 }