Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2261733pxm; Fri, 4 Mar 2022 12:34:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRLF6OnBNbUldOuAsXw72uYR1wKzIzw3Wt26YTP9bBR9DPaVRspbtGkCEbP+aR/BF31ldB X-Received: by 2002:a17:902:e847:b0:150:1198:2355 with SMTP id t7-20020a170902e84700b0015011982355mr174944plg.153.1646426084700; Fri, 04 Mar 2022 12:34:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646426084; cv=none; d=google.com; s=arc-20160816; b=bEIRcy0JA3RSgxiu4ay/d9uscw5JER3zO4EUM+DFpm9uvgCSHNHF1Zl254c57kBCcZ /PMRhTZGZPE1lUpXD/zavmjqZG9kbkigYDx8LkTW7LY4CE/02Y5K7EAqbiPj1crKyMpg 40nWMSbWy6XN74HadkS63lPUx06KhlNfHCUTMJPCILuKXA9g52wRDpMVeO9HFxHaHay7 9bem2yWl2MpViHKFRZDip2A6UT9CYeAiBthJ8DIS711x3/2KTkFIZqn4DmI+SrbOSca0 U3E67xwHRDdcr2/qUpjqi2SMaCeW6S1rpZOakXTvzAhSd9kUrLfoH3fQaw++QAW3RTzI GKZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FHtDwpQlgQxQz5J0sBkaBc/+7e3RgDBHSazI8GPXM1Y=; b=UT4WdzVbJmAhvjRF1VYD1Fhcy3uZ/0nSJd52v/28vVAfusHvC88oMAKnRFGUt6Q1TD rxdpHFWCucf/DxMU5hZDGgVjwlRm2jI5Pdzuchy4qrbxat4g18739KNHFdDrpgc778YA Rmr9c80ccYwyJDVp4Y59bh5QZXThqebAQ/MS8XtJRvBb+3v5Aox1YH1kO5z43zqXdQJu E3lEkxbmOL+aC7JlPdgHs9YHZi3OIyeKShwi+0t3hHD/iTW/TAWYLIY2LRvjfnKrLsty y3c/oW8dWyL82pseNQKJZee3PcNFTSyHR5n817doaLdn/MODdRTectjQ4yclBp9C9556 MWXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GT7fl/gR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k2-20020a170902ce0200b00151c3f9e42fsi1375490plg.437.2022.03.04.12.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:34:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GT7fl/gR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF472229C86; Fri, 4 Mar 2022 11:39:12 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239093AbiCDKFP (ORCPT + 99 others); Fri, 4 Mar 2022 05:05:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239583AbiCDKFB (ORCPT ); Fri, 4 Mar 2022 05:05:01 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6CBF1AA487 for ; Fri, 4 Mar 2022 02:04:06 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id d23so13228617lfv.13 for ; Fri, 04 Mar 2022 02:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FHtDwpQlgQxQz5J0sBkaBc/+7e3RgDBHSazI8GPXM1Y=; b=GT7fl/gRaMvLugm2rOKYUe88d7QtN+V88elk3nozvTiV+Co80FPQWl7fNWHsfmzrm3 uCcO2Lgdxyv+ScS20zbf7r0b0W7XfUn9rbdMUq2kGQvqdjIX3+p5eIpMiSsbMUlK9f7v aP7j96xmoUrrKdrzvxEGwhVSbqPDa2RLvBgAcZjM5PmSe8UsDngFOB2p0cr5N/O8Ycgw Yz49n4d72vE46c318VRhcjvFT+sj86DDfFK0NnbCN+tlGLW/kIITDi8lCDKRCi46KHnK mAmHewQsu4VKEdxAOPo72KJ5fxug5rfFkgHdkXzYwbCHEsg6Dgv8dan1oD2GUvrJW//e TEAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FHtDwpQlgQxQz5J0sBkaBc/+7e3RgDBHSazI8GPXM1Y=; b=dyHFlr0/A2vRpZnfg7uDhtH5xAa6HGXD6nUT1tguH3belbWa9BvebSBG5bLlwLzeCA PS9wMVtVVpSqevCueiqSOJ4Y8rFCK6JqwZgJdehrfF6IF5n8nK2DWqPkljOKTlTp+Wn2 VBUH4NB948babTuBNZYNUzhnxiAuzthlMQznoMZUZpSDImAhLK+u7rreKA9jLl8zBUzs TBDNKkt1XNSJf+EiKBCk1rXebetvuq3Kd/bwV0xzPkz9cR7FevyItcTRnouHkV+oz840 fw2aBN+z21gBAhabaMFBmjgOxmFozPoP11sKMHjz+qGgij67YM9EcLkTmk3l1TpZHbX2 YaJA== X-Gm-Message-State: AOAM530II26mEJ0YAlVA4nkHL9Pkyo0J8BXM2o7BRSvr2shm3HzYmkFl dVFwATc1rBB4a8T3PofWZqCqBfMxpDr6Sgu72So17A== X-Received: by 2002:a19:6f08:0:b0:448:1d19:e69a with SMTP id k8-20020a196f08000000b004481d19e69amr480689lfc.373.1646388245194; Fri, 04 Mar 2022 02:04:05 -0800 (PST) MIME-Version: 1.0 References: <20220223083441.1.I925ce9fa12992a58caed6b297e0171d214866fe7@changeid> In-Reply-To: <20220223083441.1.I925ce9fa12992a58caed6b297e0171d214866fe7@changeid> From: Ulf Hansson Date: Fri, 4 Mar 2022 11:03:28 +0100 Message-ID: Subject: Re: [PATCH] PM: runtime: Have devm_pm_runtime_enable() handle pm_runtime_dont_use_autosuspend() To: Douglas Anderson Cc: "Rafael J . Wysocki" , Dmitry Baryshkov , Linus Walleij , Stephen Boyd , Laurent Pinchart , Greg Kroah-Hartman , Len Brown , Pavel Machek , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 23 Feb 2022 at 17:35, Douglas Anderson wrote: > > 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 Okay, this provides an improvement from the short term perspective. Reviewed-by: Ulf Hansson When I get some time, I will try to explore the ->remove() and ->probe() error-path case a bit more, to try to suggest a new interface that might be able to replace the devm_pm_runtime_enable(). Let's see... Kind regards Uffe > --- > > drivers/base/power/runtime.c | 5 +++++ > include/linux/pm_runtime.h | 4 ++++ > 2 files changed, 9 insertions(+) > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c > index 2f3cce17219b..d4059e6ffeae 100644 > --- a/drivers/base/power/runtime.c > +++ b/drivers/base/power/runtime.c > @@ -1476,11 +1476,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) > diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h > index 9f09601c465a..2bff6a10095d 100644 > --- a/include/linux/pm_runtime.h > +++ b/include/linux/pm_runtime.h > @@ -567,6 +567,10 @@ static inline void pm_runtime_disable(struct device *dev) > * 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) > { > -- > 2.35.1.473.g83b2b277ed-goog >