[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1310752065-27895-95-git-send-email-kys@microsoft.com>
Date: Fri, 15 Jul 2011 10:47:23 -0700
From: "K. Y. Srinivasan" <kys@...rosoft.com>
To: gregkh@...e.de, linux-kernel@...r.kernel.org,
devel@...uxdriverproject.org, virtualization@...ts.osdl.org
Cc: "K. Y. Srinivasan" <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>
Subject: [PATCH 095/117] Staging: hv: netvsc: Leverage the spinlock to manage refcnt
Now that we have a spin lock protecting the device pointer, use it to also
protect the refrence count.
Signed-off-by: K. Y. Srinivasan <kys@...rosoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@...rosoft.com>
---
drivers/staging/hv/hyperv_net.h | 2 +-
drivers/staging/hv/netvsc.c | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/hv/hyperv_net.h b/drivers/staging/hv/hyperv_net.h
index 0b347c1..5c8fc31 100644
--- a/drivers/staging/hv/hyperv_net.h
+++ b/drivers/staging/hv/hyperv_net.h
@@ -369,7 +369,7 @@ struct nvsp_message {
struct netvsc_device {
struct hv_device *dev;
- atomic_t refcnt;
+ int refcnt;
atomic_t num_outstanding_sends;
bool destroy;
/*
diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
index 0411332..3b234a3 100644
--- a/drivers/staging/hv/netvsc.c
+++ b/drivers/staging/hv/netvsc.c
@@ -41,7 +41,7 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device)
return NULL;
/* Set to 2 to allow both inbound and outbound traffic */
- atomic_set(&net_device->refcnt, 2);
+ net_device->refcnt = 2;
net_device->destroy = false;
net_device->dev = device;
@@ -58,9 +58,9 @@ static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
spin_lock_irqsave(&device->ext_lock, flags);
net_device = device->ext;
- if (net_device && (atomic_read(&net_device->refcnt) > 1) &&
+ if (net_device && (net_device->refcnt > 1) &&
!net_device->destroy)
- atomic_inc(&net_device->refcnt);
+ net_device->refcnt++;
else
net_device = NULL;
spin_unlock_irqrestore(&device->ext_lock, flags);
@@ -76,8 +76,8 @@ static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
spin_lock_irqsave(&device->ext_lock, flags);
net_device = device->ext;
- if (net_device && atomic_read(&net_device->refcnt))
- atomic_inc(&net_device->refcnt);
+ if (net_device && net_device->refcnt)
+ net_device->refcnt++;
else
net_device = NULL;
@@ -94,7 +94,7 @@ static void put_net_device(struct hv_device *device)
net_device = device->ext;
- atomic_dec(&net_device->refcnt);
+ net_device->refcnt--;
spin_unlock_irqrestore(&device->ext_lock, flags);
}
@@ -385,7 +385,7 @@ int netvsc_device_remove(struct hv_device *device)
spin_unlock_irqrestore(&device->ext_lock, flags);
return -ENODEV;
}
- atomic_dec(&net_device->refcnt);
+ net_device->refcnt--;
net_device->destroy = true;
spin_unlock_irqrestore(&device->ext_lock, flags);
@@ -401,7 +401,7 @@ int netvsc_device_remove(struct hv_device *device)
netvsc_disconnect_vsp(net_device);
spin_lock_irqsave(&device->ext_lock, flags);
- atomic_dec(&net_device->refcnt);
+ net_device->refcnt--;
device->ext = NULL;
spin_unlock_irqrestore(&device->ext_lock, flags);
@@ -414,7 +414,7 @@ int netvsc_device_remove(struct hv_device *device)
* Since the send path is non-blocking, it is reasonable to busy
* wait here.
*/
- while (atomic_read(&net_device->refcnt))
+ while (net_device->refcnt != 0)
udelay(100);
/* At this point, no one should be accessing netDevice except in here */
--
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists