From 7bbba813667aae762d2cccca0ba6f9f7c9032311 Mon Sep 17 00:00:00 2001 From: Rishabh Bhatnagar Date: Fri, 18 Dec 2020 15:46:30 -0800 Subject: [PATCH] devfreq: memlat: Fix macros to support 32 bit kernels Cast MBYTE macro to unsiged long instead of unsigned long long. Unsigned long long causes division errors when used for 32 bit kernels. Also, add a new macro for Mbps to icc conversion without loss of precision. Change-Id: I584869c510d614e47ab7090a1f328df307d412a8 Signed-off-by: Rishabh Bhatnagar --- drivers/devfreq/devfreq_icc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/devfreq/devfreq_icc.c b/drivers/devfreq/devfreq_icc.c index 8f2b96d8de7b..f7dc42e81c2b 100644 --- a/drivers/devfreq/devfreq_icc.c +++ b/drivers/devfreq/devfreq_icc.c @@ -27,10 +27,11 @@ #include #include -/* Has to be ULL to prevent overflow where this macro is used. */ -#define MBYTE (1ULL << 20) +/* Has to be UL to avoid errors in 32 bit. Use cautiously to avoid overflows.*/ +#define MBYTE (1UL << 20) #define HZ_TO_MBPS(hz, w) (mult_frac(w, hz, MBYTE)) #define MBPS_TO_HZ(mbps, w) (mult_frac(mbps, MBYTE, w)) +#define MBPS_TO_ICC(mbps) (mult_frac(mbps, MBYTE, 1000)) enum dev_type { STD_MBPS_DEV, @@ -72,8 +73,8 @@ static int set_bw(struct device *dev, u32 new_ib, u32 new_ab) icc_ib = MBPS_TO_HZ(new_ib, d->width); icc_ab = MBPS_TO_HZ(new_ab, d->width); } else if (d->spec->type == STD_MBPS_DEV) { - icc_ib = Bps_to_icc(new_ib * MBYTE); - icc_ab = Bps_to_icc(new_ab * MBYTE); + icc_ib = MBPS_TO_ICC(new_ib); + icc_ab = MBPS_TO_ICC(new_ab); } dev_dbg(dev, "ICC BW: AB: %u IB: %u\n", icc_ab, icc_ib);