[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v8 0/7] Add pci_dev_for_each_resource() helper and update users
- To: Jonas Gorski <jonas.gorski@xxxxxxxxx>
- From: Bjorn Helgaas <helgaas@xxxxxxxxxx>
- Date: Wed, 31 May 2023 16:30:28 -0500
- Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>, Krzysztof Wilczyński <kw@xxxxxxxxx>, linux-pci@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Mickaël Salaün <mic@xxxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, linux-sh@xxxxxxxxxxxxxxx, Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>, Andrew Lunn <andrew@xxxxxxx>, sparclinux@xxxxxxxxxxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx>, Gregory Clement <gregory.clement@xxxxxxxxxxx>, "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, linux-acpi@xxxxxxxxxxxxxxx, Miguel Ojeda <ojeda@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Matt Turner <mattst88@xxxxxxxxx>, Anatolij Gustschin <agust@xxxxxxx>, Sebastian Hesselbarth <sebastian.hesselbarth@xxxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, Niklas Schnelle <schnelle@xxxxxxxxxxxxx>, Richard Henderson <richard.henderson@xxxxxxxxxx>, Nicholas Piggin <npiggin@xxxxxxxxx>, Ivan Kokshaysky <ink@xxxxxxxxxxxxxxxxxxxx>, John Paul Adrian Glaubitz <glaubitz@xxxxxxxxxxxxxxxxxxx>, Bjorn Helgaas <bhelgaas@xxxxxxxxxx>, Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, Juergen Gross <jgross@xxxxxxxx>, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Philippe Mathieu-Daudé <philmd@xxxxxxxxxx>, linuxppc-dev@xxxxxxxxxxxxxxxx, Randy Dunlap <rdunlap@xxxxxxxxxxxxx>, linux-mips@xxxxxxxxxxxxxxx, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, linux-alpha@xxxxxxxxxxxxxxx, Pali Rohár <pali@xxxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, "Maciej W. Rozycki" <macro@xxxxxxxxxxx>
- Delivery-date: Wed, 31 May 2023 21:30:46 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Wed, May 31, 2023 at 08:48:35PM +0200, Jonas Gorski wrote:
> ...
> Looking at the code I understand where coverity is coming from:
>
> #define __pci_dev_for_each_res0(dev, res, ...) \
> for (unsigned int __b = 0; \
> res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \
> __b++)
>
> res will be assigned before __b is checked for being less than
> PCI_NUM_RESOURCES, making it point to behind the array at the end of
> the last loop iteration.
>
> Rewriting the test expression as
>
> __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b));
>
> should avoid the (coverity) warning by making use of lazy evaluation.
>
> It probably makes the code slightly less performant as res will now be
> checked for being not NULL (which will always be true), but I doubt it
> will be significant (or in any hot paths).
Thanks a lot for looking into this! I think you're right, and I think
the rewritten expression is more logical as well. Do you want to post
a patch for it?
Bjorn
|