On failure pcie_capability_read_*() sets it's last parameter, val
to 0. However, with Patch 12/12, it is possible that val is set
to ~0 on failure. This would introduces a bug because
(x & x) == (~0 & x).

Since ~0 is an invalid value in here,

Add extra check for ~0 in the if condition to ensure success or
failure.

Suggested-by: Bjorn Helgaas <bj...@helgaas.com>
Signed-off-by: Saheed O. Bolarinwa <refactormys...@gmail.com>
---
 drivers/pci/pci-acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 7224b1e5f2a8..873b005947e4 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -253,7 +253,7 @@ static bool pcie_root_rcb_set(struct pci_dev *dev)
                return false;
 
        pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl);
-       if (lnkctl & PCI_EXP_LNKCTL_RCB)
+       if ((lnkctl != (u16)~0) && (lnkctl & PCI_EXP_LNKCTL_RCB))
                return true;
 
        return false;
@@ -797,7 +797,7 @@ bool pciehp_is_native(struct pci_dev *bridge)
                return false;
 
        pcie_capability_read_dword(bridge, PCI_EXP_SLTCAP, &slot_cap);
-       if (!(slot_cap & PCI_EXP_SLTCAP_HPC))
+       if ((slot_cap == (u32)~0) || !(slot_cap & PCI_EXP_SLTCAP_HPC))
                return false;
 
        if (pcie_ports_native)
-- 
2.18.4

Reply via email to