vfio/pci: Fix sizing of DPA and THP express capabilities
authorAlex Williamson <alex.williamson@redhat.com>
Fri, 30 May 2014 16:50:31 +0000 (10:50 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 30 May 2014 16:50:31 +0000 (10:50 -0600)
When sizing the TPH capability we store the register containing the
table size into the 'dword' variable, but then use the uninitialized
'byte' variable to analyze the size.  The table size is also actually
reported as an N-1 value, so correct sizing to account for this.

The round_up() for both TPH and DPA is unnecessary, remove it.

Detected by Coverity: CID 714665 & 715156

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci_config.c

index 83cd1574c810d9f62bf141c70b7c2f55a16b5e56..e50790e91f769825fad7284512eb5050b7d3f92a 100644 (file)
@@ -1126,8 +1126,7 @@ static int vfio_ext_cap_len(struct vfio_pci_device *vdev, u16 ecap, u16 epos)
                        return pcibios_err_to_errno(ret);
 
                byte &= PCI_DPA_CAP_SUBSTATE_MASK;
-               byte = round_up(byte + 1, 4);
-               return PCI_DPA_BASE_SIZEOF + byte;
+               return PCI_DPA_BASE_SIZEOF + byte + 1;
        case PCI_EXT_CAP_ID_TPH:
                ret = pci_read_config_dword(pdev, epos + PCI_TPH_CAP, &dword);
                if (ret)
@@ -1136,9 +1135,9 @@ static int vfio_ext_cap_len(struct vfio_pci_device *vdev, u16 ecap, u16 epos)
                if ((dword & PCI_TPH_CAP_LOC_MASK) == PCI_TPH_LOC_CAP) {
                        int sts;
 
-                       sts = byte & PCI_TPH_CAP_ST_MASK;
+                       sts = dword & PCI_TPH_CAP_ST_MASK;
                        sts >>= PCI_TPH_CAP_ST_SHIFT;
-                       return PCI_TPH_BASE_SIZEOF + round_up(sts * 2, 4);
+                       return PCI_TPH_BASE_SIZEOF + (sts * 2) + 2;
                }
                return PCI_TPH_BASE_SIZEOF;
        default:
This page took 0.026712 seconds and 5 git commands to generate.