From patchwork Thu Mar 23 17:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 74153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp3047423wrt; Thu, 23 Mar 2023 10:41:43 -0700 (PDT) X-Google-Smtp-Source: AK7set+GJotMG6+fkA3Gm6hgZY4WPmR57oFoKRB6A6mtMPvD6H1Py6jUF/2Ah5q1ECNKs6rHlIB+ X-Received: by 2002:a17:903:41c6:b0:19a:a9d8:e47f with SMTP id u6-20020a17090341c600b0019aa9d8e47fmr9638775ple.36.1679593302318; Thu, 23 Mar 2023 10:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679593302; cv=none; d=google.com; s=arc-20160816; b=I67fHiHUUYe8t35/oHicwpSYwfeuPtDMUU9oDplq5KyinHtaBE4Mba5CPYZMJYJtT3 EMf8v1mH/nv8//gloPpsTfmCEvdQ0n3I6+BXgoYPDIxbfFqzp5xkVV4OaC8sefsPeU5A zO23fsAH1/YxCNl7ChFt8TLY8Y5rlGYg/gwc+zzm6W81wZJcGFgDMXgNMS9gWGuyOJPV cjVb7rkrrS28+bWILVDKfHDgJQmOuvXWlt3GxiTRf7XYVgYE+M1A5vh+ylkVQ6kipUDf hDnQpSJI/BLWw+42NGFHNz+RYYtwW00jkXJGkFHq47eVrB3dZB4EK7MLaGtIy+RiPGsQ pA/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eeb430h4TaRrJjxpHuQAIFSFoa6z4wzr7cwzJ9tQ7TE=; b=lITBsWBW9jHcxVfAoavCtZvVFsZxmygNOzz/DzMV/Y5H7X+18K1pdd/4fJUeH1M35i 12XODEMQLSLhH5cn7j+telnnWKX/PdD/p5cN9Ni8N3XRebZBRpB80WKspej1rnJQ16VW by53edHI/rRKxV+XlXe90Xm0OeToLTiakSlCpFSoYA1kiFplMrj1y/QIFoTY928cvBvh 5S1zEJTCFL6mFgFwwFYYU4XYUzw2GVOdNY9YOrus9u9rjJFdE658Ueg+DJKFzMZW1Zgj o59ul2Kkv/UiZThIbRGr8Ztv/UmEiwwcuJrU+J+DYfR1E/yg3BpHleZxgjhgWIafJUPF hfRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MhsNZtT0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a17090322d200b001a0644d1e7esi21050208plg.101.2023.03.23.10.41.29; Thu, 23 Mar 2023 10:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MhsNZtT0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbjCWRgs (ORCPT + 99 others); Thu, 23 Mar 2023 13:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjCWRgN (ORCPT ); Thu, 23 Mar 2023 13:36:13 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B51332CDB; Thu, 23 Mar 2023 10:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679592950; x=1711128950; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nYcCzANNoRmgbtK/lt7NmDYl/Mib02Nl2jjjm9pP05E=; b=MhsNZtT0qEWTQvk3FiRfBUKN03xvoHhj+Bw3EmNNk13I122DQuQ2tkPD Akalrqyont0IyRmz/tYmjzoeCe/hOSz6j88g9/kSNeE3hetVoS8dGEwhz hed15dACZ1xY7VRUaPVxRzLHhmcL8ZqMbZelRXOnkzuYLkj4Mm86CONRF VJW6rdwzBv+aS7GEUPdkw730fvYGk44G0FvzR99PDmvTXWC5mbndUBHxE HBgzcMKYXl2y3qw2n+TUPuMvtybkLZ7kfDqIixS8khNi02ZHHLhNchH9n 7AB0hDScKCqq+qQQ+cq4fpe7BeZzeX/5kLBEeeD473KhwSKNMUA7JOrW8 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="367308045" X-IronPort-AV: E=Sophos;i="5.98,285,1673942400"; d="scan'208";a="367308045" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 10:35:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="682380742" X-IronPort-AV: E=Sophos;i="5.98,285,1673942400"; d="scan'208";a="682380742" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 23 Mar 2023 10:35:25 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id DBBE42A0; Thu, 23 Mar 2023 19:36:11 +0200 (EET) From: Andy Shevchenko To: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , Andy Shevchenko , Mika Westerberg , =?utf-8?q?Krzysztof_Wilc?= =?utf-8?q?zy=C5=84ski?= , Michael Ellerman , Randy Dunlap , Arnd Bergmann , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?utf-8?q?Pali_Roh=C3=A1r?= , "Maciej W. Rozycki" , Juergen Gross , Dominik Brodowski , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, linux-acpi@vger.kernel.org Cc: Miguel Ojeda , Richard Henderson , Ivan Kokshaysky , Matt Turner , Russell King , Andrew Lunn , Sebastian Hesselbarth , Gregory Clement , Thomas Bogendoerfer , Nicholas Piggin , Christophe Leroy , Anatolij Gustschin , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Bjorn Helgaas , Stefano Stabellini , Oleksandr Tyshchenko Subject: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments Date: Thu, 23 Mar 2023 19:36:07 +0200 Message-Id: <20230323173610.60442-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230323173610.60442-1-andriy.shevchenko@linux.intel.com> References: <20230323173610.60442-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761181226661254371?= X-GMAIL-MSGID: =?utf-8?q?1761181226661254371?= Refactor pci_bus_for_each_resource() in the same way as it's done in pci_dev_for_each_resource() case. This will allow to hide iterator inside the loop, where it's not used otherwise. No functional changes intended. Signed-off-by: Andy Shevchenko Reviewed-by: Krzysztof Wilczyński Reviewed-by: Philippe Mathieu-Daudé --- drivers/pci/bus.c | 7 +++---- drivers/pci/hotplug/shpchp_sysfs.c | 8 ++++---- drivers/pci/pci.c | 3 +-- drivers/pci/probe.c | 2 +- drivers/pci/setup-bus.c | 10 ++++------ include/linux/pci.h | 17 +++++++++++++---- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 549c4bd5caec..5bc81cc0a2de 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -182,13 +182,13 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, void *alignf_data, struct pci_bus_region *region) { - int i, ret; struct resource *r, avail; resource_size_t max; + int ret; type_mask |= IORESOURCE_TYPE_BITS; - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { resource_size_t min_used = min; if (!r) @@ -289,9 +289,8 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx) struct resource *res = &dev->resource[idx]; struct resource orig_res = *res; struct resource *r; - int i; - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { resource_size_t start, end; if (!r) diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c index 64beed7a26be..01d47a42da04 100644 --- a/drivers/pci/hotplug/shpchp_sysfs.c +++ b/drivers/pci/hotplug/shpchp_sysfs.c @@ -24,16 +24,16 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev; - int index, busnr; struct resource *res; struct pci_bus *bus; size_t len = 0; + int busnr; pdev = to_pci_dev(dev); bus = pdev->subordinate; len += sysfs_emit_at(buf, len, "Free resources: memory\n"); - pci_bus_for_each_resource(bus, res, index) { + pci_bus_for_each_resource(bus, res) { if (res && (res->flags & IORESOURCE_MEM) && !(res->flags & IORESOURCE_PREFETCH)) { len += sysfs_emit_at(buf, len, @@ -43,7 +43,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char } } len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n"); - pci_bus_for_each_resource(bus, res, index) { + pci_bus_for_each_resource(bus, res) { if (res && (res->flags & IORESOURCE_MEM) && (res->flags & IORESOURCE_PREFETCH)) { len += sysfs_emit_at(buf, len, @@ -53,7 +53,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char } } len += sysfs_emit_at(buf, len, "Free resources: IO\n"); - pci_bus_for_each_resource(bus, res, index) { + pci_bus_for_each_resource(bus, res) { if (res && (res->flags & IORESOURCE_IO)) { len += sysfs_emit_at(buf, len, "start = %8.8llx, length = %8.8llx\n", diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7a67611dc5f4..99299f1299c4 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -779,9 +779,8 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev, { const struct pci_bus *bus = dev->bus; struct resource *r; - int i; - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { if (!r) continue; if (resource_contains(r, res)) { diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index a3f68b6ba6ac..f8191750f6b7 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -533,7 +533,7 @@ void pci_read_bridge_bases(struct pci_bus *child) pci_read_bridge_mmio_pref(child); if (dev->transparent) { - pci_bus_for_each_resource(child->parent, res, i) { + pci_bus_for_each_resource(child->parent, res) { if (res && res->flags) { pci_bus_add_resource(child, res, PCI_SUBTRACTIVE_DECODE); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 027b985dd1ee..fdeb121e9175 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -770,9 +770,8 @@ static struct resource *find_bus_resource_of_type(struct pci_bus *bus, unsigned long type) { struct resource *r, *r_assigned = NULL; - int i; - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { if (r == &ioport_resource || r == &iomem_resource) continue; if (r && (r->flags & type_mask) == type && !r->parent) @@ -1204,7 +1203,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) additional_mmio_pref_size = 0; struct resource *pref; struct pci_host_bridge *host; - int hdr_type, i, ret; + int hdr_type, ret; list_for_each_entry(dev, &bus->devices, bus_list) { struct pci_bus *b = dev->subordinate; @@ -1228,7 +1227,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) host = to_pci_host_bridge(bus->bridge); if (!host->size_windows) return; - pci_bus_for_each_resource(bus, pref, i) + pci_bus_for_each_resource(bus, pref) if (pref && (pref->flags & IORESOURCE_PREFETCH)) break; hdr_type = -1; /* Intentionally invalid - not a PCI device. */ @@ -1333,12 +1332,11 @@ EXPORT_SYMBOL(pci_bus_size_bridges); static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) { - int i; struct resource *parent_r; unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH; - pci_bus_for_each_resource(b, parent_r, i) { + pci_bus_for_each_resource(b, parent_r) { if (!parent_r) continue; diff --git a/include/linux/pci.h b/include/linux/pci.h index e1277a2bb645..70a4684d5f26 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1446,10 +1446,19 @@ int devm_request_pci_bus_resources(struct device *dev, /* Temporary until new and working PCI SBR API in place */ int pci_bridge_secondary_bus_reset(struct pci_dev *dev); -#define pci_bus_for_each_resource(bus, res, i) \ - for (i = 0; \ - (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \ - i++) +#define __pci_bus_for_each_resource_0(bus, res, ...) \ + for (unsigned int __b = 0; \ + res = pci_bus_resource_n(bus, __b), __b < PCI_BRIDGE_RESOURCE_NUM;\ + __b++) + +#define __pci_bus_for_each_resource_1(bus, res, __b) \ + for (__b = 0; \ + res = pci_bus_resource_n(bus, __b), __b < PCI_BRIDGE_RESOURCE_NUM;\ + __b++) + +#define pci_bus_for_each_resource(bus, res, ...) \ + CONCATENATE(__pci_bus_for_each_resource_, COUNT_ARGS(__VA_ARGS__)) \ + (bus, res, __VA_ARGS__) int __must_check pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size,