From 726d78ef8a242dae247ee372f1633e2d54bad3de Mon Sep 17 00:00:00 2001 From: Jeyaprabu J Date: Tue, 22 Mar 2022 12:24:47 +0530 Subject: [PATCH] msm: kgsl: Fix UBSAN warnings Fix possible division by zero error. Change-Id: I64eb6a5ee1247dafea6701b8244eefab1c40eea6 Signed-off-by: Jeyaprabu J --- drivers/gpu/msm/adreno_a6xx_rpmh.c | 6 +++++- drivers/gpu/msm/governor_gpubw_mon.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/msm/adreno_a6xx_rpmh.c b/drivers/gpu/msm/adreno_a6xx_rpmh.c index 0594304d64ee..c7a4b3297e45 100644 --- a/drivers/gpu/msm/adreno_a6xx_rpmh.c +++ b/drivers/gpu/msm/adreno_a6xx_rpmh.c @@ -120,6 +120,7 @@ static void tcs_cmd_data(struct bcm *bcms, int count, u32 ab, u32 ib, u32 *data) { int i; + u64 total_width; for (i = 0; i < count; i++) { bool valid = true; @@ -145,8 +146,11 @@ static void tcs_cmd_data(struct bcm *bcms, int count, u32 ab, u32 ib, /* Multiple the bandwidth by the width of the connection */ avg = ((u64) ab) * bcms[i].width; + total_width = bcms[i].buswidth * bcms[i].channels; + /* And then divide by the total width across channels */ - do_div(avg, bcms[i].buswidth * bcms[i].channels); + if (total_width) + do_div(avg, (u32) total_width); peak = ((u64) ib) * bcms[i].width; do_div(peak, bcms[i].buswidth); diff --git a/drivers/gpu/msm/governor_gpubw_mon.c b/drivers/gpu/msm/governor_gpubw_mon.c index fabcd56b3776..af437abf107e 100644 --- a/drivers/gpu/msm/governor_gpubw_mon.c +++ b/drivers/gpu/msm/governor_gpubw_mon.c @@ -101,7 +101,7 @@ static int devfreq_gpubw_get_target(struct devfreq *df, int act_level; int norm_max_cycles; int norm_cycles; - int wait_active_percent; + int wait_active_percent = 0; int gpu_percent; /* * Normalized AB should at max usage be the gpu_bimc frequency in MHz. @@ -132,8 +132,9 @@ static int devfreq_gpubw_get_target(struct devfreq *df, (unsigned int) priv->bus.total_time; norm_cycles = (unsigned int)(priv->bus.ram_time + priv->bus.ram_wait) / (unsigned int) priv->bus.total_time; - wait_active_percent = (100 * (unsigned int)priv->bus.ram_wait) / - (unsigned int) priv->bus.ram_time; + if (priv->bus.ram_time) + wait_active_percent = (100 * (unsigned int)priv->bus.ram_wait) / + (unsigned int) priv->bus.ram_time; gpu_percent = (100 * (unsigned int)priv->bus.gpu_time) / (unsigned int) priv->bus.total_time;