Skip to content

Commit a3b0f10

Browse files
Naveenaidubjorn-helgaas
authored andcommitted
PCI: pciehp: Use PCI_POSSIBLE_ERROR() to check config reads
When config pci_ops.read() can detect failed PCI transactions, the data returned to the CPU is PCI_ERROR_RESPONSE (~0 or 0xffffffff). Obviously a successful PCI config read may *also* return that data if a config register happens to contain ~0, so it doesn't definitively indicate an error unless we know the register cannot contain ~0. Use PCI_POSSIBLE_ERROR() to check the response we get when we read data from hardware. This unifies PCI error response checking and makes error checks consistent and easier to find. Compile tested only. Link: https://lore.kernel.org/r/e185b052fbfd530df703a36dd31126cb870eed95.1637243717.git.naveennaidu479@gmail.com Signed-off-by: Naveen Naidu <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Acked-by: Lukas Wunner <[email protected]>
1 parent 242f288 commit a3b0f10

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/pci/hotplug/pciehp_hpc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
8989

9090
do {
9191
pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
92-
if (slot_status == (u16) ~0) {
92+
if (PCI_POSSIBLE_ERROR(slot_status)) {
9393
ctrl_info(ctrl, "%s: no response from device\n",
9494
__func__);
9595
return 0;
@@ -165,7 +165,7 @@ static void pcie_do_write_cmd(struct controller *ctrl, u16 cmd,
165165
pcie_wait_cmd(ctrl);
166166

167167
pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl);
168-
if (slot_ctrl == (u16) ~0) {
168+
if (PCI_POSSIBLE_ERROR(slot_ctrl)) {
169169
ctrl_info(ctrl, "%s: no response from device\n", __func__);
170170
goto out;
171171
}
@@ -236,7 +236,7 @@ int pciehp_check_link_active(struct controller *ctrl)
236236
int ret;
237237

238238
ret = pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
239-
if (ret == PCIBIOS_DEVICE_NOT_FOUND || lnk_status == (u16)~0)
239+
if (ret == PCIBIOS_DEVICE_NOT_FOUND || PCI_POSSIBLE_ERROR(lnk_status))
240240
return -ENODEV;
241241

242242
ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
@@ -443,7 +443,7 @@ int pciehp_card_present(struct controller *ctrl)
443443
int ret;
444444

445445
ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
446-
if (ret == PCIBIOS_DEVICE_NOT_FOUND || slot_status == (u16)~0)
446+
if (ret == PCIBIOS_DEVICE_NOT_FOUND || PCI_POSSIBLE_ERROR(slot_status))
447447
return -ENODEV;
448448

449449
return !!(slot_status & PCI_EXP_SLTSTA_PDS);
@@ -621,7 +621,7 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id)
621621

622622
read_status:
623623
pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &status);
624-
if (status == (u16) ~0) {
624+
if (PCI_POSSIBLE_ERROR(status)) {
625625
ctrl_info(ctrl, "%s: no response from device\n", __func__);
626626
if (parent)
627627
pm_runtime_put(parent);

0 commit comments

Comments
 (0)