From nobody Sun May 12 05:44:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42CD3C761A6 for ; Thu, 30 Mar 2023 16:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbjC3Q2m (ORCPT ); Thu, 30 Mar 2023 12:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231590AbjC3Q2e (ORCPT ); Thu, 30 Mar 2023 12:28:34 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3F0EBDE5; Thu, 30 Mar 2023 09:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193710; x=1711729710; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gIQa0UBc6rrUYtPkGDZ1t1xT6zplGxALb8OYgbohTeo=; b=BMtTgumTEElOfhQRh4w1CoFSlfi1IAEExZC2z1RKdIUvoIe6ccOxQVzV Rlksvnz+TcvSvVLgBTVVNHnv3EBmaC9Jdg26SckfEbnntjcaNkiJJkduh m4oUcxXM2199ksPs7gvzF+1LgO9qQToWjlEGN6L8oBajTJAuOKW2GgO8N bFBgi8gxJySCKoYEYvHJW0k0FHYB/J1zvzOvZ+OHAFlDGBrAbqdQ6itQ6 FlBGGA05YlYApYayjV7BP6ISso81/5cVOkvzXSErGBro1mVIKHNLLSFH9 fXvfsJRlgeuDd0n4MFFAh5vkidqwRdCSRQMSHS+pe5vQG+7X0A0wF0TNd w==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427496004" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="427496004" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="858971548" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="858971548" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 30 Mar 2023 09:28:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id C528C14B; Thu, 30 Mar 2023 19:24:48 +0300 (EEST) From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 1/7] kernel.h: Split out COUNT_ARGS() and CONCATENATE() Date: Thu, 30 Mar 2023 19:24:28 +0300 Message-Id: <20230330162434.35055-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kernel.h is being used as a dump for all kinds of stuff for a long time. The COUNT_ARGS() and CONCATENATE() macros may be used in some places without need of the full kernel.h dependency train with it. Here is the attempt on cleaning it up by splitting out these macros(). Signed-off-by: Andy Shevchenko --- include/linux/args.h | 13 +++++++++++++ include/linux/kernel.h | 8 +------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 include/linux/args.h diff --git a/include/linux/args.h b/include/linux/args.h new file mode 100644 index 000000000000..16ef6fad8add --- /dev/null +++ b/include/linux/args.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_ARGS_H +#define _LINUX_ARGS_H + +/* This counts to 12. Any more, it will return 13th argument. */ +#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12= , _n, X...) _n +#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4,= 3, 2, 1, 0) + +#define __CONCAT(a, b) a ## b +#define CONCATENATE(a, b) __CONCAT(a, b) + +#endif /* _LINUX_ARGS_H */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 0d91e0af0125..fa675d50d7b7 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -13,6 +13,7 @@ =20 #include #include +#include #include #include #include @@ -457,13 +458,6 @@ ftrace_vprintk(const char *fmt, va_list ap) static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } #endif /* CONFIG_TRACING */ =20 -/* This counts to 12. Any more, it will return 13th argument. */ -#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12= , _n, X...) _n -#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4,= 3, 2, 1, 0) - -#define __CONCAT(a, b) a ## b -#define CONCATENATE(a, b) __CONCAT(a, b) - /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ #ifdef CONFIG_FTRACE_MCOUNT_RECORD # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD --=20 2.40.0.1.gaa8946217a0b From nobody Sun May 12 05:44:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEFBFC77B73 for ; Thu, 30 Mar 2023 16:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbjC3Q2h (ORCPT ); Thu, 30 Mar 2023 12:28:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbjC3Q2a (ORCPT ); Thu, 30 Mar 2023 12:28:30 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80618D31C; Thu, 30 Mar 2023 09:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193709; x=1711729709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yhhBl9vHYjEoa/C6LYyaGmzTAsrwMbBX/9yhSQi3PhY=; b=eB5C1OzY1asxXvzkN6NmOx8NmWLcSDi1o6o0vQzAnDcqz+xslbgfzhEb XDNw9hfx/jy6ngofMgRUUDTQDC/ykqkPphM0MtQSCzE7yEkvqDUUZ7kAB kgga3g2haWi2Pe9FSnlANvBKaXXCRSShLQ/jUGSfj3iySTmFjiBL4y9qs k+Ma/q7Coj/tcNo2fcYvKVGBDo+BgyBg6CN+PzAQTuwUtDQj1nTFq77JU /gBT03edahvVi7DzVJsAjUUV/2OGav8FyMQ2oKQwjoZb0GG+HwmUJCVBs t/UIm3NuwgQwGlhKNuK/gOFlx/nyEfzQGRH8pZPQ3hmaG24BmSTtI5kaf w==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427495957" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="427495957" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="858971546" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="858971546" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 30 Mar 2023 09:28:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id DCBBF1D9; Thu, 30 Mar 2023 19:24:49 +0300 (EEST) From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 2/7] PCI: Introduce pci_resource_n() Date: Thu, 30 Mar 2023 19:24:29 +0300 Message-Id: <20230330162434.35055-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce pci_resource_n() and replace open-coded implementations of it in pci.h. Signed-off-by: Andy Shevchenko Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/linux/pci.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/linux/pci.h b/include/linux/pci.h index b50e5c79f7e3..aeaa95455d4c 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1995,14 +1995,13 @@ int pci_iobar_pfn(struct pci_dev *pdev, int bar, st= ruct vm_area_struct *vma); * These helpers provide future and backwards compatibility * for accessing popular PCI BAR info */ -#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start) -#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end) -#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags) -#define pci_resource_len(dev,bar) \ - ((pci_resource_end((dev), (bar)) =3D=3D 0) ? 0 : \ - \ - (pci_resource_end((dev), (bar)) - \ - pci_resource_start((dev), (bar)) + 1)) +#define pci_resource_n(dev, bar) (&(dev)->resource[(bar)]) +#define pci_resource_start(dev, bar) (pci_resource_n(dev, bar)->start) +#define pci_resource_end(dev, bar) (pci_resource_n(dev, bar)->end) +#define pci_resource_flags(dev, bar) (pci_resource_n(dev, bar)->flags) +#define pci_resource_len(dev,bar) \ + (pci_resource_end((dev), (bar)) ? \ + resource_size(pci_resource_n((dev), (bar))) : 0) =20 /* * Similar to the helpers above, these manipulate per-pci_dev --=20 2.40.0.1.gaa8946217a0b From nobody Sun May 12 05:44:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 588E8C6FD1D for ; Thu, 30 Mar 2023 16:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232102AbjC3Q2t (ORCPT ); Thu, 30 Mar 2023 12:28:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231716AbjC3Q2g (ORCPT ); Thu, 30 Mar 2023 12:28:36 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B00EFC676; Thu, 30 Mar 2023 09:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193711; x=1711729711; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KHCoRXEtiwe/FhEOF5L3Qq5P3Xpu9j6hzV2s/by6feA=; b=TLdWjYGoOZmNuVgwOFxDmbNsEhuboLOP9EpUBYr49DAg+gS23fAogdPb 6Zkb9M9JSKJjW6EYda1Rh5S4+ZHmThuQ2B0AyAyGqrhvPNHHfI3cwlPpn cFU5wzCCuyiBxZ5Wl+GQ1jvJOtl5nB2ob0/Q1CexCV6WRdD0A9l4ahnHV X135BDUQeOGHa+ZP3Nc3MCR//KFrHUhgFUjkrgFCQmTB4c5GBYqkTkwfp l2EOEXbKfxujTmOUeMXTcCgvzfZiBHCje2RiIhSruWAnY5RSxdu7IqiSN AHO7FG6WtkV6xSlX9ylIlti7nZYFesmkCMKRasssrJyvHz1MrHxyKtTSr g==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427496027" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="427496027" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="858971551" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="858971551" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 30 Mar 2023 09:28:19 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 924B4211; Thu, 30 Mar 2023 19:24:50 +0300 (EEST) From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 3/7] PCI: Introduce pci_dev_for_each_resource() Date: Thu, 30 Mar 2023 19:24:30 +0300 Message-Id: <20230330162434.35055-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mika Westerberg Instead of open-coding it everywhere introduce a tiny helper that can be used to iterate over each resource of a PCI device, and convert the most obvious users into it. While at it drop doubled empty line before pdev_sort_resources(). No functional changes intended. Suggested-by: Andy Shevchenko Signed-off-by: Mika Westerberg Signed-off-by: Andy Shevchenko Reviewed-by: Krzysztof Wilczy=C5=84ski --- .clang-format | 1 + arch/alpha/kernel/pci.c | 5 ++-- arch/arm/kernel/bios32.c | 16 ++++++------- arch/arm/mach-dove/pcie.c | 10 ++++---- arch/arm/mach-mv78xx0/pcie.c | 10 ++++---- arch/arm/mach-orion5x/pci.c | 10 ++++---- arch/mips/pci/ops-bcm63xx.c | 8 +++---- arch/mips/pci/pci-legacy.c | 3 +-- arch/powerpc/kernel/pci-common.c | 21 ++++++++-------- arch/powerpc/platforms/4xx/pci.c | 8 +++---- arch/powerpc/platforms/52xx/mpc52xx_pci.c | 5 ++-- arch/powerpc/platforms/pseries/pci.c | 16 ++++++------- arch/sh/drivers/pci/pcie-sh7786.c | 10 ++++---- arch/sparc/kernel/leon_pci.c | 5 ++-- arch/sparc/kernel/pci.c | 10 ++++---- arch/sparc/kernel/pcic.c | 5 ++-- drivers/pci/remove.c | 5 ++-- drivers/pci/setup-bus.c | 27 ++++++++------------- drivers/pci/setup-res.c | 4 +--- drivers/pci/vgaarb.c | 17 ++++--------- drivers/pci/xen-pcifront.c | 4 +--- drivers/pnp/quirks.c | 29 ++++++++--------------- include/linux/pci.h | 15 ++++++++++++ 23 files changed, 112 insertions(+), 132 deletions(-) diff --git a/.clang-format b/.clang-format index d988e9fa9b26..2048b0296d76 100644 --- a/.clang-format +++ b/.clang-format @@ -520,6 +520,7 @@ ForEachMacros: - 'of_property_for_each_string' - 'of_property_for_each_u32' - 'pci_bus_for_each_resource' + - 'pci_dev_for_each_resource' - 'pci_doe_for_each_off' - 'pcl_for_each_chunk' - 'pcl_for_each_segment' diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c index 64fbfb0763b2..4458eb7f44f0 100644 --- a/arch/alpha/kernel/pci.c +++ b/arch/alpha/kernel/pci.c @@ -288,11 +288,10 @@ pcibios_claim_one_bus(struct pci_bus *b) struct pci_bus *child_bus; =20 list_for_each_entry(dev, &b->devices, bus_list) { + struct resource *r; int i; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r =3D &dev->resource[i]; - + pci_dev_for_each_resource(dev, r, i) { if (r->parent || !r->start || !r->flags) continue; if (pci_has_flag(PCI_PROBE_ONLY) || diff --git a/arch/arm/kernel/bios32.c b/arch/arm/kernel/bios32.c index e7ef2b5bea9c..d334c7fb672b 100644 --- a/arch/arm/kernel/bios32.c +++ b/arch/arm/kernel/bios32.c @@ -142,15 +142,15 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND2, PCI_= DEVICE_ID_WINBOND2_89C940F, */ static void pci_fixup_dec21285(struct pci_dev *dev) { - int i; - if (dev->devfn =3D=3D 0) { + struct resource *r; + dev->class &=3D 0xff; dev->class |=3D PCI_CLASS_BRIDGE_HOST << 8; - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - dev->resource[i].start =3D 0; - dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D 0; + r->end =3D 0; + r->flags =3D 0; } } } @@ -162,13 +162,11 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVIC= E_ID_DEC_21285, pci_fixup_d static void pci_fixup_ide_bases(struct pci_dev *dev) { struct resource *r; - int i; =20 if ((dev->class >> 8) !=3D PCI_CLASS_STORAGE_IDE) return; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - r =3D dev->resource + i; + pci_dev_for_each_resource(dev, r) { if ((r->start & ~0x80) =3D=3D 0x374) { r->start |=3D 2; r->end =3D r->start; diff --git a/arch/arm/mach-dove/pcie.c b/arch/arm/mach-dove/pcie.c index 754ca381f600..3044b7e03890 100644 --- a/arch/arm/mach-dove/pcie.c +++ b/arch/arm/mach-dove/pcie.c @@ -142,14 +142,14 @@ static struct pci_ops pcie_ops =3D { static void rc_pci_fixup(struct pci_dev *dev) { if (dev->bus->parent =3D=3D NULL && dev->devfn =3D=3D 0) { - int i; + struct resource *r; =20 dev->class &=3D 0xff; dev->class |=3D PCI_CLASS_BRIDGE_HOST << 8; - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - dev->resource[i].start =3D 0; - dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D 0; + r->end =3D 0; + r->flags =3D 0; } } } diff --git a/arch/arm/mach-mv78xx0/pcie.c b/arch/arm/mach-mv78xx0/pcie.c index 6190f538a124..0ebc909ea273 100644 --- a/arch/arm/mach-mv78xx0/pcie.c +++ b/arch/arm/mach-mv78xx0/pcie.c @@ -186,14 +186,14 @@ static struct pci_ops pcie_ops =3D { static void rc_pci_fixup(struct pci_dev *dev) { if (dev->bus->parent =3D=3D NULL && dev->devfn =3D=3D 0) { - int i; + struct resource *r; =20 dev->class &=3D 0xff; dev->class |=3D PCI_CLASS_BRIDGE_HOST << 8; - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - dev->resource[i].start =3D 0; - dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D 0; + r->end =3D 0; + r->flags =3D 0; } } } diff --git a/arch/arm/mach-orion5x/pci.c b/arch/arm/mach-orion5x/pci.c index 888fdc9099c5..3313bc5a63ea 100644 --- a/arch/arm/mach-orion5x/pci.c +++ b/arch/arm/mach-orion5x/pci.c @@ -522,14 +522,14 @@ static int __init pci_setup(struct pci_sys_data *sys) static void rc_pci_fixup(struct pci_dev *dev) { if (dev->bus->parent =3D=3D NULL && dev->devfn =3D=3D 0) { - int i; + struct resource *r; =20 dev->class &=3D 0xff; dev->class |=3D PCI_CLASS_BRIDGE_HOST << 8; - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - dev->resource[i].start =3D 0; - dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D 0; + r->end =3D 0; + r->flags =3D 0; } } } diff --git a/arch/mips/pci/ops-bcm63xx.c b/arch/mips/pci/ops-bcm63xx.c index dc6dc2741272..b0ea023c47c0 100644 --- a/arch/mips/pci/ops-bcm63xx.c +++ b/arch/mips/pci/ops-bcm63xx.c @@ -413,18 +413,18 @@ struct pci_ops bcm63xx_cb_ops =3D { static void bcm63xx_fixup(struct pci_dev *dev) { static int io_window =3D -1; - int i, found, new_io_window; + int found, new_io_window; + struct resource *r; u32 val; =20 /* look for any io resource */ found =3D 0; - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - if (pci_resource_flags(dev, i) & IORESOURCE_IO) { + pci_dev_for_each_resource(dev, r) { + if (resource_type(r) =3D=3D IORESOURCE_IO) { found =3D 1; break; } } - if (!found) return; =20 diff --git a/arch/mips/pci/pci-legacy.c b/arch/mips/pci/pci-legacy.c index 468722c8a5c6..ec2567f8efd8 100644 --- a/arch/mips/pci/pci-legacy.c +++ b/arch/mips/pci/pci-legacy.c @@ -249,12 +249,11 @@ static int pcibios_enable_resources(struct pci_dev *d= ev, int mask) =20 pci_read_config_word(dev, PCI_COMMAND, &cmd); old_cmd =3D cmd; - for (idx =3D 0; idx < PCI_NUM_RESOURCES; idx++) { + pci_dev_for_each_resource(dev, r, idx) { /* Only set up the requested stuff */ if (!(mask & (1<resource[idx]; if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) continue; if ((idx =3D=3D PCI_ROM_RESOURCE) && diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-com= mon.c index d67cf79bf5d0..e88d7c9feeec 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -880,6 +880,7 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge = *bridge) static void pcibios_fixup_resources(struct pci_dev *dev) { struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + struct resource *res; int i; =20 if (!hose) { @@ -891,9 +892,9 @@ static void pcibios_fixup_resources(struct pci_dev *dev) if (dev->is_virtfn) return; =20 - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - struct resource *res =3D dev->resource + i; + pci_dev_for_each_resource(dev, res, i) { struct pci_bus_region reg; + if (!res->flags) continue; =20 @@ -1452,11 +1453,10 @@ void pcibios_claim_one_bus(struct pci_bus *bus) struct pci_bus *child_bus; =20 list_for_each_entry(dev, &bus->devices, bus_list) { + struct resource *r; int i; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r =3D &dev->resource[i]; - + pci_dev_for_each_resource(dev, r, i) { if (r->parent || !r->start || !r->flags) continue; =20 @@ -1705,19 +1705,20 @@ EXPORT_SYMBOL_GPL(pcibios_scan_phb); =20 static void fixup_hide_host_resource_fsl(struct pci_dev *dev) { - int i, class =3D dev->class >> 8; + int class =3D dev->class >> 8; /* When configured as agent, programming interface =3D 1 */ int prog_if =3D dev->class & 0xf; + struct resource *r; =20 if ((class =3D=3D PCI_CLASS_PROCESSOR_POWERPC || class =3D=3D PCI_CLASS_BRIDGE_OTHER) && (dev->hdr_type =3D=3D PCI_HEADER_TYPE_NORMAL) && (prog_if =3D=3D 0) && (dev->bus->parent =3D=3D NULL)) { - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - dev->resource[i].start =3D 0; - dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D 0; + r->end =3D 0; + r->flags =3D 0; } } } diff --git a/arch/powerpc/platforms/4xx/pci.c b/arch/powerpc/platforms/4xx/= pci.c index ca5dd7a5842a..07dcc2b8007f 100644 --- a/arch/powerpc/platforms/4xx/pci.c +++ b/arch/powerpc/platforms/4xx/pci.c @@ -57,7 +57,7 @@ static inline int ppc440spe_revA(void) static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev) { struct pci_controller *hose; - int i; + struct resource *r; =20 if (dev->devfn !=3D 0 || dev->bus->self !=3D NULL) return; @@ -79,9 +79,9 @@ static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev) /* Hide the PCI host BARs from the kernel as their content doesn't * fit well in the resource management */ - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - dev->resource[i].start =3D dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D r->end =3D 0; + r->flags =3D 0; } =20 printk(KERN_INFO "PCI: Hiding 4xx host bridge resources %s\n", diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pci.c b/arch/powerpc/platf= orms/52xx/mpc52xx_pci.c index 859e2818c43d..0ca4401ba781 100644 --- a/arch/powerpc/platforms/52xx/mpc52xx_pci.c +++ b/arch/powerpc/platforms/52xx/mpc52xx_pci.c @@ -327,14 +327,13 @@ mpc52xx_pci_setup(struct pci_controller *hose, static void mpc52xx_pci_fixup_resources(struct pci_dev *dev) { - int i; + struct resource *res; =20 pr_debug("%s() %.4x:%.4x\n", __func__, dev->vendor, dev->device); =20 /* We don't rely on boot loader for PCI and resets all devices */ - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - struct resource *res =3D &dev->resource[i]; + pci_dev_for_each_resource(dev, res) { if (res->end > res->start) { /* Only valid resources */ res->end -=3D res->start; res->start =3D 0; diff --git a/arch/powerpc/platforms/pseries/pci.c b/arch/powerpc/platforms/= pseries/pci.c index 60e0a58928ef..1772ae3d193d 100644 --- a/arch/powerpc/platforms/pseries/pci.c +++ b/arch/powerpc/platforms/pseries/pci.c @@ -240,7 +240,7 @@ void __init pSeries_final_fixup(void) */ static void fixup_winbond_82c105(struct pci_dev* dev) { - int i; + struct resource *r; unsigned int reg; =20 if (!machine_is(pseries)) @@ -251,14 +251,14 @@ static void fixup_winbond_82c105(struct pci_dev* dev) /* Enable LEGIRQ to use INTC instead of ISA interrupts */ pci_write_config_dword(dev, 0x40, reg | (1<<11)); =20 - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; ++i) { + pci_dev_for_each_resource(dev, r) { /* zap the 2nd function of the winbond chip */ - if (dev->resource[i].flags & IORESOURCE_IO - && dev->bus->number =3D=3D 0 && dev->devfn =3D=3D 0x81) - dev->resource[i].flags &=3D ~IORESOURCE_IO; - if (dev->resource[i].start =3D=3D 0 && dev->resource[i].end) { - dev->resource[i].flags =3D 0; - dev->resource[i].end =3D 0; + if (dev->bus->number =3D=3D 0 && dev->devfn =3D=3D 0x81 && + r->flags & IORESOURCE_IO) + r->flags &=3D ~IORESOURCE_IO; + if (r->start =3D=3D 0 && r->end) { + r->flags =3D 0; + r->end =3D 0; } } } diff --git a/arch/sh/drivers/pci/pcie-sh7786.c b/arch/sh/drivers/pci/pcie-s= h7786.c index b0c2a5238d04..4f5e49f10805 100644 --- a/arch/sh/drivers/pci/pcie-sh7786.c +++ b/arch/sh/drivers/pci/pcie-sh7786.c @@ -140,12 +140,12 @@ static void sh7786_pci_fixup(struct pci_dev *dev) * Prevent enumeration of root complex resources. */ if (pci_is_root_bus(dev->bus) && dev->devfn =3D=3D 0) { - int i; + struct resource *r; =20 - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - dev->resource[i].start =3D 0; - dev->resource[i].end =3D 0; - dev->resource[i].flags =3D 0; + pci_dev_for_each_resource(dev, r) { + r->start =3D 0; + r->end =3D 0; + r->flags =3D 0; } } } diff --git a/arch/sparc/kernel/leon_pci.c b/arch/sparc/kernel/leon_pci.c index e5e5ff6b9a5c..b6663a3fbae9 100644 --- a/arch/sparc/kernel/leon_pci.c +++ b/arch/sparc/kernel/leon_pci.c @@ -62,15 +62,14 @@ void leon_pci_init(struct platform_device *ofdev, struc= t leon_pci_info *info) =20 int pcibios_enable_device(struct pci_dev *dev, int mask) { + struct resource *res; u16 cmd, oldcmd; int i; =20 pci_read_config_word(dev, PCI_COMMAND, &cmd); oldcmd =3D cmd; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *res =3D &dev->resource[i]; - + pci_dev_for_each_resource(dev, res, i) { /* Only set up the requested stuff */ if (!(mask & (1<devices, bus_list) { + struct resource *r; int i; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r =3D &dev->resource[i]; - + pci_dev_for_each_resource(dev, r, i) { if (r->parent || !r->start || !r->flags) continue; =20 @@ -724,15 +723,14 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info = *pbm, =20 int pcibios_enable_device(struct pci_dev *dev, int mask) { + struct resource *res; u16 cmd, oldcmd; int i; =20 pci_read_config_word(dev, PCI_COMMAND, &cmd); oldcmd =3D cmd; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *res =3D &dev->resource[i]; - + pci_dev_for_each_resource(dev, res, i) { /* Only set up the requested stuff */ if (!(mask & (1<resource[i]; - + pci_dev_for_each_resource(dev, res, i) { /* Only set up the requested stuff */ if (!(mask & (1<resource + i; + pci_dev_for_each_resource(dev, res) { if (res->parent) release_resource(res); } diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index c690572b10ce..027b985dd1ee 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -124,20 +124,17 @@ static resource_size_t get_res_add_align(struct list_= head *head, return dev_res ? dev_res->min_align : 0; } =20 - /* Sort resources by alignment */ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *hea= d) { + struct resource *r; int i; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r; + pci_dev_for_each_resource(dev, r, i) { struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n; =20 - r =3D &dev->resource[i]; - if (r->flags & IORESOURCE_PCI_FIXED) continue; =20 @@ -895,10 +892,9 @@ static void pbus_size_io(struct pci_bus *bus, resource= _size_t min_size, =20 min_align =3D window_alignment(bus, IORESOURCE_IO); list_for_each_entry(dev, &bus->devices, bus_list) { - int i; + struct resource *r; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r =3D &dev->resource[i]; + pci_dev_for_each_resource(dev, r) { unsigned long r_size; =20 if (r->parent || !(r->flags & IORESOURCE_IO)) @@ -1014,10 +1010,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsig= ned long mask, size =3D 0; =20 list_for_each_entry(dev, &bus->devices, bus_list) { + struct resource *r; int i; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r =3D &dev->resource[i]; + pci_dev_for_each_resource(dev, r, i) { resource_size_t r_size; =20 if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) || @@ -1358,11 +1354,10 @@ static void assign_fixed_resource_on_bus(struct pci= _bus *b, struct resource *r) */ static void pdev_assign_fixed_resources(struct pci_dev *dev) { - int i; + struct resource *r; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { + pci_dev_for_each_resource(dev, r) { struct pci_bus *b; - struct resource *r =3D &dev->resource[i]; =20 if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) || !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) @@ -1795,11 +1790,9 @@ static void remove_dev_resources(struct pci_dev *dev= , struct resource *io, struct resource *mmio, struct resource *mmio_pref) { - int i; - - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *res =3D &dev->resource[i]; + struct resource *res; =20 + pci_dev_for_each_resource(dev, res) { if (resource_type(res) =3D=3D IORESOURCE_IO) { remove_dev_resource(io, dev, res); } else if (resource_type(res) =3D=3D IORESOURCE_MEM) { diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index b492e67c3d87..967f9a758923 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -484,12 +484,10 @@ int pci_enable_resources(struct pci_dev *dev, int mas= k) pci_read_config_word(dev, PCI_COMMAND, &cmd); old_cmd =3D cmd; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { + pci_dev_for_each_resource(dev, r, i) { if (!(mask & (1 << i))) continue; =20 - r =3D &dev->resource[i]; - if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) continue; if ((i =3D=3D PCI_ROM_RESOURCE) && diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index f80b6ec88dc3..5a696078b382 100644 --- a/drivers/pci/vgaarb.c +++ b/drivers/pci/vgaarb.c @@ -548,10 +548,8 @@ static bool vga_is_firmware_default(struct pci_dev *pd= ev) #if defined(CONFIG_X86) || defined(CONFIG_IA64) u64 base =3D screen_info.lfb_base; u64 size =3D screen_info.lfb_size; + struct resource *r; u64 limit; - resource_size_t start, end; - unsigned long flags; - int i; =20 /* Select the device owning the boot framebuffer if there is one */ =20 @@ -561,19 +559,14 @@ static bool vga_is_firmware_default(struct pci_dev *p= dev) limit =3D base + size; =20 /* Does firmware framebuffer belong to us? */ - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - flags =3D pci_resource_flags(pdev, i); - - if ((flags & IORESOURCE_MEM) =3D=3D 0) + pci_dev_for_each_resource(pdev, r) { + if (resource_type(r) !=3D IORESOURCE_MEM) continue; =20 - start =3D pci_resource_start(pdev, i); - end =3D pci_resource_end(pdev, i); - - if (!start || !end) + if (!r->start || !r->end) continue; =20 - if (base < start || limit >=3D end) + if (base < r->start || limit >=3D r->end) continue; =20 return true; diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index fcd029ca2eb1..83c0ab50676d 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -390,9 +390,7 @@ static int pcifront_claim_resource(struct pci_dev *dev,= void *data) int i; struct resource *r; =20 - for (i =3D 0; i < PCI_NUM_RESOURCES; i++) { - r =3D &dev->resource[i]; - + pci_dev_for_each_resource(dev, r, i) { if (!r->parent && r->start && r->flags) { dev_info(&pdev->xdev->dev, "claiming resource %s/%d\n", pci_name(dev), i); diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c index ac98b9919029..6085a1471de2 100644 --- a/drivers/pnp/quirks.c +++ b/drivers/pnp/quirks.c @@ -229,8 +229,7 @@ static void quirk_ad1815_mpu_resources(struct pnp_dev *= dev) static void quirk_system_pci_resources(struct pnp_dev *dev) { struct pci_dev *pdev =3D NULL; - struct resource *res; - resource_size_t pnp_start, pnp_end, pci_start, pci_end; + struct resource *res, *r; int i, j; =20 /* @@ -243,32 +242,26 @@ static void quirk_system_pci_resources(struct pnp_dev= *dev) * so they won't be claimed by the PNP system driver. */ for_each_pci_dev(pdev) { - for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { - unsigned long flags, type; + pci_dev_for_each_resource(pdev, r, i) { + unsigned long type =3D resource_type(r); =20 - flags =3D pci_resource_flags(pdev, i); - type =3D flags & (IORESOURCE_IO | IORESOURCE_MEM); - if (!type || pci_resource_len(pdev, i) =3D=3D 0) + if (!(type =3D=3D IORESOURCE_IO || type =3D=3D IORESOURCE_MEM) || + resource_size(r) =3D=3D 0) continue; =20 - if (flags & IORESOURCE_UNSET) + if (r->flags & IORESOURCE_UNSET) continue; =20 - pci_start =3D pci_resource_start(pdev, i); - pci_end =3D pci_resource_end(pdev, i); for (j =3D 0; (res =3D pnp_get_resource(dev, type, j)); j++) { if (res->start =3D=3D 0 && res->end =3D=3D 0) continue; =20 - pnp_start =3D res->start; - pnp_end =3D res->end; - /* * If the PNP region doesn't overlap the PCI * region at all, there's no problem. */ - if (pnp_end < pci_start || pnp_start > pci_end) + if (!resource_overlaps(res, r)) continue; =20 /* @@ -278,8 +271,7 @@ static void quirk_system_pci_resources(struct pnp_dev *= dev) * PNP device describes a bridge with PCI * behind it. */ - if (pnp_start <=3D pci_start && - pnp_end >=3D pci_end) + if (res->start <=3D r->start && res->end >=3D r->end) continue; =20 /* @@ -288,9 +280,8 @@ static void quirk_system_pci_resources(struct pnp_dev *= dev) * driver from requesting its resources. */ dev_warn(&dev->dev, - "disabling %pR because it overlaps " - "%s BAR %d %pR\n", res, - pci_name(pdev), i, &pdev->resource[i]); + "disabling %pR because it overlaps %s BAR %d %pR\n", + res, pci_name(pdev), i, r); res->flags |=3D IORESOURCE_DISABLED; } } diff --git a/include/linux/pci.h b/include/linux/pci.h index aeaa95455d4c..5cacd9e4c8cd 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -26,6 +26,7 @@ =20 #include =20 +#include #include #include #include @@ -2003,6 +2004,20 @@ int pci_iobar_pfn(struct pci_dev *pdev, int bar, str= uct vm_area_struct *vma); (pci_resource_end((dev), (bar)) ? \ resource_size(pci_resource_n((dev), (bar))) : 0) =20 +#define __pci_dev_for_each_res0(dev, res, ...) \ + for (unsigned int __b =3D 0; \ + res =3D pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ + __b++) + +#define __pci_dev_for_each_res1(dev, res, __b) \ + for (__b =3D 0; \ + res =3D pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ + __b++) + +#define pci_dev_for_each_resource(dev, res, ...) \ + CONCATENATE(__pci_dev_for_each_res, COUNT_ARGS(__VA_ARGS__)) \ + (dev, res, __VA_ARGS__) + /* * Similar to the helpers above, these manipulate per-pci_dev * driver-specific data. They are really just a wrapper around --=20 2.40.0.1.gaa8946217a0b From nobody Sun May 12 05:44:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72495C77B62 for ; Thu, 30 Mar 2023 16:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbjC3Q2y (ORCPT ); Thu, 30 Mar 2023 12:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231700AbjC3Q2f (ORCPT ); Thu, 30 Mar 2023 12:28:35 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432A8BB9C; Thu, 30 Mar 2023 09:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193712; x=1711729712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mMeyztJwnpsG6WpiZZE3Wzd++aYBpdo5TdtsAUuwHek=; b=UeetYP0z4KQE3eGjgEb1rZcZdEKa4Zt/lw25k6ICMVHP/gr5WLpuWQOv vHX230IkzboLjCyY0SQaC5V2mklJtqcbYRk2INBRiPU+nUZ2ThENiWsQl QjVZ5ibEfB6QA9H2UxZ8Z3lAFcYb+cVp+jJSkiiHMmVkMr1XHd/axlD3J 3JHxWBMqslYXAnMN15EbgPmZAp1alUykAZS6TnuASxRudTBpBTdr4LXG/ 0kqpNQWr3EUMkEcrs+OLeQYpHrCj5mOTQr8ShpTdUC6iUyfiIoVSwlr14 MPiOzkt1azTtcvTJEyW41A0oyLudH1otqOsj8j/Ds4aW4rMZ3DlizoKzE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427496059" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="427496059" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="684762351" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="684762351" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 30 Mar 2023 09:28:19 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 43047238; Thu, 30 Mar 2023 19:24:51 +0300 (EEST) From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 4/7] PCI: Document pci_bus_for_each_resource() to avoid confusion Date: Thu, 30 Mar 2023 19:24:31 +0300 Message-Id: <20230330162434.35055-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There might be a confusion with the implementation of the pci_bus_for_each_resources() due to side effect of Logical OR. Document entire macro and explain how it works and why the conditional needs to be like that. Signed-off-by: Andy Shevchenko --- include/linux/pci.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index 5cacd9e4c8cd..e3b3af606280 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1446,6 +1446,26 @@ int devm_request_pci_bus_resources(struct device *de= v, /* Temporary until new and working PCI SBR API in place */ int pci_bridge_secondary_bus_reset(struct pci_dev *dev); =20 +/** + * pci_bus_for_each_resource - iterate over PCI bus resources + * @bus: the PCI bus + * @res: a varible to keep a pointer to the current resource + * @i: a variable to keep the index of the current resource + * + * Iterate over PCI bus resources. The first part is to go over PCI bus + * resource array, which has at most the %PCI_BRIDGE_RESOURCE_NUM entries. + * After that continue with the separate list of the additional resources, + * if not empty. That's why the Logical OR is being used. + * + * Possible usage: + * + * struct pci_bus *bus =3D ...; + * struct resource *res; + * unsigned int i; + * + * pci_bus_for_each_resource(bus, res, i) + * pr_info("PCI bus resource[%u]: %pR\n", i, res); + */ #define pci_bus_for_each_resource(bus, res, i) \ for (i =3D 0; \ (res =3D pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \ --=20 2.40.0.1.gaa8946217a0b From nobody Sun May 12 05:44:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44608C6FD1D for ; Thu, 30 Mar 2023 16:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231576AbjC3Q3B (ORCPT ); Thu, 30 Mar 2023 12:29:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231767AbjC3Q2g (ORCPT ); Thu, 30 Mar 2023 12:28:36 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3C683FA; Thu, 30 Mar 2023 09:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193715; x=1711729715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VJ1PyQpGGPwbQf2lA7TScIDKb/DRRzKOJStqePaN450=; b=QDVgFCAh3EJ+pMB+BYsqmtGjC+FerPaWqyncraQAYxNWFskfaSxPDUXj je2x3xuJdOU270FN5YiA5oO3su9qC/10tN+8NJNDOsKFxenHrBEraO4iR CEreuwh8ry30/LFjLw+85DNcICTTBwd9GrpiGdtxhMFbZmbd33t6AvzQz yHclRxWBUe/KrePyfSdVRAAoO4jJMk8ZtmqvSoAzCFJKMGc/+ccIDKgRs YVqMRzSr6+FneoyA4H+VH0cdZeJdR5jLoMkpeImku1lpN9sR+2Ou9wcXD NPx2OUUVfchZ2SADd+sGLTXOkJc1z0/ilPGByhh8iTn92yze+ee5Yk3a7 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427496137" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="427496137" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="858971556" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="858971556" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 30 Mar 2023 09:28:22 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E3FC727B; Thu, 30 Mar 2023 19:24:51 +0300 (EEST) From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 5/7] PCI: Allow pci_bus_for_each_resource() to take less arguments Date: Thu, 30 Mar 2023 19:24:32 +0300 Message-Id: <20230330162434.35055-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=C5=84ski Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 | 24 +++++++++++++++++++----- 6 files changed, 32 insertions(+), 22 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; =20 type_mask |=3D IORESOURCE_TYPE_BITS; =20 - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { resource_size_t min_used =3D min; =20 if (!r) @@ -289,9 +289,8 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx) struct resource *res =3D &dev->resource[idx]; struct resource orig_res =3D *res; struct resource *r; - int i; =20 - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { resource_size_t start, end; =20 if (!r) diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpch= p_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 =3D 0; + int busnr; =20 pdev =3D to_pci_dev(dev); bus =3D pdev->subordinate; =20 len +=3D 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 +=3D sysfs_emit_at(buf, len, @@ -43,7 +43,7 @@ static ssize_t show_ctrl(struct device *dev, struct devic= e_attribute *attr, char } } len +=3D 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 +=3D sysfs_emit_at(buf, len, @@ -53,7 +53,7 @@ static ssize_t show_ctrl(struct device *dev, struct devic= e_attribute *attr, char } } len +=3D 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 +=3D sysfs_emit_at(buf, len, "start =3D %8.8llx, length =3D %8.8llx\n", diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 45c3bb039f21..585bb3988ddf 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 =3D dev->bus; struct resource *r; - int i; =20 - 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); =20 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(struc= t pci_bus *bus, unsigned long type) { struct resource *r, *r_assigned =3D NULL; - int i; =20 - pci_bus_for_each_resource(bus, r, i) { + pci_bus_for_each_resource(bus, r) { if (r =3D=3D &ioport_resource || r =3D=3D &iomem_resource) continue; if (r && (r->flags & type_mask) =3D=3D type && !r->parent) @@ -1204,7 +1203,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, stru= ct list_head *realloc_head) additional_mmio_pref_size =3D 0; struct resource *pref; struct pci_host_bridge *host; - int hdr_type, i, ret; + int hdr_type, ret; =20 list_for_each_entry(dev, &bus->devices, bus_list) { struct pci_bus *b =3D dev->subordinate; @@ -1228,7 +1227,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, stru= ct list_head *realloc_head) host =3D 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 =3D -1; /* Intentionally invalid - not a PCI device. */ @@ -1333,12 +1332,11 @@ EXPORT_SYMBOL(pci_bus_size_bridges); =20 static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resourc= e *r) { - int i; struct resource *parent_r; unsigned long mask =3D IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH; =20 - pci_bus_for_each_resource(b, parent_r, i) { + pci_bus_for_each_resource(b, parent_r) { if (!parent_r) continue; =20 diff --git a/include/linux/pci.h b/include/linux/pci.h index e3b3af606280..56670d016cac 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1446,11 +1446,21 @@ int devm_request_pci_bus_resources(struct device *d= ev, /* Temporary until new and working PCI SBR API in place */ int pci_bridge_secondary_bus_reset(struct pci_dev *dev); =20 +#define __pci_bus_for_each_res0(bus, res, ...) \ + for (unsigned int __b =3D 0; \ + (res =3D pci_bus_resource_n(bus, __b)) || __b < PCI_BRIDGE_RESOURCE_= NUM; \ + __b++) + +#define __pci_bus_for_each_res1(bus, res, __b) \ + for (__b =3D 0; \ + (res =3D pci_bus_resource_n(bus, __b)) || __b < PCI_BRIDGE_RESOURCE_= NUM; \ + __b++) + /** * pci_bus_for_each_resource - iterate over PCI bus resources * @bus: the PCI bus * @res: a varible to keep a pointer to the current resource - * @i: a variable to keep the index of the current resource + * @...: an optional variable to keep the index of the current resource * * Iterate over PCI bus resources. The first part is to go over PCI bus * resource array, which has at most the %PCI_BRIDGE_RESOURCE_NUM entries. @@ -1463,13 +1473,17 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *= dev); * struct resource *res; * unsigned int i; * + * // With an additional index variable * pci_bus_for_each_resource(bus, res, i) * pr_info("PCI bus resource[%u]: %pR\n", i, res); + * + * // Without index + * pci_bus_for_each_resource(bus, res) + * _do_something_(res); */ -#define pci_bus_for_each_resource(bus, res, i) \ - for (i =3D 0; \ - (res =3D pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \ - i++) +#define pci_bus_for_each_resource(bus, res, ...) \ + CONCATENATE(__pci_bus_for_each_res, COUNT_ARGS(__VA_ARGS__)) \ + (bus, res, __VA_ARGS__) =20 int __must_check pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, --=20 2.40.0.1.gaa8946217a0b From nobody Sun May 12 05:44:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76D24C761A6 for ; Thu, 30 Mar 2023 16:29:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232147AbjC3Q25 (ORCPT ); Thu, 30 Mar 2023 12:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231776AbjC3Q2g (ORCPT ); Thu, 30 Mar 2023 12:28:36 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A55B46F; Thu, 30 Mar 2023 09:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193714; x=1711729714; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xbQWUNZRhMDKSfWq+Wm+hoCdoGH5KZ6pm5K/n+XSSwM=; b=HT85l5NYyZLNzawnUtxbMAOFjsxDUmwxdiOu9NPsFbr3jTarqFqrumeb ADFomDuksf0r16xVkhXHTJtMi82ssKSmNZVJm1IueNDOuEQEnMsuWdwpV k5On/KlKTBy4Qv4YbZUQJakA7oFY7c0Mq8GyeD1CsnlHxSNF1WSa0TM+D XGlYiPil0mPNDQCh2gVTQw+xJD8WDYczG5X0SxONWIt9k6yPns26oWl5b nF/gzBfSKEdbt0TBLd9Xjr7N6aF30BQ82lhXJ0cs9P8giPP/J249Xkvzx nYLM3TZfjZ+uz1sQ2h93CPQuhtNYLmUWeBaFSvqW1dM68/NjirmKPZ10v A==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427496093" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="427496093" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="858971554" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="858971554" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 30 Mar 2023 09:28:22 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 85CC62BE; Thu, 30 Mar 2023 19:24:52 +0300 (EEST) From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 6/7] EISA: Convert to use less arguments in pci_bus_for_each_resource() Date: Thu, 30 Mar 2023 19:24:33 +0300 Message-Id: <20230330162434.35055-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pci_bus_for_each_resource() can hide the iterator loop since it may be not used otherwise. With this, we may drop that iterator variable definition. Signed-off-by: Andy Shevchenko Reviewed-by: Krzysztof Wilczy=C5=84ski Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- drivers/eisa/pci_eisa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/eisa/pci_eisa.c b/drivers/eisa/pci_eisa.c index 930c2332c3c4..8173e60bb808 100644 --- a/drivers/eisa/pci_eisa.c +++ b/drivers/eisa/pci_eisa.c @@ -20,8 +20,8 @@ static struct eisa_root_device pci_eisa_root; =20 static int __init pci_eisa_init(struct pci_dev *pdev) { - int rc, i; struct resource *res, *bus_res =3D NULL; + int rc; =20 if ((rc =3D pci_enable_device (pdev))) { dev_err(&pdev->dev, "Could not enable device\n"); @@ -38,7 +38,7 @@ static int __init pci_eisa_init(struct pci_dev *pdev) * eisa_root_register() can only deal with a single io port resource, * so we use the first valid io port resource. */ - pci_bus_for_each_resource(pdev->bus, res, i) + pci_bus_for_each_resource(pdev->bus, res) if (res && (res->flags & IORESOURCE_IO)) { bus_res =3D res; break; --=20 2.40.0.1.gaa8946217a0b From nobody Sun May 12 05:44:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680193753; cv=none; d=zohomail.com; s=zohoarc; b=LWN88cRsh3PM+cgydvfzSUOYFeczsz6b76xK8xJ1s/nYHXsGl/NZtlmqWU4GvwP2O9lJXZvsVOAGmJAVslscbxaPXXUMJcsS3SiiTjL3ISJaSnQi3Ck8t0XJ/Ztq4mgURU2Y4dX6UIv+NI4BjsdQOIkaQvm8C4fl+Q3tgZU4/0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680193753; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QeL1AtwXSCu6BtHRaduBPNduuZbKi0vfmTR7h3cfRP8=; b=htbzH8tXnlHpXIp+DWZFQRar2Vvrgm1LuhtXcMv5sZ2iQ4zilssXq8lVPcY2lAGxlKStdcguYcUiYVUFcrLMDLtYZpVapYsNXBqwQ/A0gGHxl1tVnJw5iuP7MNtqxYNrzJ5whj54xitmpY+LiYajov9swnyyfHAaQ8Mr5LuV8UQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1680193753508600.5661102378227; Thu, 30 Mar 2023 09:29:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516812.801576 (Exim 4.92) (envelope-from ) id 1phv8r-0006PJ-TI; Thu, 30 Mar 2023 16:28:49 +0000 Received: by outflank-mailman (output) from mailman id 516812.801576; Thu, 30 Mar 2023 16:28:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phv8r-0006P3-PS; Thu, 30 Mar 2023 16:28:49 +0000 Received: by outflank-mailman (input) for mailman id 516812; Thu, 30 Mar 2023 16:28:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phv8q-0004tu-LQ for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 16:28:48 +0000 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f0b8694e-cf17-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 18:28:46 +0200 (CEST) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 09:28:39 -0700 Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 30 Mar 2023 09:28:29 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4A5522E9; Thu, 30 Mar 2023 19:24:53 +0300 (EEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f0b8694e-cf17-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680193726; x=1711729726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CylzEgRAmJXOphwnxg3IbL2UXwW6z4Wch9KnUOezzDg=; b=KWdy3V8PuSK/O9+XoiZNNnunwlnaY0F5BUg2OmimFGnUp1wZTl/5exrd n+Y4U9UnzKB6Z9GKmhDGSNR2o2dH3Q7NpSAAyCguS5g2e352hfvqPvTZY Oe3T/kdo859DwvyFStL/tlET33PdcZReDeYUjwW+THHn9NJt/EgzB5iFu m3n6ZV9BdGCKM1zXnx9IMgiG5fzIDnLiy3qHNH0XARN5GBQ6zmGnaRVQy 51sAhUOcMNf8gqAciCcgBZ0cZkJUHaoWMgaAAUN+YaZO5Qn66i+J4sk5y LFNYcI8Y6c7fa8VQu7ZjaTOxplNoa/sh2M5to+Y3BJGGMBC9szhGUuc98 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="321607014" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="321607014" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="687307670" X-IronPort-AV: E=Sophos;i="5.98,305,1673942400"; d="scan'208";a="687307670" From: Andy Shevchenko To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Andy Shevchenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Mika Westerberg , Michael Ellerman , Randy Dunlap , Arnd Bergmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Niklas Schnelle , Bjorn Helgaas , "Rafael J. Wysocki" , =?UTF-8?q?Pali=20Roh=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 v8 7/7] pcmcia: Convert to use less arguments in pci_bus_for_each_resource() Date: Thu, 30 Mar 2023 19:24:34 +0300 Message-Id: <20230330162434.35055-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> References: <20230330162434.35055-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1680193754695100001 The pci_bus_for_each_resource() can hide the iterator loop since it may be not used otherwise. With this, we may drop that iterator variable definition. Signed-off-by: Andy Shevchenko Reviewed-by: Krzysztof Wilczy=C5=84ski Acked-by: Dominik Brodowski --- drivers/pcmcia/rsrc_nonstatic.c | 9 +++------ drivers/pcmcia/yenta_socket.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstati= c.c index ad1141fddb4c..96264ebee46a 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -934,7 +934,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned = int action, unsigned long static int nonstatic_autoadd_resources(struct pcmcia_socket *s) { struct resource *res; - int i, done =3D 0; + int done =3D 0; =20 if (!s->cb_dev || !s->cb_dev->bus) return -ENODEV; @@ -960,12 +960,9 @@ static int nonstatic_autoadd_resources(struct pcmcia_s= ocket *s) */ if (s->cb_dev->bus->number =3D=3D 0) return -EINVAL; - - for (i =3D 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { - res =3D s->cb_dev->bus->resource[i]; -#else - pci_bus_for_each_resource(s->cb_dev->bus, res, i) { #endif + + pci_bus_for_each_resource(s->cb_dev->bus, res) { if (!res) continue; =20 diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 1365eaa20ff4..fd18ab571ce8 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -673,9 +673,8 @@ static int yenta_search_res(struct yenta_socket *socket= , struct resource *res, u32 min) { struct resource *root; - int i; =20 - pci_bus_for_each_resource(socket->dev->bus, root, i) { + pci_bus_for_each_resource(socket->dev->bus, root) { if (!root) continue; =20 --=20 2.40.0.1.gaa8946217a0b