pciexp_device: Fix pciexp_find_next_extended_cap()

If we already encountered the last extended capability in the
list, we'd call pciexp_get_ext_cap_offset() with `offset == 0`.
So it also needs to check if the passed offset is valid.

As there were no callers of pciexp_find_next_extended_cap()
yet, pciexp_get_ext_cap_offset() was only ever called with
`PCIE_EXT_CAP_OFFSET`.

Change-Id: I155c4691a34ff16661919913a3446fa915ac535e
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66452
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Bill XIE <persmule@hardenedlinux.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Nico Huber 2022-08-05 12:44:11 +02:00 committed by Felix Held
parent ebc36c1b48
commit 4b864e5c30

View file

@ -13,7 +13,7 @@ static unsigned int pciexp_get_ext_cap_offset(const struct device *dev, unsigned
{
unsigned int this_cap_offset = offset;
unsigned int next_cap_offset, this_cap, cafe;
do {
while (this_cap_offset != 0) {
this_cap = pci_read_config32(dev, this_cap_offset);
/* Bail out when this request is unsupported */
if (this_cap == 0xffffffff)
@ -27,7 +27,7 @@ static unsigned int pciexp_get_ext_cap_offset(const struct device *dev, unsigned
next_cap_offset = this_cap >> 20;
this_cap_offset = next_cap_offset;
}
} while (next_cap_offset != 0);
}
return 0;
}