Skip to content

Commit 5480b93

Browse files
rafaeljwopsiff
authored andcommitted
PM: runtime: Take active children into account in pm_runtime_get_if_in_use()
[ Upstream commit 51888393cc64dd0462d0b96c13ab94873abbc030 ] For all practical purposes, there is no difference between the situation in which a given device is not ignoring children and its active child count is nonzero and the situation in which its runtime PM usage counter is nonzero. However, pm_runtime_get_if_in_use() will only increment the device's usage counter and return 1 in the latter case. For consistency, make it do so in the former case either by adjusting pm_runtime_get_conditional() and update the related kerneldoc comments accordingly. Fixes: c111566 ("PM: runtime: Add pm_runtime_get_if_active()") Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Ulf Hansson <[email protected]> Reviewed-by: Sakari Ailus <[email protected]> Cc: 5.10+ <[email protected]> # 5.10+: c0ef3df: PM: runtime: Simplify pm_runtime_get_if_active() usage Cc: 5.10+ <[email protected]> # 5.10+ Link: https://patch.msgid.link/[email protected] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 9e9b1fa7ecaa79036f1c77e2ebe7e0863e192763)
1 parent 8d4d26d commit 5480b93

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

drivers/base/power/runtime.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,10 +1181,12 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume);
11811181
*
11821182
* Return -EINVAL if runtime PM is disabled for @dev.
11831183
*
1184-
* Otherwise, if the runtime PM status of @dev is %RPM_ACTIVE and either
1185-
* @ign_usage_count is %true or the runtime PM usage counter of @dev is not
1186-
* zero, increment the usage counter of @dev and return 1. Otherwise, return 0
1187-
* without changing the usage counter.
1184+
* Otherwise, if its runtime PM status is %RPM_ACTIVE and (1) @ign_usage_count
1185+
* is set, or (2) @dev is not ignoring children and its active child count is
1186+
* nonero, or (3) the runtime PM usage counter of @dev is not zero, increment
1187+
* the usage counter of @dev and return 1.
1188+
*
1189+
* Otherwise, return 0 without changing the usage counter.
11881190
*
11891191
* If @ign_usage_count is %true, this function can be used to prevent suspending
11901192
* the device when its runtime PM status is %RPM_ACTIVE.
@@ -1206,7 +1208,8 @@ static int pm_runtime_get_conditional(struct device *dev, bool ign_usage_count)
12061208
retval = -EINVAL;
12071209
} else if (dev->power.runtime_status != RPM_ACTIVE) {
12081210
retval = 0;
1209-
} else if (ign_usage_count) {
1211+
} else if (ign_usage_count || (!dev->power.ignore_children &&
1212+
atomic_read(&dev->power.child_count) > 0)) {
12101213
retval = 1;
12111214
atomic_inc(&dev->power.usage_count);
12121215
} else {
@@ -1239,10 +1242,16 @@ EXPORT_SYMBOL_GPL(pm_runtime_get_if_active);
12391242
* @dev: Target device.
12401243
*
12411244
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1242-
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case
1243-
* it returns 1. If the device is in a different state or its usage_count is 0,
1244-
* 0 is returned. -EINVAL is returned if runtime PM is disabled for the device,
1245-
* in which case also the usage_count will remain unmodified.
1245+
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0 or it is not
1246+
* ignoring children and its active child count is nonzero. 1 is returned in
1247+
* this case.
1248+
*
1249+
* If @dev is in a different state or it is not in use (that is, its usage
1250+
* counter is 0, or it is ignoring children, or its active child count is 0),
1251+
* 0 is returned.
1252+
*
1253+
* -EINVAL is returned if runtime PM is disabled for the device, in which case
1254+
* also the usage counter of @dev is not updated.
12461255
*/
12471256
int pm_runtime_get_if_in_use(struct device *dev)
12481257
{

0 commit comments

Comments
 (0)