[PATCH] psi:fix divide by zero in psi_update_stats

From: tim
Date: Fri Nov 08 2019 - 02:33:16 EST


In psi_update_stats, it is possible that period has value like
0xXXXXXXXX00000000 where the lower 32 bit is 0, then it calls div_u64 which
truncates u64 period to u32, results in zero divisor.
Use div64_u64() instead of div_u64() if the divisor is u64 to avoid
truncation to 32-bit on 64-bit platforms.

Signed-off-by: xiejingfeng <xiejingfeng@xxxxxxxxxxxxxxxxx>
---
kernel/sched/psi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 517e3719027e..399d6f106de5 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -291,7 +291,7 @@ static void calc_avgs(unsigned long avg[3], int missed_periods,
}

/* Sample the most recent active period */
- pct = div_u64(time * 100, period);
+ pct = div64_u64(time * 100, period);
pct *= FIXED_1;
avg[0] = calc_load(avg[0], EXP_10s, pct);
avg[1] = calc_load(avg[1], EXP_60s, pct);
--
2.14.4.44.g2045bb