From: "Alex G." <mr.nuke.me@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
linux-pci@vger.kernel.org,
Stuart Hayes <stuart.w.hayes@gmail.com>
Subject: Re: [PATCH v1] PCI: pciehp: Refactor infinite loop in pcie_poll_cmd()
Date: Thu, 7 Nov 2019 11:21:12 -0600 [thread overview]
Message-ID: <a11f53df-911a-3eee-6bda-01322550f1d4@gmail.com> (raw)
In-Reply-To: <20191107151536.GA32742@smile.fi.intel.com>
Hi Andy,
On 11/7/19 9:15 AM, Andy Shevchenko wrote:
> On Fri, Oct 11, 2019 at 12:02:30PM +0300, Andy Shevchenko wrote:
>> Infinite timeout loops are hard to read.
Why do you find infinite timeout loops hard to read? I personally find
that emphasizing the common case to be more redable. An ideal loop for
me would look like:
do {
do_stuff();
if (timeout) {
complain();
break()
}
} while (what_we_expect_has_not_happened());
Cheers,
Alex
>> 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.
>
> Bjorn, any comment on this? It would be nice to have in since contributors are
> unable to know which style to use. This patch makes similar places follow the
> same style.
>
>>
>> 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
>>
>
next prev parent reply other threads:[~2019-11-07 17:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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. [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a11f53df-911a-3eee-6bda-01322550f1d4@gmail.com \
--to=mr.nuke.me@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=stuart.w.hayes@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).