Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8403165 authored by Pranav Patel's avatar Pranav Patel
Browse files

msm: kgsl: fix division results for UBSAN warnings



Possible divide by zero can occur in wait_active_percent
calculation as reported by UBSAN. Fix this possible
division by zero.

Change-Id: I9068fbcc9347eade8a51c7fc3526491511188f03
Signed-off-by: default avatarPranav Patel <quic_pranavp@quicinc.com>
parent ded0049a
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#include <linux/devfreq.h>
@@ -149,8 +150,15 @@ 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;

	if (priv->bus.ram_wait == 0)
		wait_active_percent = 0;
	else if (priv->bus.ram_time == 0)
		wait_active_percent = 100;
	else
		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;