Skip to content

Commit 8a007d6

Browse files
committed
PM: runtime: Take active children into account in pm_runtime_get_if_in_use()
JIRA: https://issues.redhat.com/browse/RHEL-109251 commit 5188839 Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Date: Tue, 15 Jul 2025 15:03:25 +0000 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 <rafael.j.wysocki@intel.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> Cc: 5.10+ <stable@vger.kernel.org> # 5.10+: c0ef3df: PM: runtime: Simplify pm_runtime_get_if_active() usage Cc: 5.10+ <stable@vger.kernel.org> # 5.10+ Link: https://patch.msgid.link/12700973.O9o76ZdvQC@rjwysocki.net Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent dd5176f commit 8a007d6

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
@@ -1203,10 +1203,12 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume);
12031203
*
12041204
* Return -EINVAL if runtime PM is disabled for @dev.
12051205
*
1206-
* Otherwise, if the runtime PM status of @dev is %RPM_ACTIVE and either
1207-
* @ign_usage_count is %true or the runtime PM usage counter of @dev is not
1208-
* zero, increment the usage counter of @dev and return 1. Otherwise, return 0
1209-
* without changing the usage counter.
1206+
* Otherwise, if its runtime PM status is %RPM_ACTIVE and (1) @ign_usage_count
1207+
* is set, or (2) @dev is not ignoring children and its active child count is
1208+
* nonero, or (3) the runtime PM usage counter of @dev is not zero, increment
1209+
* the usage counter of @dev and return 1.
1210+
*
1211+
* Otherwise, return 0 without changing the usage counter.
12101212
*
12111213
* If @ign_usage_count is %true, this function can be used to prevent suspending
12121214
* the device when its runtime PM status is %RPM_ACTIVE.
@@ -1228,7 +1230,8 @@ static int pm_runtime_get_conditional(struct device *dev, bool ign_usage_count)
12281230
retval = -EINVAL;
12291231
} else if (dev->power.runtime_status != RPM_ACTIVE) {
12301232
retval = 0;
1231-
} else if (ign_usage_count) {
1233+
} else if (ign_usage_count || (!dev->power.ignore_children &&
1234+
atomic_read(&dev->power.child_count) > 0)) {
12321235
retval = 1;
12331236
atomic_inc(&dev->power.usage_count);
12341237
} else {
@@ -1261,10 +1264,16 @@ EXPORT_SYMBOL_GPL(pm_runtime_get_if_active);
12611264
* @dev: Target device.
12621265
*
12631266
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1264-
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case
1265-
* it returns 1. If the device is in a different state or its usage_count is 0,
1266-
* 0 is returned. -EINVAL is returned if runtime PM is disabled for the device,
1267-
* in which case also the usage_count will remain unmodified.
1267+
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0 or it is not
1268+
* ignoring children and its active child count is nonzero. 1 is returned in
1269+
* this case.
1270+
*
1271+
* If @dev is in a different state or it is not in use (that is, its usage
1272+
* counter is 0, or it is ignoring children, or its active child count is 0),
1273+
* 0 is returned.
1274+
*
1275+
* -EINVAL is returned if runtime PM is disabled for the device, in which case
1276+
* also the usage counter of @dev is not updated.
12681277
*/
12691278
int pm_runtime_get_if_in_use(struct device *dev)
12701279
{

0 commit comments

Comments
 (0)