
From: "Bill Rugolsky Jr." <brugolsky@telemetry-investments.com>

This patch extends the useful range of the poll() timeout parameter from a
mere 2147s (LONG_MAX/(1000*HZ)) to 2147483s (LONG_MAX/1000).



---

 25-akpm/fs/select.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff -puN fs/select.c~poll-select-longer-timeouts fs/select.c
--- 25/fs/select.c~poll-select-longer-timeouts	2004-03-12 01:30:21.000000000 -0800
+++ 25-akpm/fs/select.c	2004-03-12 01:30:21.000000000 -0800
@@ -469,11 +469,17 @@ asmlinkage long sys_poll(struct pollfd _
 		return -EINVAL;
 
 	if (timeout) {
-		/* Careful about overflow in the intermediate values */
-		if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
-			timeout = (unsigned long)(timeout*HZ+999)/1000+1;
-		else /* Negative or overflow */
+                if (timeout < 0) {
 			timeout = MAX_SCHEDULE_TIMEOUT;
+		} else {
+			/* Careful about overflow in the intermediate values */
+			long seconds = timeout/1000;
+			timeout = ((timeout - 1000*seconds)*HZ + 999)/1000 + 1;
+			if (seconds <= (MAX_SCHEDULE_TIMEOUT-2) / HZ - 1)
+				timeout += seconds*HZ;
+			else
+				timeout = MAX_SCHEDULE_TIMEOUT;
+		}
 	}
 
 	poll_initwait(&table);

_
