diff options
author | Bjorn Andersson <bjorn.andersson@linaro.org> | 2022-01-18 10:56:12 -0800 |
---|---|---|
committer | Vinod Koul <vkoul@kernel.org> | 2022-01-25 16:41:02 +0530 |
commit | 8b4561ee07948f9342e3586efad1a4bd59477537 (patch) | |
tree | 91af9ca37e1f1f9730fccd36f4e034d92c5bb0bf | |
parent | dc94d1e4257e5a751fc8ecc84edfd3d4d42c50af (diff) |
arch_topology: Sanity check cpumask in thermal pressure update
Occasionally during boot the Qualcomm cpufreq driver was able to cause
an invalid memory access in topology_update_thermal_pressure() on the
line:
if (max_freq <= capped_freq)
It turns out that this was caused by a race, which resulted in the
cpumask passed to the function being empty, in which case
cpumask_first() will return a cpu beyond the number of valid cpus, which
when used to access the per_cpu max_freq would return invalid pointer.
The bug in the Qualcomm cpufreq driver is being fixed, but having a
sanity check of the arguments would have saved quite a bit of time and
it's not unlikely that others will run into the same issue.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Message-Id: <20220118185612.2067031-2-bjorn.andersson@linaro.org>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
-rw-r--r-- | drivers/base/arch_topology.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 976154140f0b..6560a0c3b969 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -177,6 +177,9 @@ void topology_update_thermal_pressure(const struct cpumask *cpus, u32 max_freq; int cpu; + if (WARN_ON(cpumask_empty(cpus))) + return; + cpu = cpumask_first(cpus); max_capacity = arch_scale_cpu_capacity(cpu); max_freq = per_cpu(freq_factor, cpu); |