PCI: Add pci_dev_for_each_resource() helper and refactor bus one
Subsystems (10)
v2 cover PCI: Add pci_dev_for_each_resource() helper and refactor bus one
Provide two new helper macros to iterate over PCI device resources and convert users.
Looking at it, refactor existing pci_bus_for_each_resource() and convert users accordingly.
This applies on top of this patch Mika sent out earlier:
https://lore.kernel.org/linux-pci/[email protected]/
Changelog v2:
- refactor to have two macros
- refactor existing pci_bus_for_each_resource() in the same way and convert users
Andy Shevchenko (3):
PCI: Split pci_bus_for_each_resource_p() out of
pci_bus_for_each_resource()
EISA: Convert to use pci_bus_for_each_resource_p()
pcmcia: Convert to use pci_bus_for_each_resource_p()
Mika Westerberg (1):
PCI: Introduce pci_dev_for_each_resource()
.clang-format | 3 +++ arch/alpha/kernel/pci.c | 5 ++--- arch/arm/kernel/bios32.c | 16 ++++++------- arch/mips/pci/pci-legacy.c | 3 +-- arch/powerpc/kernel/pci-common.c | 5 ++--- arch/sparc/kernel/leon_pci.c | 5 ++--- arch/sparc/kernel/pci.c | 10 ++++----- arch/sparc/kernel/pcic.c | 5 ++--- drivers/eisa/pci_eisa.c | 4 ++-- drivers/pci/bus.c | 7 +++--- drivers/pci/hotplug/shpchp_sysfs.c | 8 +++---- drivers/pci/pci.c | 5 ++--- drivers/pci/probe.c | 2 +- drivers/pci/remove.c | 5 ++--- drivers/pci/setup-bus.c | 36 ++++++++++++------------------ drivers/pci/setup-res.c | 4 +--- drivers/pci/xen-pcifront.c | 4 +--- drivers/pcmcia/rsrc_nonstatic.c | 9 +++----- drivers/pcmcia/yenta_socket.c | 3 +-- include/linux/pci.h | 25 +++++++++++++++++---- 20 files changed, 78 insertions(+), 86 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/4 PCI: Introduce pci_dev_for_each_resource()
From: Mika Westerberg <[email protected]>
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.
--- .clang-format | 2 ++ arch/alpha/kernel/pci.c | 5 ++--- arch/arm/kernel/bios32.c | 16 +++++++--------- arch/mips/pci/pci-legacy.c | 3 +-- arch/powerpc/kernel/pci-common.c | 5 ++--- 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 | 26 ++++++++++---------------- drivers/pci/setup-res.c | 4 +--- drivers/pci/xen-pcifront.c | 4 +--- include/linux/pci.h | 11 +++++++++++ 13 files changed, 47 insertions(+), 54 deletions(-)
.clang-format +2 -0
@@ -520,6 +520,8 @@ ForEachMacros: - 'of_property_for_each_string' - 'of_property_for_each_u32' - 'pci_bus_for_each_resource' + - 'pci_dev_for_each_resource' + - 'pci_dev_for_each_resource_p' - 'pci_doe_for_each_off' - 'pcl_for_each_chunk' - 'pcl_for_each_segment'
arch/alpha/kernel/pci.c +2 -3
@@ -288,11 +288,10 @@ pcibios_claim_one_bus(struct pci_bus *b)struct pci_bus *child_bus;list_for_each_entry (dev, &b->devices, bus_list) { +struct resource *r;int i; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *r = &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) ||
arch/arm/kernel/bios32.c +7 -9
@@ -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 ==0 ) { +struct resource *r; + dev->class &=0xff ; dev->class |=PCI_CLASS_BRIDGE_HOST <<8 ; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { - dev->resource[i].start =0 ; - dev->resource[i].end =0 ; - dev->resource[i].flags =0 ; +pci_dev_for_each_resource_p (dev, r) { + r->start =0 ; + r->end =0 ; + r->flags =0 ; } } }
@@ -162,13 +162,11 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, pci_fixup_dstatic void pci_fixup_ide_bases (struct pci_dev *dev) {struct resource *r; -int i;if ((dev->class >>8 ) !=PCI_CLASS_STORAGE_IDE )return ; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { - r = dev->resource + i; +pci_dev_for_each_resource_p (dev, r) {if ((r->start & ~0x80 ) ==0x374 ) { r->start |=2 ; r->end = r->start;
arch/mips/pci/pci-legacy.c +1 -2
@@ -249,12 +249,11 @@ static int pcibios_enable_resources(struct pci_dev *dev, int mask)pci_read_config_word (dev,PCI_COMMAND , &cmd); old_cmd = cmd; -for (idx =0 ; idx <PCI_NUM_RESOURCES ; idx++) { +pci_dev_for_each_resource (dev, r, idx) {/* Only set up the requested stuff */ if (!(mask & (1 <<idx)))continue ; - r = &dev->resource[idx];if (!(r->flags & (IORESOURCE_IO |IORESOURCE_MEM )))continue ; if ((idx == PCI_ROM_RESOURCE) &&
arch/powerpc/kernel/pci-common.c +2 -3
@@ -1452,11 +1452,10 @@ void pcibios_claim_one_bus(struct pci_bus *bus)struct pci_bus *child_bus;list_for_each_entry (dev, &bus->devices, bus_list) { +struct resource *r;int i; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *r = &dev->resource[i]; - +pci_dev_for_each_resource (dev, r, i) {if (r->parent || !r->start || !r->flags)continue ;
arch/sparc/kernel/leon_pci.c +2 -3
@@ -62,15 +62,14 @@ void leon_pci_init(struct platform_device *ofdev, struct leon_pci_info *info)int pcibios_enable_device (struct pci_dev *dev,int mask) { +struct resource *res;u16 cmd, oldcmd;int i;pci_read_config_word (dev,PCI_COMMAND , &cmd); oldcmd = cmd; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *res = &dev->resource[i]; - +pci_dev_for_each_resource (dev, res, i) {/* Only set up the requested stuff */ if (!(mask & (1 <<i)))continue ;
arch/sparc/kernel/pci.c +4 -6
@@ -663,11 +663,10 @@ static void pci_claim_bus_resources(struct pci_bus *bus)struct pci_dev *dev;list_for_each_entry (dev, &bus->devices, bus_list) { +struct resource *r;int i; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *r = &dev->resource[i]; - +pci_dev_for_each_resource (dev, r, i) {if (r->parent || !r->start || !r->flags)continue ;
@@ -724,15 +723,14 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,int pcibios_enable_device (struct pci_dev *dev,int mask) { +struct resource *res;u16 cmd, oldcmd;int i;pci_read_config_word (dev,PCI_COMMAND , &cmd); oldcmd = cmd; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *res = &dev->resource[i]; - +pci_dev_for_each_resource (dev, res, i) {/* Only set up the requested stuff */ if (!(mask & (1 <<i)))continue ;
arch/sparc/kernel/pcic.c +2 -3
@@ -643,15 +643,14 @@ void pcibios_fixup_bus(struct pci_bus *bus)int pcibios_enable_device (struct pci_dev *dev,int mask) { +struct resource *res;u16 cmd, oldcmd;int i;pci_read_config_word (dev,PCI_COMMAND , &cmd); oldcmd = cmd; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *res = &dev->resource[i]; - +pci_dev_for_each_resource (dev, res, i) {/* Only set up the requested stuff */ if (!(mask & (1 <<i)))continue ;
drivers/pci/remove.c +2 -3
@@ -5,10 +5,9 @@static void pci_free_resources (struct pci_dev *dev) { -int i; +struct resource *res; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *res = dev->resource + i; +pci_dev_for_each_resource_p (dev, res) {if (res->parent)release_resource (res); }
drivers/pci/setup-bus.c +10 -16
@@ -124,20 +124,17 @@ static resource_size_t get_res_add_align(struct list_head *head,return dev_res ? dev_res->min_align :0 ; } -/* Sort resources by alignment */ static void pdev_sort_resources (struct pci_dev *dev,struct list_head *head) { +struct resource *r;int i; -for (i =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; - r = &dev->resource[i]; -if (r->flags &IORESOURCE_PCI_FIXED )continue ;
@@ -895,10 +892,9 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, min_align =window_alignment (bus,IORESOURCE_IO );list_for_each_entry (dev, &bus->devices, bus_list) { -int i; +struct resource *r; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *r = &dev->resource[i]; +pci_dev_for_each_resource_p (dev, r) {unsigned long r_size;if (r->parent || !(r->flags &IORESOURCE_IO ))
@@ -1014,10 +1010,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, size =0 ;list_for_each_entry (dev, &bus->devices, bus_list) { +struct resource *r;int i; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -struct resource *r = &dev->resource[i]; +pci_dev_for_each_resource (dev, r, i) {resource_size_t r_size; 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; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { +pci_dev_for_each_resource_p (dev, r) {struct pci_bus *b; -struct resource *r = &dev->resource[i];if (r->parent || !(r->flags &IORESOURCE_PCI_FIXED ) || !(r->flags & (IORESOURCE_IO |IORESOURCE_MEM )))
@@ -1845,7 +1840,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,* distributing the rest. */ list_for_each_entry (dev, &bus->devices, bus_list) { -int i; +struct resource *dev_res;if (dev == bridge)continue ;
@@ -1857,8 +1852,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,if (!dev->multifunction)return ; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { -const struct resource *dev_res = &dev->resource[i]; +pci_dev_for_each_resource_p (dev, dev_res) {resource_size_t dev_sz;struct resource *b_res;
drivers/pci/setup-res.c +1 -3
@@ -484,12 +484,10 @@ int pci_enable_resources(struct pci_dev *dev, int mask)pci_read_config_word (dev,PCI_COMMAND , &cmd); old_cmd = cmd; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { +pci_dev_for_each_resource (dev, r, i) {if (!(mask & (1 << i)))continue ; - r = &dev->resource[i]; -if (!(r->flags & (IORESOURCE_IO |IORESOURCE_MEM )))continue ; if ((i == PCI_ROM_RESOURCE) &&
drivers/pci/xen-pcifront.c +1 -3
@@ -390,9 +390,7 @@ static int pcifront_claim_resource(struct pci_dev *dev, void *data)int i;struct resource *r; -for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { - r = &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);
include/linux/pci.h +11 -0
@@ -1407,6 +1407,17 @@ int pci_request_selected_regions(struct pci_dev *, int, const char *);int pci_request_selected_regions_exclusive (struct pci_dev *,int ,const char *);void pci_release_selected_regions (struct pci_dev *,int ); +#define __pci_dev_for_each_resource (dev, res, __i, vartype) \ + for (vartype __i = 0; \ + res = &(dev)->resource[__i], __i < PCI_NUM_RESOURCES; \ + __i++) + +#define pci_dev_for_each_resource (dev, res, i) \ + __pci_dev_for_each_resource(dev, res, i, ) + +#define pci_dev_for_each_resource_p (dev, res) \ + __pci_dev_for_each_resource(dev, res, i, unsigned int) +/* drivers/pci/bus.c */ void pci_add_resource (struct list_head *resources,struct resource *res); void pci_add_resource_offset(struct list_head *resources, struct resource *res,
Signature · 1 line
2.35.1
PATCH v2 2/4 PCI: Split pci_bus_for_each_resource_p() out of pci_bus_for_each_resource()
In reply to Andy ShevchenkoRefactor 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.
--- .clang-format | 1 + drivers/pci/bus.c | 7 +++---- drivers/pci/hotplug/shpchp_sysfs.c | 8 ++++---- drivers/pci/pci.c | 5 ++--- drivers/pci/probe.c | 2 +- drivers/pci/setup-bus.c | 10 ++++------ include/linux/pci.h | 14 ++++++++++---- 7 files changed, 25 insertions(+), 22 deletions(-)
.clang-format +1 -0
@@ -520,6 +520,7 @@ ForEachMacros: - 'of_property_for_each_string' - 'of_property_for_each_u32' - 'pci_bus_for_each_resource' + - 'pci_bus_for_each_resource_p' - 'pci_dev_for_each_resource' - 'pci_dev_for_each_resource_p' - 'pci_doe_for_each_off'
drivers/pci/bus.c +3 -4
@@ -161,13 +161,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_p (bus, r) {resource_size_t min_used = min;if (!r)
@@ -264,9 +264,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_p (bus, r) {resource_size_t start, end;if (!r)
drivers/pci/hotplug/shpchp_sysfs.c +4 -4
@@ -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_p (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_p (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_p (bus, res) {if (res && (res->flags &IORESOURCE_IO )) { len += sysfs_emit_at(buf, len, "start = %8.8llx, length = %8.8llx\n",
drivers/pci/pci.c +2 -3
@@ -782,9 +782,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_p (bus, r) {if (!r)continue ;if (resource_contains (r, res)) {
@@ -802,7 +801,7 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,* be both a positively-decoded aperture and a * subtractively-decoded region that contain the BAR. * We want the positively-decoded one, so this depends -* on pci_bus_for_each_resource() giving us those +* on pci_bus_for_each_resource_p() giving us those * first. */ return r;
drivers/pci/probe.c +1 -1
@@ -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_p (child->parent, res) {if (res && res->flags) {pci_bus_add_resource (child, res,PCI_SUBTRACTIVE_DECODE );
drivers/pci/setup-bus.c +4 -6
@@ -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_p (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_p (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_p (b, parent_r) {if (!parent_r)continue ;
include/linux/pci.h +10 -4
@@ -1433,10 +1433,16 @@ 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 (bus, res, __i, vartype) \ + for (vartype __i = 0; \ + res = pci_bus_resource_n(bus, __i), __i < PCI_BRIDGE_RESOURCE_NUM; \ + __i++) + +#define pci_bus_for_each_resource (bus, res, i) \ + __pci_bus_for_each_resource(bus, res, i, ) + +#define pci_bus_for_each_resource_p (bus, res) \ + __pci_bus_for_each_resource(bus, res, i, unsigned int) int __must_check pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size,
Signature · 1 line
2.35.1
PATCH v2 3/4 EISA: Convert to use pci_bus_for_each_resource_p()
In reply to Andy ShevchenkoThe pci_bus_for_each_resource_p() hides the iterator loop since it may be not used otherwise. With this, we may drop that iterator variable definition.
--- drivers/eisa/pci_eisa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/eisa/pci_eisa.c +2 -2
@@ -20,8 +20,8 @@ static struct eisa_root_device pci_eisa_root;static int __init pci_eisa_init (struct pci_dev *pdev) { -int rc, i;struct resource *res, *bus_res =NULL ; +int rc;if ((rc =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_p (pdev->bus, res)if (res && (res->flags &IORESOURCE_IO )) { bus_res = res;break ;
Signature · 1 line
2.35.1
PATCH v2 4/4 pcmcia: Convert to use pci_bus_for_each_resource_p()
In reply to Andy ShevchenkoThe pci_bus_for_each_resource_p() hides the iterator loop since it may be not used otherwise. With this, we may drop that iterator variable definition.
--- drivers/pcmcia/rsrc_nonstatic.c | 9 +++------ drivers/pcmcia/yenta_socket.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/pcmcia/rsrc_nonstatic.c +3 -6
@@ -934,7 +934,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned longstatic int nonstatic_autoadd_resources (struct pcmcia_socket *s) {struct resource *res; -int i, done =0 ; +int done =0 ;if (!s->cb_dev || !s->cb_dev->bus)return -ENODEV ;
@@ -960,12 +960,9 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)*/ if (s->cb_dev->bus->number ==0 )return -EINVAL ; - -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {#endif + +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;
drivers/pcmcia/yenta_socket.c +1 -2
@@ -673,9 +673,8 @@ static int yenta_search_res(struct yenta_socket *socket, struct resource *res, u32 min) {struct resource *root; -int i; -pci_bus_for_each_resource (socket->dev->bus, root, i) { +pci_bus_for_each_resource_p (socket->dev->bus, root) {if (!root)continue ;
Signature · 1 line
2.35.1
Dominik Brodowski
maintainerRe: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
Am Thu, Nov 03, 2022 at 06:46:44PM +0200 schrieb Andy Shevchenko:
Quoted 3 lines
The
pci_bus_for_each_resource_p()hides the iterator loop since it may be not used otherwise. With this, we may drop that iterator variable definition.
Thanks for your patch!
Quoted 17 lines
drivers/pcmcia/rsrc_nonstatic.c +1
-1@@ -934,7 +934,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned longstatic int nonstatic_autoadd_resources (struct pcmcia_socket *s) {struct resource *res; -int i, done =0 ; +int done =0 ;if (!s->cb_dev || !s->cb_dev->bus)return -ENODEV ;@@ -960,12 +960,9 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)*/ if (s->cb_dev->bus->number ==0 )return -EINVAL ;
drivers/pcmcia/rsrc_nonstatic.c static int nonstatic_autoadd_resources(struct pcmcia_socket *s) · line 967
Quoted 10 lines
drivers/pcmcia/rsrc_nonstatic.c +2
-5- -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {#endif + +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;
Doesn't this remove the proper iterator for X86? Even if that is the right thing to do, it needs an explict explanation.
Quoted 6 lines
drivers/pcmcia/yenta_socket.c +0
-0
drivers/pcmcia/yenta_socket.c static int yenta_search_res(struct yenta_socket *socket, struct resource *res, · line 680
Quoted 10 lines
drivers/pcmcia/yenta_socket.c +1
-2@@ -673,9 +673,8 @@ static int yenta_search_res(struct yenta_socket *socket, struct resource *res, u32 min) {struct resource *root; -int i; -pci_bus_for_each_resource (socket->dev->bus, root, i) { +pci_bus_for_each_resource_p (socket->dev->bus, root) {if (!root)continue ;
That looks fine!
Thanks,
Dominik
Re: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
Quoted 1 line · Dominik Brodowski
Am Thu, Nov 03, 2022 at 06:46:44PM +0200 schrieb Andy Shevchenko:
...
Quoted 5 lines
Quoted 5 lines
drivers/pcmcia/rsrc_nonstatic.c +0
-5- -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {
Quoted 8 lines
drivers/pcmcia/rsrc_nonstatic.c static int nonstatic_autoadd_resources(struct pcmcia_socket *s) · line 967
Quoted 5 lines
#endif
drivers/pcmcia/rsrc_nonstatic.c +2
-0+ +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;Doesn't this remove the proper iterator for X86? Even if that is the right thing to do, it needs an explict explanation.
I dunno what was in 2010, but reading code now I have found no differences in the logic on how resources are being iterated in these two pieces of code.
But fine, I will add a line to a commit message about this change.
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
Am Thu, Nov 03, 2022 at 07:12:45PM +0200 schrieb Andy Shevchenko:
Quoted 19 lines · Dominik Brodowski
Quoted 1 line
Am Thu, Nov 03, 2022 at 06:46:44PM +0200 schrieb Andy Shevchenko:
...
Quoted 5 lines
Quoted 5 lines
drivers/pcmcia/rsrc_nonstatic.c +0
-5- -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {Quoted 8 lines
drivers/pcmcia/rsrc_nonstatic.c static int nonstatic_autoadd_resources(struct pcmcia_socket *s) · line 967
Quoted 5 lines
#endif
drivers/pcmcia/rsrc_nonstatic.c +2
-0+ +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;Doesn't this remove the proper iterator for X86? Even if that is the right thing to do, it needs an explict explanation.
Quoted 7 lines
I dunno what was in 2010, but reading code now I have found no differences in the logic on how resources are being iterated in these two pieces of code.
But fine, I will add a line to a commit message about this change.
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
Certainly, feel free to add
Thanks,
Dominik
Re: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
Quoted 2 lines · Dominik Brodowski
Am Thu, Nov 03, 2022 at 07:12:45PM +0200 schrieb Andy Shevchenko:
Quoted 1 line · Dominik Brodowski
...
Quoted 6 lines
Quoted 2 lines
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
Certainly, feel free to add
Thank you for the review!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
In reply to Andy ShevchenkoHello,
[...]
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/pcmcia/rsrc_nonstatic.c +0
-5- -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {Quoted 8 lines
drivers/pcmcia/rsrc_nonstatic.c static int nonstatic_autoadd_resources(struct pcmcia_socket *s) · line 967
Quoted 5 lines
#endif
drivers/pcmcia/rsrc_nonstatic.c +2
-0+ +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;Doesn't this remove the proper iterator for X86? Even if that is the right thing to do, it needs an explict explanation.
Quoted 2 lines
I dunno what was in 2010, but reading code now I have found no differences in the logic on how resources are being iterated in these two pieces of code.
This code is over a decade old (13 years old to be precise) and there was something odd between Bjorn's and Jesse's patches, as per:
89a74ecccd1f ("PCI: add pci_bus_for_each_resource(), remove direct bus->resource[] refs") cf26e8dc4194 ("pcmcia: do not autoadd root PCI bus resources")
Quoted 1 line
But fine, I will add a line to a commit message about this change.
I wouldn't, personally. The change you are proposing is self-explanatory and somewhat in-line with what is there already - unless I am also reading the current implementation wrong.
That said, Dominik is the maintainer of PCMCIA driver, so his is the last word, so to speak. :)
Quoted 2 lines
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
No need, really. Again, unless Dominik thinks otherwise.
Krzysztof
Dominik Brodowski
maintainerRe: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
Am Fri, Nov 04, 2022 at 03:29:44AM +0900 schrieb Krzysztof Wilczyński:
Quoted 32 lines
Hello,
[...]
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/pcmcia/rsrc_nonstatic.c +0
-5- -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {Quoted 8 lines
drivers/pcmcia/rsrc_nonstatic.c static int nonstatic_autoadd_resources(struct pcmcia_socket *s) · line 967
Quoted 5 lines
#endif
drivers/pcmcia/rsrc_nonstatic.c +2
-0+ +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;Doesn't this remove the proper iterator for X86? Even if that is the right thing to do, it needs an explict explanation.
Quoted 2 lines
I dunno what was in 2010, but reading code now I have found no differences in the logic on how resources are being iterated in these two pieces of code.
This code is over a decade old (13 years old to be precise) and there was something odd between Bjorn's and Jesse's patches, as per:
89a74ecccd1f("PCI: addpci_bus_for_each_resource(), remove direct bus->resource[] refs")cf26e8dc4194("pcmcia: do not autoadd root PCI bus resources")Quoted 1 line
But fine, I will add a line to a commit message about this change.
I wouldn't, personally. The change you are proposing is self-explanatory and somewhat in-line with what is there already - unless I am also reading the current implementation wrong.
Quoted 7 lines
That said, Dominik is the maintainer of PCMCIA driver, so his is the last word, so to speak. :)
Quoted 2 lines
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
No need, really. Again, unless Dominik thinks otherwise.
Ah, thanks for the correction. Then v2 is perfectly fine.
Thanks,
Dominik
Re: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
Quoted 1 line · Dominik Brodowski
Am Fri, Nov 04, 2022 at 03:29:44AM +0900 schrieb Krzysztof Wilczyński:
...
Quoted 9 lines
Quoted 7 lines
That said, Dominik is the maintainer of PCMCIA driver, so his is the last word, so to speak. :)
Quoted 2 lines
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
No need, really. Again, unless Dominik thinks otherwise.
Ah, thanks for the correction. Then v2 is perfectly fine.
I'm fine with either, thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()
In reply to Krzysztof WilczyńskiQuoted 14 lines · Krzysztof WilczyÅ„ski
Quoted 14 lines
Quoted 13 lines
drivers/pcmcia/rsrc_nonstatic.c static int nonstatic_autoadd_resources(struct pcmcia_socket *s) · line 967
Quoted 10 lines
drivers/pcmcia/rsrc_nonstatic.c +2
-5- -for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) { - res = s->cb_dev->bus->resource[i]; -#else -pci_bus_for_each_resource (s->cb_dev->bus, res, i) {#endif + +pci_bus_for_each_resource_p (s->cb_dev->bus, res) {if (!res)continue ;Doesn't this remove the proper iterator for X86? Even if that is the right thing to do, it needs an explict explanation.
Quoted 8 lines
Quoted 2 lines
I dunno what was in 2010, but reading code now I have found no differences in the logic on how resources are being iterated in these two pieces of code.
This code is over a decade old (13 years old to be precise) and there was something odd between Bjorn's and Jesse's patches, as per:
89a74ecccd1f("PCI: addpci_bus_for_each_resource(), remove direct bus->resource[] refs")cf26e8dc4194("pcmcia: do not autoadd root PCI bus resources")
Yeah, thanks for pointing out to the other patch from the same 2010 year. It seems the code was completely identical that time, now it uses more sophisticated way of getting bus resources, but it's kept the same for the resources under PCI_BRIDGE_RESOURCE_NUM threshold.
Quoted 5 lines
Quoted 1 line
But fine, I will add a line to a commit message about this change.
I wouldn't, personally. The change you are proposing is self-explanatory and somewhat in-line with what is there already - unless I am also reading the current implementation wrong.
But it wouldn't be harmful either.
Quoted 7 lines
That said, Dominik is the maintainer of PCMCIA driver, so his is the last word, so to speak. :)
Quoted 2 lines
Considering this is done, can you issue your conditional tag so I will incorporate it in v3?
No need, really. Again, unless Dominik thinks otherwise.
I think that what is wanted to have to get his tag.
Thanks for review, both of you, guys!
Signature · 2 lines
With Best Regards, Andy Shevchenko