hv_netvsc: Fix error handling in netvsc_attach()
authorHaiyang Zhang <haiyangz@microsoft.com>
Wed, 30 Oct 2019 15:32:13 +0000 (15:32 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 31 Oct 2019 01:17:36 +0000 (18:17 -0700)
If rndis_filter_open() fails, we need to remove the rndis device created
in earlier steps, before returning an error code. Otherwise, the retry of
netvsc_attach() from its callers will fail and hang.

Fixes: 7b2ee50c0cd5 ("hv_netvsc: common detach logic")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/hyperv/netvsc_drv.c

index bab7c1f84dfd62b13aa3d32e54fd656918de6bd1..963509add611ffc1de2f2ebbbfe13f9f58cb5d08 100644 (file)
@@ -982,7 +982,7 @@ static int netvsc_attach(struct net_device *ndev,
        if (netif_running(ndev)) {
                ret = rndis_filter_open(nvdev);
                if (ret)
-                       return ret;
+                       goto err;
 
                rdev = nvdev->extension;
                if (!rdev->link_state)
@@ -990,6 +990,13 @@ static int netvsc_attach(struct net_device *ndev,
        }
 
        return 0;
+
+err:
+       netif_device_detach(ndev);
+
+       rndis_filter_device_remove(hdev, nvdev);
+
+       return ret;
 }
 
 static int netvsc_set_channels(struct net_device *net,