linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd()
@ 2019-10-11  9:02 Andy Shevchenko
  2019-11-07 15:15 ` Andy Shevchenko
  2019-11-07 22:37 ` Keith Busch
  0 siblings, 2 replies; 7+ messages in thread
From: Andy Shevchenko @ 2019-10-11  9:02 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Stuart Hayes, Alexandru Gagniuc; +Cc: Andy Shevchenko

Infinite timeout loops are hard to read. Refactor it
to plausible 'do {} while ()'.

Note, the supplied timeout can't be negative for current use,
though if it's not dividable to 10, we may go below 0,
that's why type of the parameter is int. And thus, we may move
the check to the loop condition.

No functional changes implied.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pci/hotplug/pciehp_hpc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 1a522c1c4177..e397c78ca232 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -68,7 +68,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
 	struct pci_dev *pdev = ctrl_dev(ctrl);
 	u16 slot_status;
 
-	while (true) {
+	do {
 		pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
 		if (slot_status == (u16) ~0) {
 			ctrl_info(ctrl, "%s: no response from device\n",
@@ -81,11 +81,9 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
 						   PCI_EXP_SLTSTA_CC);
 			return 1;
 		}
-		if (timeout < 0)
-			break;
 		msleep(10);
 		timeout -= 10;
-	}
+	} while (timeout > 0);
 	return 0;	/* timeout */
 }
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-08 11:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11  9:02 [PATCH v1] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd() Andy Shevchenko
2019-11-07 15:15 ` Andy Shevchenko
2019-11-07 17:21   ` Alex G.
2019-11-08 11:08     ` Andy Shevchenko
2019-11-07 22:37 ` Keith Busch
2019-11-08 10:18   ` Andrew Murray
2019-11-08 11:10     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).