vfio/pci: Allow VPD short read
authorAlex Williamson <alex.williamson@redhat.com>
Wed, 1 Jun 2016 03:25:52 +0000 (21:25 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Wed, 1 Jun 2016 03:25:52 +0000 (21:25 -0600)
The size of the VPD area is not necessarily 4-byte aligned, so a
pci_vpd_read() might return less than 4 bytes.  Zero our buffer and
accept anything other than an error.  Intel X710 NICs exercise this.

Fixes: 4e1a635552d3 ("vfio/pci: Use kernel VPD access functions")
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci_config.c

index 93601407dab8a04b44c8a379b9ff0d480c12303d..688691d9058dd98e134459fbaed507721ae507f8 100644 (file)
@@ -749,7 +749,8 @@ static int vfio_vpd_config_write(struct vfio_pci_device *vdev, int pos,
                if (pci_write_vpd(pdev, addr & ~PCI_VPD_ADDR_F, 4, &data) != 4)
                        return count;
        } else {
-               if (pci_read_vpd(pdev, addr, 4, &data) != 4)
+               data = 0;
+               if (pci_read_vpd(pdev, addr, 4, &data) < 0)
                        return count;
                *pdata = cpu_to_le32(data);
        }