From 8b2c5df07ab866e3a5dd229532649a2c65073f40 Mon Sep 17 00:00:00 2001 From: tao zeng Date: Mon, 29 Oct 2018 12:11:18 +0800 Subject: [PATCH] ddr: fix bandwidth read result 0 on 32bit OS [1/1] PD#SWPL-960 Problem: Reading bandwidth of DDR from sysfs get all 0 result on 32 bit kernel Solution: Fix overflow when calculating bandwidth. Verify: P212 Change-Id: I35837db653bdc2d97ced98689546a9ffc0db21c7 Signed-off-by: tao zeng --- drivers/amlogic/ddr_tool/ddr_bandwidth.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/amlogic/ddr_tool/ddr_bandwidth.c b/drivers/amlogic/ddr_tool/ddr_bandwidth.c index 132773c..fb49fe8 100644 --- a/drivers/amlogic/ddr_tool/ddr_bandwidth.c +++ b/drivers/amlogic/ddr_tool/ddr_bandwidth.c @@ -40,17 +40,23 @@ static void cal_ddr_usage(struct ddr_bandwidth *db, struct ddr_grant *dg) if (db->ops && db->ops->get_freq) freq = db->ops->get_freq(db); - mul = (dg->all_grant * 10000ULL) / 16; /* scale up to keep precision*/ + mul = dg->all_grant; + mul *= 10000ULL; + mul /= 16; cnt = db->clock_count; do_div(mul, cnt); db->total_usage = mul; if (freq) { /* calculate in KB */ - mul = (dg->all_grant * freq) / 1024; + mul = dg->all_grant; + mul *= freq; + mul /= 1024; do_div(mul, cnt); db->total_bandwidth = mul; for (i = 0; i < db->channels; i++) { - mul = (dg->channel_grant[i] * freq) / 1024; + mul = dg->channel_grant[i]; + mul *= freq; + mul /= 1024; do_div(mul, cnt); db->bandwidth[i] = mul; } -- 2.7.4