linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] PM: EM: Fix potential division-by-zero error in em_compute_costs()
@ 2025-04-11  1:28 Yaxiong Tian
  2025-04-12  1:55 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Yaxiong Tian @ 2025-04-11  1:28 UTC (permalink / raw)
  To: rafael, lukasz.luba; +Cc: linux-pm, linux-kernel, Yaxiong Tian

From: Yaxiong Tian <tianyaxiong@kylinos.cn>

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>
---
 kernel/power/energy_model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index d9b7e2b38c7a..d1fa7e8787b5 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -244,7 +244,7 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table,
 					cost, ret);
 				return -EINVAL;
 			}
-		} else {
+		} else if (_is_cpu_device(dev)) {
 			/* increase resolution of 'cost' precision */
 			power_res = table[i].power * 10;
 			cost = power_res / table[i].performance;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-04-28  1:45 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11  1:28 [PATCH v2] PM: EM: Fix potential division-by-zero error in em_compute_costs() Yaxiong Tian
2025-04-12  1:55 ` kernel test robot
2025-04-14  8:08 ` Lukasz Luba
2025-04-14  9:08   ` Yaxiong Tian
2025-04-17  7:20     ` Geert Uytterhoeven
2025-04-17  7:41       ` Yaxiong Tian
2025-04-15  1:12   ` Yaxiong Tian
2025-04-15  1:58     ` Yaxiong Tian
2025-04-15 17:19       ` Rafael J. Wysocki
2025-04-14  9:04 ` [PATCH v3] " Yaxiong Tian
2025-04-15  8:50   ` Lukasz Luba
2025-04-15 17:17   ` Rafael J. Wysocki
2025-04-16  2:56     ` Yaxiong Tian
2025-04-16 11:58       ` Rafael J. Wysocki
2025-04-16 15:26         ` Lukasz Luba
2025-04-17  0:56         ` Yaxiong Tian
2025-04-17  1:07 ` [PATCH v4] " Yaxiong Tian
2025-04-17  5:57   ` Lukasz Luba
2025-04-17  7:43     ` Yaxiong Tian
2025-04-17 13:27       ` Lukasz Luba
2025-04-18  1:26         ` Yaxiong Tian
2025-04-28  1:45           ` Yaxiong Tian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).