@@ -342,9 +342,9 @@ static void
isert_device_put(struct isert_device *device)
{
mutex_lock(&device_list_mutex);
- device->refcount--;
- isert_info("device %p refcount %d\n", device, device->refcount);
- if (!device->refcount) {
+ isert_info("device %p refcount %d\n", device,
+ refcount_read(&device->refcount));
+ if (refcount_dec_and_test(&device->refcount)) {
isert_free_device_ib_res(device);
list_del(&device->dev_node);
kfree(device);
@@ -361,9 +361,9 @@ isert_device_get(struct rdma_cm_id *cma_id)
mutex_lock(&device_list_mutex);
list_for_each_entry(device, &device_list, dev_node) {
if (device->ib_device->node_guid == cma_id->device->node_guid) {
- device->refcount++;
+ refcount_inc(&device->refcount);
isert_info("Found iser device %p refcount %d\n",
- device, device->refcount);
+ device, refcount_read(&device->refcount));
mutex_unlock(&device_list_mutex);
return device;
}
@@ -386,10 +386,10 @@ isert_device_get(struct rdma_cm_id *cma_id)
return ERR_PTR(ret);
}
- device->refcount++;
+ refcount_inc(&device->refcount);
list_add_tail(&device->dev_node, &device_list);
isert_info("Created a new iser device %p refcount %d\n",
- device, device->refcount);
+ device, refcount_read(&device->refcount));
mutex_unlock(&device_list_mutex);
return device;
@@ -2,6 +2,7 @@
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/in6.h>
+#include <linux/refcount.h>
#include <rdma/ib_verbs.h>
#include <rdma/rdma_cm.h>
#include <rdma/rw.h>
@@ -183,7 +184,7 @@ struct isert_comp {
struct isert_device {
bool pi_capable;
- int refcount;
+ refcount_t refcount;
struct mutex comp_mutex;
struct ib_device *ib_device;
struct ib_pd *pd;
refcount_t has a nice overflow runtime protection on x86 and clear API, so prefer it instead of a raw integer. Signed-off-by: Roman Pen <roman.penyaev@profitbricks.de> Cc: Christoph Hellwig <hch@lst.de> Cc: Steve Wise <swise@opengridcomputing.com> Cc: Bart Van Assche <bart.vanassche@sandisk.com> Cc: Sagi Grimberg <sagi@grimberg.me> Cc: Doug Ledford <dledford@redhat.com> Cc: target-devel@vger.kernel.org --- drivers/infiniband/ulp/isert/ib_isert.c | 14 +++++++------- drivers/infiniband/ulp/isert/ib_isert.h | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-)