]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
staging: wilc1000: refactor wilc_netdev_init() to handle memory free in error path
authorAjay Singh <ajay.kathat@microchip.com>
Tue, 4 Sep 2018 06:39:41 +0000 (12:09 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 10 Sep 2018 16:06:51 +0000 (18:06 +0200)
Refactor the wilc_netdev_init() to cleanup the memory for error
scenario and remove unnecessary 'dev' pointer check.

Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wilc1000/linux_wlan.c
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c

index d7d43fdf55ec61b69358abfa9f1cf918540f96ad..91a45a7c10efdb7e0698adca17e91e6ca20b1541 100644 (file)
@@ -1073,10 +1073,8 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
        INIT_LIST_HEAD(&wl->rxq_head.list);
 
        wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
-       if (!wl->hif_workqueue) {
-               kfree(wl);
-               return -ENOMEM;
-       }
+       if (!wl->hif_workqueue)
+               goto free_wl;
 
        register_inetaddr_notifier(&g_dev_notifier);
 
@@ -1085,7 +1083,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 
                ndev = alloc_etherdev(sizeof(struct wilc_vif));
                if (!ndev)
-                       return -ENOMEM;
+                       goto free_ndev;
 
                vif = netdev_priv(ndev);
                memset(vif, 0, sizeof(struct wilc_vif));
@@ -1106,15 +1104,13 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
                ndev->netdev_ops = &wilc_netdev_ops;
 
                wdev = wilc_create_wiphy(ndev, dev);
-
-               if (dev)
-                       SET_NETDEV_DEV(ndev, dev);
-
                if (!wdev) {
                        netdev_err(ndev, "Can't register WILC Wiphy\n");
-                       return -1;
+                       goto free_ndev;
                }
 
+               SET_NETDEV_DEV(ndev, dev);
+
                vif->ndev->ieee80211_ptr = wdev;
                vif->ndev->ml_priv = vif;
                wdev->netdev = vif->ndev;
@@ -1125,11 +1121,29 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 
                ret = register_netdev(ndev);
                if (ret)
-                       return ret;
+                       goto free_ndev;
 
                vif->iftype = STATION_MODE;
                vif->mac_opened = 0;
        }
 
        return 0;
+
+free_ndev:
+       for (; i >= 0; i--) {
+               if (wl->vif[i]) {
+                       if (wl->vif[i]->iftype == STATION_MODE)
+                               unregister_netdev(wl->vif[i]->ndev);
+
+                       if (wl->vif[i]->ndev) {
+                               wilc_free_wiphy(wl->vif[i]->ndev);
+                               free_netdev(wl->vif[i]->ndev);
+                       }
+               }
+       }
+       unregister_inetaddr_notifier(&g_dev_notifier);
+       destroy_workqueue(wl->hif_workqueue);
+free_wl:
+       kfree(wl);
+       return -ENOMEM;
 }
index d103dce223bc82dd48e8e19845ded9dc9d5ac7c2..37c26d465bcf4812dcff911d6c466bbd5246ddb2 100644 (file)
@@ -2145,8 +2145,12 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net,
        set_wiphy_dev(wdev->wiphy, dev);
 
        ret = wiphy_register(wdev->wiphy);
-       if (ret)
+       if (ret) {
                netdev_err(net, "Cannot register wiphy device\n");
+               wiphy_free(wdev->wiphy);
+               kfree(wdev);
+               return NULL;
+       }
 
        priv->dev = net;
        return wdev;