diff options
author | Yaxiong Tian <tianyaxiong@kylinos.cn> | 2025-04-18 09:06:13 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-06-19 15:31:32 +0200 |
commit | 81d72f9241d884ec29524431f74f8009310cfa0c (patch) | |
tree | 972bec5c184bc05446062cc311ee858e40766e4c | |
parent | d05c33c14f09a76fd04279d0eb9dc7d4b86287a7 (diff) |
PM: EM: Fix potential division-by-zero error in em_compute_costs()
[ Upstream commit 179c0c7044a378198adb36f2a12410ab68cc730a ]
When the device is of a non-CPU type, table[i].performance won't be
initialized in the previous em_init_performance(), resulting in division
by zero when calculating costs in em_compute_costs().
Since the 'cost' algorithm is only used for EAS energy efficiency
calculations and is currently not utilized by other device drivers, we
should add the _is_cpu_device(dev) check to prevent this division-by-zero
issue.
Fixes: 1b600da51073 ("PM: EM: Optimize em_cpu_energy() and remove division")
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/tencent_7F99ED4767C1AF7889D0D8AD50F34859CE06@qq.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | kernel/power/energy_model.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 4e1778071d70..1c9fe741fe6d 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -233,6 +233,10 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, unsigned long prev_cost = ULONG_MAX; int i, ret; + /* This is needed only for CPUs and EAS skip other devices */ + if (!_is_cpu_device(dev)) + return 0; + /* Compute the cost of each performance state. */ for (i = nr_states - 1; i >= 0; i--) { unsigned long power_res, cost; |