Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1068135pxm; Wed, 23 Feb 2022 17:16:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNluXNhk5584eWPY7U2i9iNDg7qcbv5lpANTiwXLHL3PRj1ETReTYPgQ+t1tLYEZcZR8K1 X-Received: by 2002:a17:90a:2c0c:b0:1b9:fa47:1caf with SMTP id m12-20020a17090a2c0c00b001b9fa471cafmr334350pjd.34.1645665402047; Wed, 23 Feb 2022 17:16:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645665402; cv=none; d=google.com; s=arc-20160816; b=LbKcCABb7jL0YVhkhQc0V20aNpiq2N9d1Ihb8qt7yMztrFYaaauoWHHHLV9begYggM KtJWrknfSH0CTT/1oCfyyqHOW3rfcMWSPeS1w09hWX8zi7/Z5bj3jWnODFLn2AmchS2W D1hxjP4qAUMXv66yhuodW4tOBnohonLUC+CHT9bA0hzci+kpZ4GA/YzApJp1JTh9yekH VlvkfGtY8/cXq1WQJHlvrh3aBwKd0+1EFDNF9HUZVo5zTNJeAX6aQ57o9tpuVmLgkd32 WFM9xBcA5UyLSld7XaJOe15MVOUJHbVzUkBsCHCJPsAJHPl1aKf1mNMFLmUNsMMDhF/6 qJhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PvSxjAkCTzHrnUJ0VH9JVo6LzgFiDVwgoKiwOiM2FoE=; b=qnkH4FpNFhPN1r2AgVdSK9EX3xUc6N6NOlNYYWggh4p7zf1KNV9SphfmWpFwaC/I/U jND2aoDASAx0adkNM8w1EU5olxoZf3His/RsiK/mvjyfU+x0IN2O3R9N03EOibPDo7xY 1zqfppkAuxZZiycRk6MM0gXBAzYTw3ZNTzGPVFsYYJKI3BM8O7Jt9APdjM2UAMOX/15M FaFIv5IGMCW+IibMLnW7Lxq5CTiicUb49Vv0sbEzsbs1uUSxzqeLkF+cY+7vFUYp9FYw pu2bE05fo3unO10FWVIzJ5bgQ9oiXt0V8gUGpaULlSXlY82ibt8aBtoAdPVE97Z610IA Yajw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lIs9bWeQ; 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=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j72si1089030pge.724.2022.02.23.17.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:16:42 -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=@chromium.org header.s=google header.b=lIs9bWeQ; 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=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E97DFFCB6C; Wed, 23 Feb 2022 17:01:52 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242855AbiBWQfs (ORCPT + 99 others); Wed, 23 Feb 2022 11:35:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241768AbiBWQfq (ORCPT ); Wed, 23 Feb 2022 11:35:46 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D386B53B4B for ; Wed, 23 Feb 2022 08:35:18 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id ev16-20020a17090aead000b001bc3835fea8so3334115pjb.0 for ; Wed, 23 Feb 2022 08:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PvSxjAkCTzHrnUJ0VH9JVo6LzgFiDVwgoKiwOiM2FoE=; b=lIs9bWeQZCbVcF0ZizI997m5HtjcGLwofO/q2rO50UhL2K3rqPXTmaaK8+hPGnStlK q0uM9I0AHFvbcVjS9NV0PVxbJ2oX2Dy9tIg/WyZAfQWBlPrACWk9PxTR5y2yk4VmL8IB cqLE3fvXs01qOtV9upS+bV7gb2+cx4ePjwXpU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PvSxjAkCTzHrnUJ0VH9JVo6LzgFiDVwgoKiwOiM2FoE=; b=BVXvkCrcZxFqERyPs9+i0iQJl7MtDwgqXt9x7dMKGZxkXBI4XLMrddX0G4ZLGD1nki E0Y2PoJqjG7ao6TJ+WE3tVhpFC91s4YX8vkMBPyQt8QEIYki6KS/NpI/sbZG3UfogKcz V7jUVKqZ8DOQMogNa2AHiYOAkciSZMFlZVSXaxaLkwXuHRbDQxn+DRw9AyrXEkNtwhPp ausXvOPgVaoxCYY3ZEBoFE7GeNodOauRoDlCBfTPyxeZcup/R3Xs3ejFlyFjxYL0VPC5 3KM+I4Z9XXH0shVHNRdLR9RYcmMDrgtHDbsSvlgPRL3u8rsW9lvKldVXx9LtJsqiTHrA sJbA== X-Gm-Message-State: AOAM533uDGw6VeBpTUERluXCxG8k15J5JAAB81ts6TP20Yd2dgIp0hZi tcNin9ed/3KHqIcoTnTW/4jBVA== X-Received: by 2002:a17:902:a406:b0:14d:61ba:8bcc with SMTP id p6-20020a170902a40600b0014d61ba8bccmr575575plq.36.1645634118294; Wed, 23 Feb 2022 08:35:18 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:201:fbbe:971a:f60f:11e1]) by smtp.gmail.com with ESMTPSA id g20sm4219pfj.64.2022.02.23.08.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 08:35:18 -0800 (PST) From: Douglas Anderson To: "Rafael J . Wysocki" Cc: Dmitry Baryshkov , Linus Walleij , Stephen Boyd , Laurent Pinchart , Douglas Anderson , Greg Kroah-Hartman , Len Brown , Pavel Machek , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH] PM: runtime: Have devm_pm_runtime_enable() handle pm_runtime_dont_use_autosuspend() Date: Wed, 23 Feb 2022 08:34:48 -0800 Message-Id: <20220223083441.1.I925ce9fa12992a58caed6b297e0171d214866fe7@changeid> X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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 --- 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