Re: [patch] fix common mistake in polling loops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux