sys_poll with timeout -1 bug fix
If you do a poll() call with timeout -1, the wait will be a big number (depending on HZ) instead of infinite wait, since -1 is passed to the msecs_to_jiffies function. Tested on i386 and MIPS with latest (2.6.16) kernel.
Frode
fs/select.c renamed from fs/select.c.orig.c +0 -0
@@ -699,9 +699,9 @@ out_fds:
asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
long timeout_msecs)
{
- s64 timeout_jiffies = 0;
+ s64 timeout_jiffies;
- if (timeout_msecs) {
+ if (timeout_msecs > 0) {
#if HZ > 1000
/* We can only overflow if HZ > 1000 */
if (timeout_msecs / 1000 > (s64)0x7fffffffffffffffULL / (s64)HZ)
@@ -709,6 +709,9 @@ asmlinkage long sys_poll(struct pollfd _
else
#endif
timeout_jiffies = msecs_to_jiffies(timeout_msecs);
+ } else {
+ /* Infinite (-1) or no (0) timeout */
+ timeout_jiffies = timeout_msecs;
}
return do_sys_poll(ufds, nfds, &timeout_jiffies);Quoted 4 lines · frode isaksen
If you do a
poll()call with timeout -1, the wait will be a big number (depending on HZ) instead of infinite wait, since -1 is passed to themsecs_to_jiffiesfunction.
Tested on i386 and MIPS with latest (2.6.16) kernel.
This looks very close to a fix I have on my machine, as well, after looking at sys_poll() a bit. I suppose the only times you would notice are if an application actually wants as long a wait as possible, as opposed to a very long one.
Your patch was line-wrapped and does not have a Signed-off-by line, however. Care to try again?
Thanks,
Nish
Signature · 2 lines
Nishanth Aravamudan <[email protected]> IBM Linux Technology Center