PCI: pciehp: Simplify pcie_poll_cmd()
authorYijing Wang <wangyijing@huawei.com>
Fri, 19 Jun 2015 07:57:45 +0000 (15:57 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 16 Jul 2015 03:03:33 +0000 (22:03 -0500)
Move first slot status read into while to simplify code.

Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/hotplug/pciehp_hpc.c

index 2913f7e68a10bdee3eefe169576dd7347965e31c..daf54bee720d4e0f9cbccab1a2b0f2a2fdbca691 100644 (file)
@@ -109,21 +109,17 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
        struct pci_dev *pdev = ctrl_dev(ctrl);
        u16 slot_status;
 
-       pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
-       if (slot_status & PCI_EXP_SLTSTA_CC) {
-               pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
-                                          PCI_EXP_SLTSTA_CC);
-               return 1;
-       }
-       while (timeout > 0) {
-               msleep(10);
-               timeout -= 10;
+       while (true) {
                pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
                if (slot_status & PCI_EXP_SLTSTA_CC) {
                        pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
                                                   PCI_EXP_SLTSTA_CC);
                        return 1;
                }
+               if (timeout < 0)
+                       break;
+               msleep(10);
+               timeout -= 10;
        }
        return 0;       /* timeout */
 }