Skip to content

Commit b947769

Browse files
Kant Fanrafaeljw
authored andcommitted
thermal: devfreq_cooling: use local ops instead of global ops
Fix access illegal address problem in following condition: There are multiple devfreq cooling devices in system, some of them has EM model but others do not. Energy model ops such as state2power will append to global devfreq_cooling_ops when the cooling device with EM model is registered. It makes the cooling device without EM model also use devfreq_cooling_ops after appending when registered later by of_devfreq_cooling_register_power() or of_devfreq_cooling_register(). The IPA governor regards the cooling devices without EM model as a power actor, because they also have energy model ops, and will access illegal address at dfc->em_pd when execute cdev->ops->get_requested_power, cdev->ops->state2power or cdev->ops->power2state. Fixes: 615510f ("thermal: devfreq_cooling: remove old power model and use EM") Cc: 5.13+ <[email protected]> # 5.13+ Signed-off-by: Kant Fan <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7bb732f commit b947769

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

drivers/thermal/devfreq_cooling.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,28 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
358358
struct thermal_cooling_device *cdev;
359359
struct device *dev = df->dev.parent;
360360
struct devfreq_cooling_device *dfc;
361+
struct thermal_cooling_device_ops *ops;
361362
char *name;
362363
int err, num_opps;
363364

364-
dfc = kzalloc(sizeof(*dfc), GFP_KERNEL);
365-
if (!dfc)
365+
ops = kmemdup(&devfreq_cooling_ops, sizeof(*ops), GFP_KERNEL);
366+
if (!ops)
366367
return ERR_PTR(-ENOMEM);
367368

369+
dfc = kzalloc(sizeof(*dfc), GFP_KERNEL);
370+
if (!dfc) {
371+
err = -ENOMEM;
372+
goto free_ops;
373+
}
374+
368375
dfc->devfreq = df;
369376

370377
dfc->em_pd = em_pd_get(dev);
371378
if (dfc->em_pd) {
372-
devfreq_cooling_ops.get_requested_power =
379+
ops->get_requested_power =
373380
devfreq_cooling_get_requested_power;
374-
devfreq_cooling_ops.state2power = devfreq_cooling_state2power;
375-
devfreq_cooling_ops.power2state = devfreq_cooling_power2state;
381+
ops->state2power = devfreq_cooling_state2power;
382+
ops->power2state = devfreq_cooling_power2state;
376383

377384
dfc->power_ops = dfc_power;
378385

@@ -407,8 +414,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
407414
if (!name)
408415
goto remove_qos_req;
409416

410-
cdev = thermal_of_cooling_device_register(np, name, dfc,
411-
&devfreq_cooling_ops);
417+
cdev = thermal_of_cooling_device_register(np, name, dfc, ops);
412418
kfree(name);
413419

414420
if (IS_ERR(cdev)) {
@@ -429,6 +435,8 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
429435
kfree(dfc->freq_table);
430436
free_dfc:
431437
kfree(dfc);
438+
free_ops:
439+
kfree(ops);
432440

433441
return ERR_PTR(err);
434442
}
@@ -510,11 +518,13 @@ EXPORT_SYMBOL_GPL(devfreq_cooling_em_register);
510518
void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
511519
{
512520
struct devfreq_cooling_device *dfc;
521+
const struct thermal_cooling_device_ops *ops;
513522
struct device *dev;
514523

515524
if (IS_ERR_OR_NULL(cdev))
516525
return;
517526

527+
ops = cdev->ops;
518528
dfc = cdev->devdata;
519529
dev = dfc->devfreq->dev.parent;
520530

@@ -525,5 +535,6 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
525535

526536
kfree(dfc->freq_table);
527537
kfree(dfc);
538+
kfree(ops);
528539
}
529540
EXPORT_SYMBOL_GPL(devfreq_cooling_unregister);

0 commit comments

Comments
 (0)