diff options
author | Sudeep Holla <sudeep.holla@arm.com> | 2018-09-06 16:10:39 +0100 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2018-09-06 09:59:40 -0700 |
commit | 96d529bac562574600eda85726fcfa3eef6dde8e (patch) | |
tree | 680a3d261814ef7157c0d3cf09bf851b05f40b25 | |
parent | a72b44a871c218e2a0580e68affa1d3528c0587a (diff) | |
download | linux-96d529bac562574600eda85726fcfa3eef6dde8e.tar.gz linux-96d529bac562574600eda85726fcfa3eef6dde8e.tar.bz2 linux-96d529bac562574600eda85726fcfa3eef6dde8e.zip |
firmware: arm_scmi: fix divide by zero when sustained_perf_level is zero
Firmware can provide zero as values for sustained performance level and
corresponding sustained frequency in kHz in order to hide the actual
frequencies and provide only abstract values. It may endup with divide
by zero scenario resulting in kernel panic.
Let's set the multiplication factor to one if either one or both of them
(sustained_perf_level and sustained_freq) are set to zero.
Fixes: a9e3fbfaa0ff ("firmware: arm_scmi: add initial support for performance protocol")
Reported-by: Ionela Voinescu <ionela.voinescu@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Olof Johansson <olof@lixom.net>
-rw-r--r-- | drivers/firmware/arm_scmi/perf.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index 721e6c57beae..64342944d917 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -166,7 +166,13 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain, le32_to_cpu(attr->sustained_freq_khz); dom_info->sustained_perf_level = le32_to_cpu(attr->sustained_perf_level); - dom_info->mult_factor = (dom_info->sustained_freq_khz * 1000) / + if (!dom_info->sustained_freq_khz || + !dom_info->sustained_perf_level) + /* CPUFreq converts to kHz, hence default 1000 */ + dom_info->mult_factor = 1000; + else + dom_info->mult_factor = + (dom_info->sustained_freq_khz * 1000) / dom_info->sustained_perf_level; memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE); } |