Message ID | 1537544432-34712-1-git-send-email-vincent.donnefort@arm.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | [v2] PM / devfreq: Stop the governor before device_unregister() | expand |
> From: Vincent Donnefort <vincent.donnefort@arm.com> > > device_release() is freeing the resources before calling the device > specific release callback which is, in the case of devfreq, stopping > the governor. > > It is a problem as some governors are using the device resources. e.g. > simpleondemand which is using the devfreq deferrable monitoring work. If it > is not stopped before the resources are freed, it might lead to a use after > free. > > Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com> > Reviewed-by: John Einar Reitan <john.reitan@arm.com> > Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com> Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com> Cheers, MyungJoo
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 4c49bb1..4e43830 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -534,10 +534,6 @@ static void devfreq_dev_release(struct device *dev) list_del(&devfreq->node); mutex_unlock(&devfreq_list_lock); - if (devfreq->governor) - devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_STOP, NULL); - if (devfreq->profile->exit) devfreq->profile->exit(devfreq->dev.parent); @@ -672,7 +668,7 @@ struct devfreq *devfreq_add_device(struct device *dev, list_del(&devfreq->node); mutex_unlock(&devfreq_list_lock); - device_unregister(&devfreq->dev); + devfreq_remove_device(devfreq); devfreq = NULL; err_dev: if (devfreq) @@ -693,6 +689,9 @@ int devfreq_remove_device(struct devfreq *devfreq) if (!devfreq) return -EINVAL; + if (devfreq->governor) + devfreq->governor->event_handler(devfreq, + DEVFREQ_GOV_STOP, NULL); device_unregister(&devfreq->dev); return 0;