Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: sashiko-reviews@lists.linux.dev
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	 intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	 linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 14/16] PCI: Add iterators for devices and resources in bus windows
Date: Sat, 5 Dec 2026 03:12:41 +0200 (EET)	[thread overview]
Message-ID: <bf375588-f087-a7e8-8fec-c56a39412701@linux.intel.com> (raw)
In-Reply-To: <sashiko-outbox-250875@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 3211 bytes --]

On Sat, 5 Dec 2026, sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] PCI: break inside pci_bus_for_each_window_resource() only exits
>   inner loop
> --
> 
> commit 73da7b0150edfd796b5aa15f8d77912a014f57a3
> Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> 
> PCI: Add iterators for devices and resources in bus windows
> 
> This commit adds pci_bus_for_each_window_dev() and
> pci_bus_for_each_window_resource() to iterate over devices on a bus (and
> below its transparent bridges) and their resources that reside directly in
> a given bus window.
> 
> > diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> > index 77efa4c5c960e..9d0cbe6c89917 100644
> > --- a/drivers/pci/pci.h
> > +++ b/drivers/pci/pci.h
> 
> [ ... ]
> 
> > @@ -546,6 +547,27 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
> >  void pci_walk_bus_locked(struct pci_bus *top,
> >  			 int (*cb)(struct pci_dev *, void *),
> >  			 void *userdata);
> > +struct pci_dev *pci_bus_next_window_dev(struct pci_bus *bus,
> > +					struct pci_dev *dev);
> > +
> > +/*
> > + * Iterate over the devices whose resources may reside directly in the
> > + * windows of @bus: the devices on @bus and, recursively, the devices
> > + * below its transparent bridges. A transparent bridge also forwards
> > + * accesses outside of its own windows.
> > + */
> > +#define pci_bus_for_each_window_dev(bus, dev)				\
> > +	for (dev = pci_bus_next_window_dev(bus, NULL); dev;		\
> > +	     dev = pci_bus_next_window_dev(bus, dev))
> > +
> > +/*
> > + * Iterate over the resources of the devices of
> > + * pci_bus_for_each_window_dev() that reside directly in window @win.
> > + */
> > +#define pci_bus_for_each_window_resource(bus, win, dev, res)		\
> > +	pci_bus_for_each_window_dev(bus, dev)				\
> > +		pci_dev_for_each_resource(dev, res)			\
> > +			for_each_if((res)->parent == (win))
> 
> [Severity: Low]
> Will a break statement inside pci_bus_for_each_window_resource() only exit
> the inner pci_dev_for_each_resource() loop?
> 
> Because this macro nests two separate for loops, break only stops scanning
> the current device's resources while the outer
> pci_bus_for_each_window_dev() loop silently continues to the remaining
> devices, executing the loop body again and overwriting dev and res.
> 
> Backing the iterator with a single-loop helper that finds the next matching
> resource, or documenting that break is unsupported, would avoid this trap.

I'm aware of this but these loops generally don't want to use break. 
There is not really an use case for looking up a single child resource 
for a bridge window. This is not a problem with the current loops and I 
don't foresee it becoming a realistic problem.

Converting these tidy loops into next based iteration is nowhere near
as elegant as this.

C's syntax is lacking here so the macro cannot mark the inner loops 
transparent to a break statement (e.g. using a compiler attribute), which 
would fulfill the natural expectation by the looks of the macro.

If somebody wants, I can add a comment.

-- 
 i.

  reply	other threads:[~2026-12-05  1:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com>
2026-12-05  0:39 ` [PATCH v2 01/16] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 02/16] PCI: Set new BAR Size only after releasing the BARs for BAR resize Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 03/16] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  1:25     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 04/16] PCI: Consistently use Header Type to detect bridge headers Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  0:39 ` [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  1:29     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 13/16] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 14/16] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-05  1:02   ` sashiko-bot
2026-12-05  1:12     ` Ilpo Järvinen [this message]
2026-12-05  0:39 ` [PATCH v2 15/16] PCI: Keep the range of fixed resources when releasing them Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 16/16] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-05  1:11   ` sashiko-bot
2026-12-05  1:57     ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf375588-f087-a7e8-8fec-c56a39412701@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox