Linux-PCI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd()
@ 2019-11-08 11:18 Andy Shevchenko
  2019-11-12  0:17 ` Bjorn Helgaas
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2019-11-08 11:18 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, Stuart Hayes, Alexandru Gagniuc,
	Keith Busch, Andrew Murray
  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.

Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
- corrected loop conditional to include 0 comparison (Keith)
- added Rb (Andrew)
 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 86d97f3112f0..764384153c7d 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.24.0.rc1


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

* Re: [PATCH v2] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd()
  2019-11-08 11:18 [PATCH v2] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd() Andy Shevchenko
@ 2019-11-12  0:17 ` Bjorn Helgaas
  0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2019-11-12  0:17 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-pci, Stuart Hayes, Alexandru Gagniuc, Keith Busch, Andrew Murray

On Fri, Nov 08, 2019 at 01:18:55PM +0200, Andy Shevchenko wrote:
> 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.
> 
> Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied to pci/hotplug for v5.5, thanks!

> ---
> - corrected loop conditional to include 0 comparison (Keith)
> - added Rb (Andrew)
>  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 86d97f3112f0..764384153c7d 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.24.0.rc1
> 

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 11:18 [PATCH v2] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd() Andy Shevchenko
2019-11-12  0:17 ` Bjorn Helgaas

Linux-PCI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pci/0 linux-pci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pci linux-pci/ https://lore.kernel.org/linux-pci \
		linux-pci@vger.kernel.org
	public-inbox-index linux-pci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git