Staging: hv: netvsc: Introduce state to manage the lifecycle of net device
Introduce state to manage the lifecycle of net device.
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
diff --git a/drivers/staging/hv/hyperv_net.h b/drivers/staging/hv/hyperv_net.h
index 5782fea..0b347c1 100644
--- a/drivers/staging/hv/hyperv_net.h
+++ b/drivers/staging/hv/hyperv_net.h
@@ -371,6 +371,7 @@
atomic_t refcnt;
atomic_t num_outstanding_sends;
+ bool destroy;
/*
* List of free preallocated hv_netvsc_packet to represent receive
* packet
diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
index 7722102..8eb4039 100644
--- a/drivers/staging/hv/netvsc.c
+++ b/drivers/staging/hv/netvsc.c
@@ -43,6 +43,7 @@
/* Set to 2 to allow both inbound and outbound traffic */
atomic_set(&net_device->refcnt, 2);
+ net_device->destroy = false;
net_device->dev = device;
device->ext = net_device;
@@ -396,6 +397,7 @@
{
struct netvsc_device *net_device;
struct hv_netvsc_packet *netvsc_packet, *pos;
+ unsigned long flags;
/* Stop outbound traffic ie sends and receives completions */
net_device = release_outbound_net_device(device);
@@ -404,6 +406,10 @@
return -ENODEV;
}
+ spin_lock_irqsave(&device->channel->inbound_lock, flags);
+ net_device->destroy = true;
+ spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
+
/* Wait for all send completions */
while (atomic_read(&net_device->num_outstanding_sends)) {
dev_err(&device->device,