public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Garzik <jeff@garzik.org>
To: Zed 0xff <zed.0xff@gmail.com>
Cc: kernel-janitors@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [patch] fix common mistake in polling loops
Date: Fri, 28 Jul 2006 04:51:04 -0400	[thread overview]
Message-ID: <44C9CFF8.2080503@garzik.org> (raw)
In-Reply-To: <710c0ee0607280128g2d968c49ycff3bac9e073e7fa@mail.gmail.com>

Zed 0xff wrote:
> b/drivers/block/sx8.c
> --- a/drivers/block/sx8.c    2006-07-27 21:56:05.000000000 +0600
> +++ b/drivers/block/sx8.c    2006-07-28 00:52:33.000000000 +0600
> @@ -550,21 +550,23 @@ static struct carm_request *carm_get_spe
>     unsigned long flags;
>     struct carm_request *crq = NULL;
>     struct request *rq;
> -    int tries = 5000;
> +    unsigned long timeout= jiffies + msecs_to_jiffies(50000);
> 
> -    while (tries-- > 0) {
> +    for(;;) {
>         spin_lock_irqsave(&host->lock, flags);
>         crq = carm_get_request(host);
>         spin_unlock_irqrestore(&host->lock, flags);
> 
>         if (crq)
>             break;
> +
> +        if (time_after(timeout, jiffies)) {
> +            return NULL;
> +        }
> +       
>         msleep(10);
>     }
> 
> -    if (!crq)
> -        return NULL;
> -


NAK:
* [minor] broken whitespace
* [minor] adding braces to singleton C statements
* [major] makes a simple loop much more annoying to read

There is no critical hard deadline for this loop, as with most error 
handling loops.

Since error handling code is exercised much less frequently than regular 
code, I would rather KISS.

	Jeff



  reply	other threads:[~2006-07-28  8:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-28  8:28 [patch] fix common mistake in polling loops Zed 0xff
2006-07-28  8:51 ` Jeff Garzik [this message]
2006-07-28 12:43 ` Dmitry Torokhov
2006-08-05 11:40 ` Pavel Machek
2006-08-05 11:45   ` Pavel Machek
2006-08-06 23:39     ` [KJ] " Darren Jenkins
2006-08-07 23:34       ` Pavel Machek
2006-08-08  0:53         ` Darren Jenkins
2006-08-08  2:53           ` Om N.
2006-08-10  0:25             ` Andrew James Wade
2006-08-10  1:11               ` Darren Jenkins
2006-08-08  9:19           ` Pavel Machek

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=44C9CFF8.2080503@garzik.org \
    --to=jeff@garzik.org \
    --cc=kernel-janitors@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zed.0xff@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