@@ -489,7 +489,6 @@ static ssize_t vfio_pci_cap_size(struct pci_cap_hdr *cap_hdr)
static int vfio_pci_add_cap(struct vfio_device *vdev, struct pci_cap_hdr *cap_hdr,
off_t fd_offset, off_t pos)
{
- int i;
ssize_t size = vfio_pci_cap_size(cap_hdr);
struct pci_device_header *hdr = &vdev->pci.hdr;
struct pci_cap_hdr *out = (void *)hdr + pos;
@@ -505,9 +504,12 @@ static int vfio_pci_add_cap(struct vfio_device *vdev, struct pci_cap_hdr *cap_hd
} else {
/* Add cap at end of list */
struct pci_cap_hdr *last;
+ int i = hdr->capabilities & ~3;
- pci_for_each_cap(i, last, hdr)
- ;
+ do {
+ last = (void *)hdr + i;
+ i = last->next;
+ } while (i);
last->next = pos;
}