Skip to content

Commit 8188672

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM: EM: Check if the get_cost() callback is present in em_compute_costs()
Subsequent changes will introduce a case in which 'cb->get_cost' may not be set in em_compute_costs(), so add a check to ensure that it is not NULL before attempting to dereference it. Reviewed-by: Dietmar Eggemann <[email protected]> Tested-by: Dietmar Eggemann <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent faf7075 commit 8188672

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/power/energy_model.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table,
116116
for (i = nr_states - 1; i >= 0; i--) {
117117
unsigned long power_res, cost;
118118

119-
if (flags & EM_PERF_DOMAIN_ARTIFICIAL) {
119+
if ((flags & EM_PERF_DOMAIN_ARTIFICIAL) && cb->get_cost) {
120120
ret = cb->get_cost(dev, table[i].frequency, &cost);
121121
if (ret || !cost || cost > EM_MAX_POWER) {
122122
dev_err(dev, "EM: invalid cost %lu %d\n",

0 commit comments

Comments
 (0)