From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7D7B2DE6E2 for ; Thu, 21 Aug 2025 16:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755793717; cv=none; b=KNIeoQKTzBZLrT4IJJQ6rgAkbrxltk36eUISOrs0c2yYP6cbQPIdKU/rr+H6pLi7vnCr++ViAwUJcMqJu7EfWildZ41NRVrEjvbyg/D7tECC8rZmvA0o8Z8xM1QAhhtqNF1y6Bu3PV33uule63JTXfL5PnBCqeWmYea9VzF+k6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755793717; c=relaxed/simple; bh=CuGdmc1nSLWDhmJP8owlk0OB2hKEey+P8PFdqZoHj3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A51/Le0hCGCUwOUSb8MYhcWhfrIHhHgGE4KyLsl7dLA01GDolCO0Dh4TD0g0w8n1Vm8KGzqLfTbrvElECRc5NThmLl53cNC70Ia88LaYxiElgDjE1mKYW4T08mIc1ICBoP3SISyzJcP4juFTxLLnuhYVIrXzQpOz+GdiGud4Yko= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iRyEFkpf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iRyEFkpf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C2DCC4CEF4; Thu, 21 Aug 2025 16:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755793717; bh=CuGdmc1nSLWDhmJP8owlk0OB2hKEey+P8PFdqZoHj3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRyEFkpfqkI2PnkEDVCDp8ddW8ccshWLwFg9TCCGIhQdiN9Lf6PdUIxrWOY+CqUnL 35iOETT6wn6nr8kh/4P0C5qbKM7ABJyBKQz0N2i/bdD3YT4MAPP/9d0N3oqGjh621c lMdVFsSjF33C48Iq+ItqBsoWezqk96Wl5jGuzOuUSPxe+suCE+4i00oQKdQlzmtDFp ueK/yCe6MwnuUwDYCfPm2sPzyGAVzCSn5hXWJ0gA/0WOYhDm/FdR75lR6dS7ikGbmJ cn+0m5dkR4RrU2RpqgrIXeOLYaCFwHFEBdZ4+1R9FJcQ2SDyI3VjFNif8K6IY5xBqd LPCvBze6JBQbQ== From: Sasha Levin To: stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Ulf Hansson , Sakari Ailus , Sasha Levin Subject: [PATCH 6.6.y 2/2] PM: runtime: Take active children into account in pm_runtime_get_if_in_use() Date: Thu, 21 Aug 2025 12:28:33 -0400 Message-ID: <20250821162833.814231-2-sashal@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250821162833.814231-1-sashal@kernel.org> References: <2025082128-casually-sensuous-5677@gregkh> <20250821162833.814231-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Rafael J. Wysocki" [ 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: c111566bea7c ("PM: runtime: Add pm_runtime_get_if_active()") Signed-off-by: Rafael J. Wysocki Reviewed-by: Ulf Hansson Reviewed-by: Sakari Ailus Cc: 5.10+ # 5.10+: c0ef3df8dbae: PM: runtime: Simplify pm_runtime_get_if_active() usage Cc: 5.10+ # 5.10+ Link: https://patch.msgid.link/12700973.O9o76ZdvQC@rjwysocki.net Signed-off-by: Sasha Levin --- drivers/base/power/runtime.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index d5ac30249cac..b7c4caff743f 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1181,10 +1181,12 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume); * * Return -EINVAL if runtime PM is disabled for @dev. * - * Otherwise, if the runtime PM status of @dev is %RPM_ACTIVE and either - * @ign_usage_count is %true or the runtime PM usage counter of @dev is not - * zero, increment the usage counter of @dev and return 1. Otherwise, return 0 - * without changing the usage counter. + * Otherwise, if its runtime PM status is %RPM_ACTIVE and (1) @ign_usage_count + * is set, or (2) @dev is not ignoring children and its active child count is + * nonero, or (3) the runtime PM usage counter of @dev is not zero, increment + * the usage counter of @dev and return 1. + * + * Otherwise, return 0 without changing the usage counter. * * If @ign_usage_count is %true, this function can be used to prevent suspending * 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) retval = -EINVAL; } else if (dev->power.runtime_status != RPM_ACTIVE) { retval = 0; - } else if (ign_usage_count) { + } else if (ign_usage_count || (!dev->power.ignore_children && + atomic_read(&dev->power.child_count) > 0)) { retval = 1; atomic_inc(&dev->power.usage_count); } else { @@ -1239,10 +1242,16 @@ EXPORT_SYMBOL_GPL(pm_runtime_get_if_active); * @dev: Target device. * * Increment the runtime PM usage counter of @dev if its runtime PM status is - * %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case - * it returns 1. If the device is in a different state or its usage_count is 0, - * 0 is returned. -EINVAL is returned if runtime PM is disabled for the device, - * in which case also the usage_count will remain unmodified. + * %RPM_ACTIVE and its runtime PM usage counter is greater than 0 or it is not + * ignoring children and its active child count is nonzero. 1 is returned in + * this case. + * + * If @dev is in a different state or it is not in use (that is, its usage + * counter is 0, or it is ignoring children, or its active child count is 0), + * 0 is returned. + * + * -EINVAL is returned if runtime PM is disabled for the device, in which case + * also the usage counter of @dev is not updated. */ int pm_runtime_get_if_in_use(struct device *dev) { -- 2.50.1