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 974B576C99; Wed, 21 Feb 2024 14:15:01 +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=1708524901; cv=none; b=h7UgBpGRy4bLwCUo54a277uxDhsSrDuIz0L/GRrhxbKZdyMsm3kJQAs4zo7ygUs2Ij0/QPmbG9Y1khru7OQfQ2CN+jsDbFP2Wflyr55xXrKcWDrHE43APFae09XjS5tV4NPB2isKLFEH+1GWF245EKK6Yt+WzfFgc5TcuqbGvLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524901; c=relaxed/simple; bh=B5ipLj0UUxkPXb39vpInLq0B+4guqqB0jsZ/vglS/wI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W1N0DshSeLlplsGK2fkPS2L1fO/QJPTEku2wFLoastHRxDfcANUIKsdEbgrOGVlYH6SwE70BjRqHqlGJUe/31Dg4mcQNFoiMMeQFTbkoMcrzqHH1t0UFpVHJk3FNnveP4/2avmWuxR9AExtmRPJzI2ZSud+p2o7pxQYw0Eu3rRg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=I2DjueLu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="I2DjueLu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0245C433C7; Wed, 21 Feb 2024 14:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708524901; bh=B5ipLj0UUxkPXb39vpInLq0B+4guqqB0jsZ/vglS/wI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I2DjueLuLv3fEU31ktAsQJHOfF+W2VV8JUnvsljp9+mEbYoMwl7ZFiz89w4LAaNjM mCouDz5piEnRoGRy2RTcKyF5QIPXEHAriPAAq/XptJJdHuUZPyZ1K5YgmNN7trP+iH 93cG8yXLycE85pbqxPovFPWA7+RXnrCVgQpgUkYo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Laurent Pinchart , Douglas Anderson , Ulf Hansson , "Rafael J. Wysocki" , Amit Pundir Subject: [PATCH 5.10 375/379] PM: runtime: Have devm_pm_runtime_enable() handle pm_runtime_dont_use_autosuspend() Date: Wed, 21 Feb 2024 14:09:14 +0100 Message-ID: <20240221130006.155815799@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125954.917878865@linuxfoundation.org> References: <20240221125954.917878865@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Douglas Anderson [ Upstream commit b4060db9251f919506e4d672737c6b8ab9a84701 ] The PM Runtime docs say: Drivers in ->remove() callback should undo the runtime PM changes done in ->probe(). Usually this means calling pm_runtime_disable(), pm_runtime_dont_use_autosuspend() etc. >>From grepping code, it's clear that many people aren't aware of the need to call pm_runtime_dont_use_autosuspend(). When brainstorming solutions, one idea that came up was to leverage the new-ish devm_pm_runtime_enable() function. The idea here is that: * When the devm action is called we know that the driver is being removed. It's the perfect time to undo the use_autosuspend. * The code of pm_runtime_dont_use_autosuspend() already handles the case of being called when autosuspend wasn't enabled. Suggested-by: Laurent Pinchart Signed-off-by: Douglas Anderson Reviewed-by: Ulf Hansson Signed-off-by: Rafael J. Wysocki Stable-dep-of: 3d07a411b4fa ("drm/msm/dsi: Use pm_runtime_resume_and_get to prevent refcnt leaks") Signed-off-by: Amit Pundir Signed-off-by: Greg Kroah-Hartman --- drivers/base/power/runtime.c | 5 +++++ include/linux/pm_runtime.h | 4 ++++ 2 files changed, 9 insertions(+) --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1481,11 +1481,16 @@ EXPORT_SYMBOL_GPL(pm_runtime_enable); static void pm_runtime_disable_action(void *data) { + pm_runtime_dont_use_autosuspend(data); pm_runtime_disable(data); } /** * devm_pm_runtime_enable - devres-enabled version of pm_runtime_enable. + * + * NOTE: this will also handle calling pm_runtime_dont_use_autosuspend() for + * you at driver exit time if needed. + * * @dev: Device to handle. */ int devm_pm_runtime_enable(struct device *dev) --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -539,6 +539,10 @@ static inline void pm_runtime_disable(st * Allow the runtime PM autosuspend mechanism to be used for @dev whenever * requested (or "autosuspend" will be handled as direct runtime-suspend for * it). + * + * NOTE: It's important to undo this with pm_runtime_dont_use_autosuspend() + * at driver exit time unless your driver initially enabled pm_runtime + * with devm_pm_runtime_enable() (which handles it for you). */ static inline void pm_runtime_use_autosuspend(struct device *dev) {