Skip to content

Commit 179c0c7

Browse files
Yaxiong Tianrafaeljw
authored andcommitted
PM: EM: Fix potential division-by-zero error in em_compute_costs()
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: 1b600da ("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>
1 parent b443265 commit 179c0c7

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

kernel/power/energy_model.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table,
233233
unsigned long prev_cost = ULONG_MAX;
234234
int i, ret;
235235

236+
/* This is needed only for CPUs and EAS skip other devices */
237+
if (!_is_cpu_device(dev))
238+
return 0;
239+
236240
/* Compute the cost of each performance state. */
237241
for (i = nr_states - 1; i >= 0; i--) {
238242
unsigned long power_res, cost;

0 commit comments

Comments
 (0)