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@xxxxxxxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Steve Wise <swise@xxxxxxxxxxxxxxxxxxxxx> Cc: Bart Van Assche <bart.vanassche@xxxxxxxxxxx> Cc: Sagi Grimberg <sagi@xxxxxxxxxxx> Cc: Doug Ledford <dledford@xxxxxxxxxx> --- drivers/infiniband/ulp/iser/iscsi_iser.h | 3 ++- drivers/infiniband/ulp/iser/iser_verbs.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.h b/drivers/infiniband/ulp/iser/iscsi_iser.h index c1ae4aeae2f9..09664e12bd6b 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.h +++ b/drivers/infiniband/ulp/iser/iscsi_iser.h @@ -59,6 +59,7 @@ #include <linux/mutex.h> #include <linux/mempool.h> #include <linux/uio.h> +#include <linux/refcount.h> #include <linux/socket.h> #include <linux/in.h> @@ -376,7 +377,7 @@ struct iser_device { struct ib_pd *pd; struct ib_event_handler event_handler; struct list_head ig_list; - int refcount; + refcount_t refcount; int comps_used; struct iser_comp *comps; const struct iser_reg_ops *reg_ops; diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c index 56b7240a3fc3..786f348e27c1 100644 --- a/drivers/infiniband/ulp/iser/iser_verbs.c +++ b/drivers/infiniband/ulp/iser/iser_verbs.c @@ -522,7 +522,7 @@ struct iser_device *iser_device_find_by_ib_device(struct rdma_cm_id *cma_id) list_add(&device->ig_list, &ig.device_list); inc_refcnt: - device->refcount++; + refcount_inc(&device->refcount); out: mutex_unlock(&ig.device_list_mutex); return device; @@ -532,9 +532,9 @@ struct iser_device *iser_device_find_by_ib_device(struct rdma_cm_id *cma_id) static void iser_device_try_release(struct iser_device *device) { mutex_lock(&ig.device_list_mutex); - device->refcount--; - iser_info("device %p refcount %d\n", device, device->refcount); - if (!device->refcount) { + iser_info("device %p refcount %d\n", device, + refcount_read(&device->refcount)); + if (refcount_dec_and_test(&device->refcount)) { iser_free_device_ib_res(device); list_del(&device->ig_list); kfree(device); -- 2.13.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html