lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Wed, 9 Aug 2006 20:25:01 -0400
From:	Andrew James Wade <andrew.j.wade@...il.com>
To:	"Om N." <xhandle@...il.com>
Cc:	kernel-janitors@...l.org, linux-kernel@...r.kernel.org
Subject: Re: [KJ] [patch] fix common mistake in polling loops

[resending due to delivery failure.]

On Monday 07 August 2006 22:53, Om N. wrote:
> On 8/7/06, Darren Jenkins <darrenrjenkins@...il.com> wrote:
> > G'day
> >
> > On 8/8/06, Pavel Machek <pavel@...e.cz> wrote:
> > >
> > > But you have to make sure YOU CHECK READY AFTER THE TIMEOUT. Linus'
> > > code does not do that.
> > >                                                                 Pavel
> >
> >
> > Sorry I did not realise that was your problem with the code.
> > Would it help if we just explicitly added a
> >
>       unsigned long timeout = jiffies + HZ/2;
>        for (;;) {
>                if (ready())
>                        return 0;
> [IMAGINE HALF A SECOND DELAY HERE]
>                if (time_after(timeout, jiffies)) {
>                        if (ready())
>                               return 0;
>                        break;
>                 }
>                msleep(10);
>        }
> Wouldn't this be better than adding a check after the break of loop?

You're getting duplicated code there. That'll be an issue in more
complex loops. How about:

unsigned long timeout = jiffies + HZ/2;
int timeup = 0;

for (;;;) {
	if (ready())
 		return 0;
	if (timeup)
		break;
	msleep(10);
	timeup = time_after(timeout, jiffies);
};
... timeout ...

However care is needed with the use of timeup, since timeup==1 only
indicates failure at the point it's tested in the loop; in particular
it won't indicate failure after the loop if "return 0" is changed to
"break".

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ