msm: kgsl: Fix UBSAN warnings

Fix possible division by zero error.

Change-Id: I64eb6a5ee1247dafea6701b8244eefab1c40eea6
Signed-off-by: Jeyaprabu J <quic_jeyaprab@quicinc.com>
This commit is contained in:
Jeyaprabu J 2022-03-22 12:24:47 +05:30 • committed by Alexander Winkowski
commit 726d78ef8a
No known key found for this signature in database
GPG key ID: 72762A66704CDE44
2 changed files with 9 additions and 4 deletions

View file

@ -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);

View file

@ -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;