diff options
Diffstat (limited to 'fs/select.c')
-rw-r--r-- | fs/select.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/fs/select.c b/fs/select.c index 8084834e123e..fd38ce2e32e3 100644 --- a/fs/select.c +++ b/fs/select.c | |||
@@ -15,6 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/sched.h> | ||
18 | #include <linux/syscalls.h> | 19 | #include <linux/syscalls.h> |
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
20 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
@@ -41,22 +42,28 @@ | |||
41 | * better solutions.. | 42 | * better solutions.. |
42 | */ | 43 | */ |
43 | 44 | ||
45 | #define MAX_SLACK (100 * NSEC_PER_MSEC) | ||
46 | |||
44 | static long __estimate_accuracy(struct timespec *tv) | 47 | static long __estimate_accuracy(struct timespec *tv) |
45 | { | 48 | { |
46 | long slack; | 49 | long slack; |
47 | int divfactor = 1000; | 50 | int divfactor = 1000; |
48 | 51 | ||
52 | if (tv->tv_sec < 0) | ||
53 | return 0; | ||
54 | |||
49 | if (task_nice(current) > 0) | 55 | if (task_nice(current) > 0) |
50 | divfactor = divfactor / 5; | 56 | divfactor = divfactor / 5; |
51 | 57 | ||
58 | if (tv->tv_sec > MAX_SLACK / (NSEC_PER_SEC/divfactor)) | ||
59 | return MAX_SLACK; | ||
60 | |||
52 | slack = tv->tv_nsec / divfactor; | 61 | slack = tv->tv_nsec / divfactor; |
53 | slack += tv->tv_sec * (NSEC_PER_SEC/divfactor); | 62 | slack += tv->tv_sec * (NSEC_PER_SEC/divfactor); |
54 | 63 | ||
55 | if (slack > 100 * NSEC_PER_MSEC) | 64 | if (slack > MAX_SLACK) |
56 | slack = 100 * NSEC_PER_MSEC; | 65 | return MAX_SLACK; |
57 | 66 | ||
58 | if (slack < 0) | ||
59 | slack = 0; | ||
60 | return slack; | 67 | return slack; |
61 | } | 68 | } |
62 | 69 | ||