pci: Rework pci_bar_is_valid()
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
diff --git a/lib/pci.c b/lib/pci.c
index cf33b89..fc18b25 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -205,7 +205,7 @@
bool pci_bar_is_valid(struct pci_dev *dev, int bar_num)
{
- return pci_bar_get(dev, bar_num);
+ return dev->resource[bar_num] != INVALID_PHYS_ADDR;
}
bool pci_bar_is64(struct pci_dev *dev, int bar_num)
@@ -224,11 +224,11 @@
phys_addr_t size, start, end;
uint32_t bar;
- size = pci_bar_size(dev, bar_num);
- if (!size)
+ if (!pci_bar_is_valid(dev, bar_num))
return;
bar = pci_bar_get(dev, bar_num);
+ size = pci_bar_size(dev, bar_num);
start = pci_bar_get_addr(dev, bar_num);
end = start + size - 1;
@@ -308,7 +308,7 @@
return;
for (i = 0; i < PCI_BAR_NUM; i++) {
- if (pci_bar_size(&pci_dev, i)) {
+ if (pci_bar_is_valid(&pci_dev, i)) {
printf("\t");
pci_bar_print(&pci_dev, i);
printf("\n");