From patchwork Wed May 23 17:11:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 10421979 X-Patchwork-Delegate: bhelgaas@google.com 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 A15AF60224 for ; Wed, 23 May 2018 17:48:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99E832899C for ; Wed, 23 May 2018 17:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E76428A28; Wed, 23 May 2018 17:48:29 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 29AB12899C for ; Wed, 23 May 2018 17:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933195AbeEWRs1 (ORCPT ); Wed, 23 May 2018 13:48:27 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:38016 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933649AbeEWRs0 (ORCPT ); Wed, 23 May 2018 13:48:26 -0400 Received: by mail-pl0-f66.google.com with SMTP id c11-v6so13477114plr.5 for ; Wed, 23 May 2018 10:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fZbtwR90OzVTlxWBLVcJyRuyBGMvLEPi2panO1ZsUWY=; b=OYLJCnhIx9GxeRK36oa06F0IGtTmWaFP9VM2eIT2zQ9a6GCMg8Trsq9YeZJLIwrozt mc+9sB5VomjzkpeGe6UoBy9vVWSwlhg8Ni4ceISvOVMzPMTx21HYHDZfoRjd2AachOoA p1KS8+rNxIuRmG09OgijtDgQWnHYREg6HfdnxZFzmDf9p1gOtjHeBKyNsP+RRA7qhGHU 9QWWctbkAksWOUun8mn2cAAAhNZMiF8m8/YKjsVre00v3EbN4Wm9ja31hJHfk9awBtJ5 gzGGWOlXMvJDBdjmYnMIR3xqKKmEka+oGaW6A+M+j23rGLXYKXxHRFVwkZBIZR0vAy77 rihA== 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=fZbtwR90OzVTlxWBLVcJyRuyBGMvLEPi2panO1ZsUWY=; b=VHzgfZdwqxJSvG9M2mMbN4IbGRtoW0gON8L3eqm7EWYSOeMPt/4iYU0c88QdM6vac9 Mpl7TDXZUEu9v7CDPOYnxteMXWg6uDFNAubEzQrfibukRBXFZw4nl4YvFH4X1oCpzTck fMdXWB/p0ONxjB5Ap/8FhXKunW0bShGpZ1YWwQQUzwOGhWo4MlL0oISdZr/oNkr89Tf4 vmQ+gzEPboFw7YkwctAZZkssCwzsVarbYWjH+bJ7OQjd+nWpw8SxBQxIdoHgeDidLw0n DSKcya7JnEa3Z5WeQmQymIYHjXF4oguqPO8cnoEfxGRSSpCwIQctFbPTnSdOFRLL38AN oI0g== X-Gm-Message-State: ALKqPwe1S1e9aWGe+b/zRyLNDNs58vT3DmltEnMP4EKh5CjLIl9XIIdo 0YAHCnbTG0AdKegTiGXaGrbEPw== X-Google-Smtp-Source: AB8JxZrObPxT7aOHt1v+J8mIKicNP660hPbkp+Oc6tXxHNzEJ5xPdlQBmFSRdMr7ydCNLc1CUSbPMg== X-Received: by 2002:a17:902:a585:: with SMTP id az5-v6mr3853650plb.79.1527097705611; Wed, 23 May 2018 10:48:25 -0700 (PDT) Received: from xeon-e3.lan (204-195-35-107.wavecable.com. [204.195.35.107]) by smtp.gmail.com with ESMTPSA id y197-v6sm36409118pfg.184.2018.05.23.10.48.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 10:48:24 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: bhelgaas@google.com, kys@microsoft.com, haiyangz@microsoft.com, lorenzo.pieralisi@arm.com Cc: devel@linuxdriverproject.org, linux-pci@vger.kernel.org, Stephen Hemminger Subject: [PATCH 2/3] PCI: hv: convert remove_lock to refcount Date: Wed, 23 May 2018 10:11:13 -0700 Message-Id: <20180523171114.5136-3-sthemmin@microsoft.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523171114.5136-1-sthemmin@microsoft.com> References: <20180523171114.5136-1-sthemmin@microsoft.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use refcount instead of atomic for the reference counting on bus. Refcount is safer because it handles overflow correctly. Signed-off-by: Stephen Hemminger --- drivers/pci/host/pci-hyperv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 505453e23c22..19eb47f58ccb 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -433,7 +433,7 @@ enum hv_pcibus_state { struct hv_pcibus_device { struct pci_sysdata sysdata; enum hv_pcibus_state state; - atomic_t remove_lock; + refcount_t remove_lock; struct hv_device *hdev; resource_size_t low_mmio_space; resource_size_t high_mmio_space; @@ -2441,12 +2441,12 @@ static int hv_send_resources_released(struct hv_device *hdev) static void get_hvpcibus(struct hv_pcibus_device *hbus) { - atomic_inc(&hbus->remove_lock); + refcount_inc(&hbus->remove_lock); } static void put_hvpcibus(struct hv_pcibus_device *hbus) { - if (atomic_dec_and_test(&hbus->remove_lock)) + if (refcount_dec_and_test(&hbus->remove_lock)) complete(&hbus->remove_event); } @@ -2490,7 +2490,7 @@ static int hv_pci_probe(struct hv_device *hdev, hdev->dev_instance.b[8] << 8; hbus->hdev = hdev; - atomic_inc(&hbus->remove_lock); + refcount_set(&hbus->remove_lock, 1); INIT_LIST_HEAD(&hbus->children); INIT_LIST_HEAD(&hbus->dr_list); INIT_LIST_HEAD(&hbus->resources_for_children);