diff options
author | Rik van Riel <riel@redhat.com> | 2014-05-06 15:50:01 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-05-06 16:04:58 -0400 |
commit | d5c9fde3dae750889168807038243ff36431d276 (patch) | |
tree | 8b57ac0da7278daae45c9b7ac87a6bec7a554983 /mm/page-writeback.c | |
parent | 457c1b27ed56ec472d202731b12417bff023594a (diff) |
mm/page-writeback.c: fix divide by zero in pos_ratio_polynom
It is possible for "limit - setpoint + 1" to equal zero, after getting
truncated to a 32 bit variable, and resulting in a divide by zero error.
Using the fully 64 bit divide functions avoids this problem. It also
will cause pos_ratio_polynom() to return the correct value when
(setpoint - limit) exceeds 2^32.
Also uninline pos_ratio_polynom, at Andrew's request.
Signed-off-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page-writeback.c')
-rw-r--r-- | mm/page-writeback.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/mm/page-writeback.c b/mm/page-writeback.c index ef413492a149..a4317da60532 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c | |||
@@ -593,14 +593,14 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) | |||
593 | * (5) the closer to setpoint, the smaller |df/dx| (and the reverse) | 593 | * (5) the closer to setpoint, the smaller |df/dx| (and the reverse) |
594 | * => fast response on large errors; small oscillation near setpoint | 594 | * => fast response on large errors; small oscillation near setpoint |
595 | */ | 595 | */ |
596 | static inline long long pos_ratio_polynom(unsigned long setpoint, | 596 | static long long pos_ratio_polynom(unsigned long setpoint, |
597 | unsigned long dirty, | 597 | unsigned long dirty, |
598 | unsigned long limit) | 598 | unsigned long limit) |
599 | { | 599 | { |
600 | long long pos_ratio; | 600 | long long pos_ratio; |
601 | long x; | 601 | long x; |
602 | 602 | ||
603 | x = div_s64(((s64)setpoint - (s64)dirty) << RATELIMIT_CALC_SHIFT, | 603 | x = div64_s64(((s64)setpoint - (s64)dirty) << RATELIMIT_CALC_SHIFT, |
604 | limit - setpoint + 1); | 604 | limit - setpoint + 1); |
605 | pos_ratio = x; | 605 | pos_ratio = x; |
606 | pos_ratio = pos_ratio * x >> RATELIMIT_CALC_SHIFT; | 606 | pos_ratio = pos_ratio * x >> RATELIMIT_CALC_SHIFT; |
@@ -842,7 +842,7 @@ static unsigned long bdi_position_ratio(struct backing_dev_info *bdi, | |||
842 | x_intercept = bdi_setpoint + span; | 842 | x_intercept = bdi_setpoint + span; |
843 | 843 | ||
844 | if (bdi_dirty < x_intercept - span / 4) { | 844 | if (bdi_dirty < x_intercept - span / 4) { |
845 | pos_ratio = div_u64(pos_ratio * (x_intercept - bdi_dirty), | 845 | pos_ratio = div64_u64(pos_ratio * (x_intercept - bdi_dirty), |
846 | x_intercept - bdi_setpoint + 1); | 846 | x_intercept - bdi_setpoint + 1); |
847 | } else | 847 | } else |
848 | pos_ratio /= 4; | 848 | pos_ratio /= 4; |