|
@@ -1149,9 +1149,12 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
|
|
|
return pcibios_err_to_errno(ret);
|
|
|
|
|
|
if (PCI_X_CMD_VERSION(word)) {
|
|
|
- /* Test for extended capabilities */
|
|
|
- pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
|
|
|
- vdev->extended_caps = (dword != 0);
|
|
|
+ if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
|
|
|
+ /* Test for extended capabilities */
|
|
|
+ pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE,
|
|
|
+ &dword);
|
|
|
+ vdev->extended_caps = (dword != 0);
|
|
|
+ }
|
|
|
return PCI_CAP_PCIX_SIZEOF_V2;
|
|
|
} else
|
|
|
return PCI_CAP_PCIX_SIZEOF_V0;
|
|
@@ -1163,9 +1166,11 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
|
|
|
|
|
|
return byte;
|
|
|
case PCI_CAP_ID_EXP:
|
|
|
- /* Test for extended capabilities */
|
|
|
- pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
|
|
|
- vdev->extended_caps = (dword != 0);
|
|
|
+ if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
|
|
|
+ /* Test for extended capabilities */
|
|
|
+ pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
|
|
|
+ vdev->extended_caps = (dword != 0);
|
|
|
+ }
|
|
|
|
|
|
/* length based on version */
|
|
|
if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)
|