Commit 23e0fc5a authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM / QoS: Create device constraints objects on notifier registration

The current behavior of dev_pm_qos_add_notifier() makes device PM QoS
notifiers less than useful.  Namely, it silently returns success when
called before any PM QoS constraints are added for the device, so the
caller will assume that the notifier has been registered, but when
someone actually adds some nontrivial constraints for the device
eventually, the previous callers of dev_pm_qos_add_notifier()
will not know about that and their notifier routines will not be
executed (contrary to their expectations).

To address this problem make dev_pm_qos_add_notifier() create the
constraints object for the device if it is not present when the
routine is called.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by : markgross <markgross@thegnar.org>
parent 76e267d8
...@@ -352,21 +352,26 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request); ...@@ -352,21 +352,26 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request);
* *
* Will register the notifier into a notification chain that gets called * Will register the notifier into a notification chain that gets called
* upon changes to the target value for the device. * upon changes to the target value for the device.
*
* If the device's constraints object doesn't exist when this routine is called,
* it will be created (or error code will be returned if that fails).
*/ */
int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier) int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier)
{ {
int retval = 0; int ret = 0;
mutex_lock(&dev_pm_qos_mtx); mutex_lock(&dev_pm_qos_mtx);
/* Silently return if the constraints object is not present. */ if (!dev->power.constraints)
if (dev->power.constraints) ret = dev->power.power_state.event != PM_EVENT_INVALID ?
retval = blocking_notifier_chain_register( dev_pm_qos_constraints_allocate(dev) : -ENODEV;
dev->power.constraints->notifiers,
notifier); if (!ret)
ret = blocking_notifier_chain_register(
dev->power.constraints->notifiers, notifier);
mutex_unlock(&dev_pm_qos_mtx); mutex_unlock(&dev_pm_qos_mtx);
return retval; return ret;
} }
EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier); EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment