From patchwork Wed May 23 17:11:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 919240 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=networkplumber.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="jYQWKPd1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40rg3b2KGnz9s0y for ; Thu, 24 May 2018 03:48:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933638AbeEWRs0 (ORCPT ); Wed, 23 May 2018 13:48:26 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:34769 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933144AbeEWRsY (ORCPT ); Wed, 23 May 2018 13:48:24 -0400 Received: by mail-pl0-f66.google.com with SMTP id ay10-v6so13478548plb.1 for ; Wed, 23 May 2018 10:48:24 -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=7HCKX2nESoBLE/5TsNT4zA2kQ33FpBCSW1f9u5BTti0=; b=jYQWKPd1qk7Z/1EcOrDYzu6K7IfKJalFeIasyN0DqVy8izIaqO6pFfCiAU+pZcC2QI 2+RvPYw29WEZuWMGHxNHXWWf9T1PifcaAekOGzoz1oM1TTkDg1hd05TqI/a2ygkLuG6K nsinuFuslQ9tp5jdFj07nLnVFth02DpAYAzMpYOuBPOvCF4ThvZc751EkY+kfkWjAnKw 5jw9Tqa2QNXapDea6O3f10waEK2dxp70a6JvGdKC4+wnhzgTpeS6kNDe8kSwxaDx69no Z7GEwDCxtecHRKvAU3CFSKPJ1m81odN9uGs4mr+azixeeP9uuQemQAIXZxAyTepkimFi lVog== 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=7HCKX2nESoBLE/5TsNT4zA2kQ33FpBCSW1f9u5BTti0=; b=qGu8y8lU0Xmfrf4Vwn8i07vgn0VBDeEuIIiIlYtNW6Z3tEPMt1a0CLy6/z6fx4GaG2 gNrEbW5UURBPrXJSoKYS4T4w8ijM7P3RK+JvE3isbSaxrwpoj/gPinyJEQWiAciGuTg+ /3Wyv9wxK4qSl0E5+ViSSuRdvvYN24iZjYAsVIs8ESvhM7PzQI1dNRvFcK+XB7n8+hhd 2ixIEz9nTYHvYGK606/iuX/1c47nCLcA1hnYh7GLziWMaEFnjGZIAfGNew+TexvgdnOO LtOK0I83q55y/SsMK4dsC8rNVZ2hHFIh3HW+6GmOCyQzRNuJyxVakW6AtAafY9/jgI/T 2tWA== X-Gm-Message-State: ALKqPwebJ69D0SOdggtZKFdGI+N/+pzXpHxmxNWQlKi7XIE1wP7svBuz mVVYQyRMzcGrTNer2R7yO4A+FevnnKA= X-Google-Smtp-Source: AB8JxZouM305QEOw+OQG2QcNakG9g4ur1NdsRNKkgLyiIt0WAvrR6jvqYz7RFD1hu7zBFdEMLTsqtA== X-Received: by 2002:a17:902:aa04:: with SMTP id be4-v6mr3917540plb.20.1527097704214; Wed, 23 May 2018 10:48:24 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 10:48:23 -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 1/3] PCI: hv: remove unused reason for refcount handler Date: Wed, 23 May 2018 10:11:12 -0700 Message-Id: <20180523171114.5136-2-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 The get/put functions were taking a reason code. This appears to be a debug infrastructure that is no longer used. Move the functions to start of file to eliminate need for forward declaration. Forward declarations are discouraged on Linux. Signed-off-by: Stephen Hemminger --- drivers/pci/host/pci-hyperv.c | 70 +++++++++++++---------------------- 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 50cdefe3f6d3..505453e23c22 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -488,17 +488,6 @@ enum hv_pcichild_state { hv_pcichild_maximum }; -enum hv_pcidev_ref_reason { - hv_pcidev_ref_invalid = 0, - hv_pcidev_ref_initial, - hv_pcidev_ref_by_slot, - hv_pcidev_ref_packet, - hv_pcidev_ref_pnp, - hv_pcidev_ref_childlist, - hv_pcidev_irqdata, - hv_pcidev_ref_max -}; - struct hv_pci_dev { /* List protected by pci_rescan_remove_lock */ struct list_head list_entry; @@ -548,10 +537,17 @@ static void hv_pci_generic_compl(void *context, struct pci_response *resp, static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus, u32 wslot); -static void get_pcichild(struct hv_pci_dev *hv_pcidev, - enum hv_pcidev_ref_reason reason); -static void put_pcichild(struct hv_pci_dev *hv_pcidev, - enum hv_pcidev_ref_reason reason); + +static void get_pcichild(struct hv_pci_dev *hpdev) +{ + refcount_inc(&hpdev->refs); +} + +static void put_pcichild(struct hv_pci_dev *hpdev) +{ + if (refcount_dec_and_test(&hpdev->refs)) + kfree(hpdev); +} static void get_hvpcibus(struct hv_pcibus_device *hv_pcibus); static void put_hvpcibus(struct hv_pcibus_device *hv_pcibus); @@ -762,7 +758,7 @@ static int hv_pcifront_read_config(struct pci_bus *bus, unsigned int devfn, _hv_pcifront_read_config(hpdev, where, size, val); - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); return PCIBIOS_SUCCESSFUL; } @@ -790,7 +786,7 @@ static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn, _hv_pcifront_write_config(hpdev, where, size, val); - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); return PCIBIOS_SUCCESSFUL; } @@ -856,7 +852,7 @@ static void hv_msi_free(struct irq_domain *domain, struct msi_domain_info *info, } hv_int_desc_free(hpdev, int_desc); - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); } static int hv_set_affinity(struct irq_data *data, const struct cpumask *dest, @@ -1186,13 +1182,13 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) msg->address_lo = comp.int_desc.address & 0xffffffff; msg->data = comp.int_desc.data; - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); return; free_int_desc: kfree(int_desc); drop_reference: - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); return_null_message: msg->address_hi = 0; msg->address_lo = 0; @@ -1508,19 +1504,6 @@ static void q_resource_requirements(void *context, struct pci_response *resp, complete(&completion->host_event); } -static void get_pcichild(struct hv_pci_dev *hpdev, - enum hv_pcidev_ref_reason reason) -{ - refcount_inc(&hpdev->refs); -} - -static void put_pcichild(struct hv_pci_dev *hpdev, - enum hv_pcidev_ref_reason reason) -{ - if (refcount_dec_and_test(&hpdev->refs)) - kfree(hpdev); -} - /** * new_pcichild_device() - Create a new child device * @hbus: The internal struct tracking this root PCI bus. @@ -1572,7 +1555,7 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, hpdev->desc = *desc; refcount_set(&hpdev->refs, 1); - get_pcichild(hpdev, hv_pcidev_ref_childlist); + get_pcichild(hpdev); spin_lock_irqsave(&hbus->device_list_lock, flags); /* @@ -1618,7 +1601,7 @@ static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus, list_for_each_entry(iter, &hbus->children, list_entry) { if (iter->desc.win_slot.slot == wslot) { hpdev = iter; - get_pcichild(hpdev, hv_pcidev_ref_by_slot); + get_pcichild(hpdev); break; } } @@ -1735,7 +1718,7 @@ static void pci_devices_present_work(struct work_struct *work) list_entry); if (hpdev->reported_missing) { found = true; - put_pcichild(hpdev, hv_pcidev_ref_childlist); + put_pcichild(hpdev); list_move_tail(&hpdev->list_entry, &removed); break; } @@ -1748,7 +1731,7 @@ static void pci_devices_present_work(struct work_struct *work) hpdev = list_first_entry(&removed, struct hv_pci_dev, list_entry); list_del(&hpdev->list_entry); - put_pcichild(hpdev, hv_pcidev_ref_initial); + put_pcichild(hpdev); } switch (hbus->state) { @@ -1883,8 +1866,8 @@ static void hv_eject_device_work(struct work_struct *work) sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, VM_PKT_DATA_INBAND, 0); - put_pcichild(hpdev, hv_pcidev_ref_childlist); - put_pcichild(hpdev, hv_pcidev_ref_pnp); + put_pcichild(hpdev); + put_pcichild(hpdev); put_hvpcibus(hpdev->hbus); } @@ -1899,7 +1882,7 @@ static void hv_eject_device_work(struct work_struct *work) static void hv_pci_eject_device(struct hv_pci_dev *hpdev) { hpdev->state = hv_pcichild_ejecting; - get_pcichild(hpdev, hv_pcidev_ref_pnp); + get_pcichild(hpdev); INIT_WORK(&hpdev->wrk, hv_eject_device_work); get_hvpcibus(hpdev->hbus); queue_work(hpdev->hbus->wq, &hpdev->wrk); @@ -1999,8 +1982,7 @@ static void hv_pci_onchannelcallback(void *context) dev_message->wslot.slot); if (hpdev) { hv_pci_eject_device(hpdev); - put_pcichild(hpdev, - hv_pcidev_ref_by_slot); + put_pcichild(hpdev); } break; @@ -2398,7 +2380,7 @@ static int hv_send_resources_allocated(struct hv_device *hdev) PCI_RESOURCES_ASSIGNED2; res_assigned2->wslot.slot = hpdev->desc.win_slot.slot; } - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); ret = vmbus_sendpacket(hdev->channel, &pkt->message, size_res, (unsigned long)pkt, @@ -2446,7 +2428,7 @@ static int hv_send_resources_released(struct hv_device *hdev) pkt.message_type.type = PCI_RESOURCES_RELEASED; pkt.wslot.slot = hpdev->desc.win_slot.slot; - put_pcichild(hpdev, hv_pcidev_ref_by_slot); + put_pcichild(hpdev); ret = vmbus_sendpacket(hdev->channel, &pkt, sizeof(pkt), 0, VM_PKT_DATA_INBAND, 0); 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: 919241 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=networkplumber.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="OYLJCnhI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40rg3d5qpCz9s0W for ; Thu, 24 May 2018 03:48:29 +1000 (AEST) 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 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); From patchwork Wed May 23 17:11:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 919242 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=networkplumber.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="drC3I7DK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40rg3f3pbZz9s15 for ; Thu, 24 May 2018 03:48:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933703AbeEWRs3 (ORCPT ); Wed, 23 May 2018 13:48:29 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:46059 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933144AbeEWRs1 (ORCPT ); Wed, 23 May 2018 13:48:27 -0400 Received: by mail-pf0-f194.google.com with SMTP id c10-v6so10844996pfi.12 for ; Wed, 23 May 2018 10:48:27 -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=UnIh8cPb7HFejLK0nmWMpXHlxA8hkVX2HrbK3wGO/rA=; b=drC3I7DKpqQ6BUkpiKEtIik7sC2S5r/TWaxW8KUxyBM8cXpyQf4OUy15knCtAdScMj saXza5Rxez4mD8haGfF3cTAyh2jGjz51wTQKzUZg8GDD0A5R7rq4iaHCCDbIUDNBi3gQ ccdut/4iKI1xQX9s4iAlC6brjjcK94/fG+oOO3/jx+UWY/JClKrGc2KbOqyDEmxu6xv7 /zeJ+MwrcQ/0fnJEOCv6LXlLPlQfEHvi//y3rZ/8+IumUnI5iHNSXtEKbUkljxEWeS0n 0ZpQpmSU/d3smj/NxNQ4WI1Yf14eV+0EyNySCBsqsuNwxqO4LK1NaM8EEv+FsapSe/fp QCqA== 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=UnIh8cPb7HFejLK0nmWMpXHlxA8hkVX2HrbK3wGO/rA=; b=nIzvZdK0AnTIDrhulM/t9PIVywnDaXyNkNiNKYNuC2tgt5TJ3bc9MD6e6MYgYhKp7f 4TnoMzxSy3YdE0xvYRaIAz4jvbPgBT2AvyATYavFdkt3YbEGE7t/5IBhYpayY4ai3UMt 0izM4K2ZsiE3VnC3CTTUUlPBb+x9mjojKPiF9JgouP61Oyj4SMkJyE7v4dlq3wTAfvju ZSRzAxOfIGn5x5zWTVa085CaTjQxzJk6aKDApqSkcGmCELV8+nZWWk6pkZKP3ozIAmbB VEPZSJ7vDqQClsk03NDQDVQ0iPPLcJ+pM8n8TyDMXo02uTKLvk4B2/2DIhio6faJXEbT zaGQ== X-Gm-Message-State: ALKqPwciG8j8FAhWifVlPwaxKsOjMo95CGok9bcMaE2tkrZGp8WXypHV Vax4HvtUW6jc7Qi9TjlV+2yO1Q== X-Google-Smtp-Source: AB8JxZrg852/L/3Uo13W1VFe9RXUlzLMdxv3QyHKAVXhn8gI47RuAvi1r8CNEQrbBV0kI5PQD14aOg== X-Received: by 2002:a62:f909:: with SMTP id o9-v6mr3829556pfh.256.1527097706861; Wed, 23 May 2018 10:48:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 10:48:25 -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 3/3] PCI: hv: use list_for_each_entry Date: Wed, 23 May 2018 10:11:14 -0700 Message-Id: <20180523171114.5136-4-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 There are several places where list_for_each_entry could be used to simplify the code. Signed-off-by: Stephen Hemminger --- drivers/pci/host/pci-hyperv.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 19eb47f58ccb..afc30dee6001 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1279,7 +1279,6 @@ static u64 get_bar_size(u64 bar_val) */ static void survey_child_resources(struct hv_pcibus_device *hbus) { - struct list_head *iter; struct hv_pci_dev *hpdev; resource_size_t bar_size = 0; unsigned long flags; @@ -1305,8 +1304,7 @@ static void survey_child_resources(struct hv_pcibus_device *hbus) * for a child device are a power of 2 in size and aligned in memory, * so it's sufficient to just add them up without tracking alignment. */ - list_for_each(iter, &hbus->children) { - hpdev = container_of(iter, struct hv_pci_dev, list_entry); + list_for_each_entry(hpdev, &hbus->children, list_entry) { for (i = 0; i < 6; i++) { if (hpdev->probed_bar[i] & PCI_BASE_ADDRESS_SPACE_IO) dev_err(&hbus->hdev->device, @@ -1359,7 +1357,6 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) resource_size_t low_base = 0; resource_size_t bar_size; struct hv_pci_dev *hpdev; - struct list_head *iter; unsigned long flags; u64 bar_val; u32 command; @@ -1381,9 +1378,7 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) /* Pick addresses for the BARs. */ do { - list_for_each(iter, &hbus->children) { - hpdev = container_of(iter, struct hv_pci_dev, - list_entry); + list_for_each_entry(hpdev, &hbus->children, list_entry) { for (i = 0; i < 6; i++) { bar_val = hpdev->probed_bar[i]; if (bar_val == 0) @@ -1637,7 +1632,6 @@ static void pci_devices_present_work(struct work_struct *work) { u32 child_no; bool found; - struct list_head *iter; struct pci_function_description *new_desc; struct hv_pci_dev *hpdev; struct hv_pcibus_device *hbus; @@ -1674,10 +1668,8 @@ static void pci_devices_present_work(struct work_struct *work) /* First, mark all existing children as reported missing. */ spin_lock_irqsave(&hbus->device_list_lock, flags); - list_for_each(iter, &hbus->children) { - hpdev = container_of(iter, struct hv_pci_dev, - list_entry); - hpdev->reported_missing = true; + list_for_each_entry(hpdev, &hbus->children, list_entry) { + hpdev->reported_missing = true; } spin_unlock_irqrestore(&hbus->device_list_lock, flags); @@ -1687,11 +1679,8 @@ static void pci_devices_present_work(struct work_struct *work) new_desc = &dr->func[child_no]; spin_lock_irqsave(&hbus->device_list_lock, flags); - list_for_each(iter, &hbus->children) { - hpdev = container_of(iter, struct hv_pci_dev, - list_entry); - if ((hpdev->desc.win_slot.slot == - new_desc->win_slot.slot) && + list_for_each_entry(hpdev, &hbus->children, list_entry) { + if ((hpdev->desc.win_slot.slot == new_desc->win_slot.slot) && (hpdev->desc.v_id == new_desc->v_id) && (hpdev->desc.d_id == new_desc->d_id) && (hpdev->desc.ser == new_desc->ser)) { @@ -1713,9 +1702,7 @@ static void pci_devices_present_work(struct work_struct *work) spin_lock_irqsave(&hbus->device_list_lock, flags); do { found = false; - list_for_each(iter, &hbus->children) { - hpdev = container_of(iter, struct hv_pci_dev, - list_entry); + list_for_each_entry(hpdev, &hbus->children, list_entry) { if (hpdev->reported_missing) { found = true; put_pcichild(hpdev);