From patchwork Mon Jun 4 12:30:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Pen X-Patchwork-Id: 10446509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 09D7660375 for ; Mon, 4 Jun 2018 12:30:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7FFD28E5D for ; Mon, 4 Jun 2018 12:30:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4FED28ED5; Mon, 4 Jun 2018 12:30:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64A8B28E66 for ; Mon, 4 Jun 2018 12:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752692AbeFDMa0 (ORCPT ); Mon, 4 Jun 2018 08:30:26 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38629 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752643AbeFDMaZ (ORCPT ); Mon, 4 Jun 2018 08:30:25 -0400 Received: by mail-wr0-f194.google.com with SMTP id 94-v6so43040766wrf.5 for ; Mon, 04 Jun 2018 05:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XiRt0lUhCoNtzceyv9zswV1FvoJ5Xh6aKlmBdSbGWwQ=; b=RyP+c56Lh1T9CGiehezPDrrZ21eQB20s2HJq9cE99PvObjLxrs4B2SUs30pWn5c+Br 49jZchne3CqjAfTHlGV2v+32FXdceF62yjxvlmRab4gnvXssgpzawNRlA6r2jTe2gA2S z3rIQPNkiJNfNSIn3J4LQisZya1gcoG2O4MPqr3NOkcm8FfJp51YZYTUZa4Yhb5W8Ul3 WMkcA4Xueig1kMzRK8TBpvr8pGMO2NWiEkiCOx76TUU7Q2HiG0Cidt/gucFgtbdKI+qm BemAvonBsWUUzRTXFrseiMUHmzS/NjPntCdoZAQF15Et3kJo7XNHvy0LGs+H/vfxjdoj SqHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XiRt0lUhCoNtzceyv9zswV1FvoJ5Xh6aKlmBdSbGWwQ=; b=WJh31+7CGX9TP54B50cke5yeGHNeNhS0oC+0KRkvh2P9GnXNb2qmRUq+DGyWRe6bJG L2G8xLayYcD1GrxuLq9JPt8uRjlUQBcm+ERF3oQ/1I7p4u/4EqE8jookYpjp5pPeqAuC R8lXwhB1WFoNN94t/TLwYVd2zGttJIjn4ikw9413SINeuABgnWjxVRjxjis1YhXSbkk5 yTJx3I4+tblq8f1AVS+h7jSpjEEuILaXTy1T62Odm5NIJ0KlpX2ulsGrDdgPWUVCY0SB KyXALp765MdOJz1mx3t96jilM5wf+jFSk8W1RJbTNCRZRX+HbBw2shZd5pAvCyVwnYum RB2g== X-Gm-Message-State: ALKqPwcxlSwuU2/8KfOpknA/5H4F6+fomEw5YIj6NGbT5m8wSrDFksPl dqS7cfIbJnMYsF/3N9o5fD0YEQ== X-Google-Smtp-Source: ADUXVKJ4iPxpPQY7CwvNMwptT77RfFux/4fRxB1/vx2upbtJVD64lLIMBqmoaybQdL9ApRDiE6lSmw== X-Received: by 2002:adf:d086:: with SMTP id y6-v6mr16611388wrh.152.1528115424117; Mon, 04 Jun 2018 05:30:24 -0700 (PDT) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id s9-v6sm70578wmc.34.2018.06.04.05.30.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 05:30:23 -0700 (PDT) From: Roman Pen To: linux-rdma@vger.kernel.org Cc: Roman Pen , Roman Pen , Christoph Hellwig , Steve Wise , Bart Van Assche , Sagi Grimberg , Doug Ledford , target-devel@vger.kernel.org Subject: [PATCH v2 7/8] IB/isert: use refcount_t instead of just a raw integer Date: Mon, 4 Jun 2018 14:30:02 +0200 Message-Id: <20180604123003.24748-8-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180604123003.24748-1-roman.penyaev@profitbricks.com> References: <20180604123003.24748-1-roman.penyaev@profitbricks.com> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Christoph Hellwig Cc: Steve Wise Cc: Bart Van Assche Cc: Sagi Grimberg Cc: Doug Ledford 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(-) diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c index b7da1a6ea32c..08dc9d27e5b1 100644 --- a/drivers/infiniband/ulp/isert/ib_isert.c +++ b/drivers/infiniband/ulp/isert/ib_isert.c @@ -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; diff --git a/drivers/infiniband/ulp/isert/ib_isert.h b/drivers/infiniband/ulp/isert/ib_isert.h index 9f0b0a6d87cf..ff08bf29dce4 100644 --- a/drivers/infiniband/ulp/isert/ib_isert.h +++ b/drivers/infiniband/ulp/isert/ib_isert.h @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -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;