Re: [PATCH] drivers/net/wan/wanxl.c: time_before(timeout, jiffies)-> jiffies, timeout

From: Joe Perches
Date: Thu Mar 20 2008 - 17:09:37 EST


On Thu, 2008-03-20 at 21:23 +0100, Roel Kluin wrote:
> > - while ((stat = readl(card->plx + PLX_MAILBOX_0)) != 0) {
> > - if (time_before(timeout, jiffies)) {
> > - printk(KERN_WARNING "wanXL %s: timeout waiting for"
> > - " PUTS to complete\n", pci_name(pdev));
> > - wanxl_pci_remove_one(pdev);
> > - return -ENODEV;
> > - }
> > -
> > - switch(stat & 0xC0) {
> > - case 0x00: /* hmm - PUTS completed with non-zero code? */
> > - case 0x80: /* PUTS still testing the hardware */
> > - break;
> > -
> > - default:
> > - printk(KERN_WARNING "wanXL %s: PUTS test 0x%X"
> > + if (TEST_UNTIL_TIMEOUT(((stat = readl(card->plx + PLX_MAILBOX_0)) != 0),
> > + 20 * HZ)) {
> > + printk(KERN_WARNING "wanXL %s: PUTS test 0x%X"
> > " failed\n", pci_name(pdev), stat & 0x30);
> > wanxl_pci_remove_one(pdev);
> > return -ENODEV;
>
> Doesn't this change behavior for (stat & 0xC0) != 0x00 or 0x80?

Probably, I didn't look at it too much. Feel free to fix it.

The patch was just to demonstrate the statement expression macro
and show the lack of schedules() in some of the loops.

Maybe the statement expression macro should optionally schedule too:

#define TEST_UNTIL_TIMEOUT(test, hz, schedule) \
({ \
typeof(test) t; \
unsigned long timeout = jiffies + (hz); \
do { \
t = (test); \
if (t) \
break; \
if ((schedule)) \
schedule(); \
} while (time_before(jiffies, timeout)); \
t; \
})

cheers, Joe

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