From: Michal Nazarewicz Date: Sun, 10 Nov 2013 19:42:01 +0000 (+0100) Subject: sched/fair: Avoid integer overflow X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=85b088e934b9943322bfe37077289ae60f1b3414;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git sched/fair: Avoid integer overflow sa->runnable_avg_sum is of type u32 but after shifting it by NICE_0_SHIFT bits it is promoted to u64. This of course makes no sense, since the result will never be more then 32-bit long. Casting sa->runnable_avg_sum to u64 before it is shifted, fixes this problem. Reviewed-by: Ben Segall Signed-off-by: Michal Nazarewicz Signed-off-by: Peter Zijlstra Link: http://lkml.kernel.org/r/1384112521-25177-1-git-send-email-mpn@google.com Signed-off-by: Ingo Molnar --- diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 201be782b5b3..e8b652ebe027 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2178,7 +2178,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa, long contrib; /* The fraction of a cpu used by this cfs_rq */ - contrib = div_u64(sa->runnable_avg_sum << NICE_0_SHIFT, + contrib = div_u64((u64)sa->runnable_avg_sum << NICE_0_SHIFT, sa->runnable_avg_period + 1); contrib -= cfs_rq->tg_runnable_contrib;