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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140114231003.GB7877@kroah.com>
Date:	Tue, 14 Jan 2014 15:10:03 -0800
From:	Greg KH <gregkh@...uxfoundation.org>
To:	Chase Southwood <chase.southwood@...oo.com>
Cc:	devel@...verdev.osuosl.org, abbotti@....co.uk,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] Staging: comedi: convert while loop to timeout in
 ni_mio_common.c

On Tue, Jan 14, 2014 at 03:31:01PM -0600, Chase Southwood wrote:
> This patch to ni_mio_common.c changes a simple while loop to a timeout,
> which is preferred.
> 
> Signed-off-by: Chase Southwood <chase.southwood@...oo.com>
> ---
> 
> I removed the extra counter variable this time.  Greg, you mentioned that I could just look at the time that has expired to far, and exit and error out if that exceeds a limit.  Right now I'm just tracking how many times udelay is called, since that seems to conform more to other timeouts in this file, but did you instead want me to use some time function to keep track of actual real time that expires?

Please wrap your lines of text, as that's one very long line :)

The best way to do this is to do:
	unsigned long timeout;
	...
	timeout = jiffies + msec_to_jiffies(500);	/* Or how ever long you want to wait */
	do {
		do something...
		udelay(10);
	} while (time_before(jiffies, timeout);

	or switch the loop around and do:

	while (something hasn't happened) {
		if (time_after(jjiffies, timeout)) {
			we timed out, handle it here;
			break;
		}
		udelay(10);
	}

That's much better than having to count up a "number" and have to look
to see how long you are sleeping for to determine just exactly how long
you are going to have until the loop times out, as your code did.

Make sense?

greg k-h
--
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