From patchwork Sat Jul 31 19:50:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 489847 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp530434jas; Sat, 31 Jul 2021 12:50:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh47r7ed6uY5yaTy1tNar7sY7JR5m3NW72iaYd8/QhSU/TzKDiU3BBAUaQVpAAtNYfwtJc X-Received: by 2002:a05:6402:95a:: with SMTP id h26mr10354608edz.109.1627761048547; Sat, 31 Jul 2021 12:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627761048; cv=none; d=google.com; s=arc-20160816; b=hSng5asZtuCm5VFZnGf+5pIJinh6yp4np/MPp6jEE6YWVxQ+Fx8qt6Y/6KqPY3GiYV l6bklJO0IBOI0Gmc3mgKZc5FqCrGRoevbX62C9pBKhu1lhmj8Z5bQ86l2bpQ8dinVn88 +Yij3MUwZaSJ/VQwTyKFpQta6jucVQ6cpkP0BSlh/o8Yb2x6lNn1Cvi+cuOe+96JzAJ+ yhJznE9UhvsxdNRYQ6TfI1bHBFuRMpMTI97sTzwNUzzsInV2cqx63Dj59qSGqZ/mu3f2 xZ13A/44Gkawkvzuhw/kg6cpU0VNkHi3ibAr990xUU1cCPg+ZPb8cmdUdWVaJWTB9mCM WwjA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a3HfCoK/N2a3QV65vcttbj2g0Y4NliR7IfkMwtRbhSY=; b=GJLzAi5A0sUgSFgt8jYtCoUTD4JLEn2tQEsKBgH8c82qP8rjLe12ZwkFblIsqchsvi ayWzuJhisRHHEf0MejJtUlxuZCnEN/iDM7jlWWkbR23PjiI3tXzW0gZyVcU8ZlngIQ+6 xE/isKlqM8iAh/peuuKnyLNKKSsfyZ7jT8ee7bZagDOZHySGyvga7IyQNDONGd18+2Pi +8jXc9vFSRNwR6nj63TGpze/9xMYP1GzAxdvdF7W3M48vvdmnIuPcsTCYEaVs4IfMq/X lcOua3IvkGvoH5KovDy9TorScciwL1gTSms1ttsIUdkoSZXj6ahM+ERXK29zTGz+WPmE I+eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h0XIju8e; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si6805829eji.536.2021.07.31.12.50.48; Sat, 31 Jul 2021 12:50:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h0XIju8e; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbhGaTuq (ORCPT + 8 others); Sat, 31 Jul 2021 15:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbhGaTup (ORCPT ); Sat, 31 Jul 2021 15:50:45 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138E1C061798 for ; Sat, 31 Jul 2021 12:50:39 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id f12so18025548ljn.1 for ; Sat, 31 Jul 2021 12:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a3HfCoK/N2a3QV65vcttbj2g0Y4NliR7IfkMwtRbhSY=; b=h0XIju8emNWth5jqECkvdQqW6QJ4e0Q50EMYw1kFfau1vwfi8sIivLnMvYJPkyozCY N3a4vjx4SrW4h6PyJJEwFIJF4PrDiEExFvFeC5t2IKTF9xQuUq6/Rn3InlGB3Gfayxe/ JR2OSb+LkMuDO9gnHJTLWfPMB2rGIx0SmjrxzjY3Zrwyo5dvnYIZO1EqjdWINRjWRFDg 1/NDWHp7LJ6QY91cS81uu3pjMPLj9tYHWVC5G2EPQ87Vcb/jm69/Kefxm1alWrsIqBDR FGtOs27f1UP10Hvf5KMcomYatNRepfmjX/Da0FbfsC0Xbm37bkx/QOnkJ4F5Jq3sMEmM 0i+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a3HfCoK/N2a3QV65vcttbj2g0Y4NliR7IfkMwtRbhSY=; b=Hj6JsTMCG2xZia6srKgZKwf4RpEgyqZskRpshqjY3g3n/8tNtgBgnnzWHmjhsPfInS Au+px+vohB1gZR+C/kFlxKcfs4WCTv3H6wP/Sq+Odwu1xu0gduK2mNvvQkSQEfL09iBV rtBYiGY/9S27AS8d33MoZVuAEMKGo/MrV9Uv/WIQpxVdhns2IE31PRcG1dTJUZqdWQ1a +o3AooM5h11t0+zTpDJhN9OupFvj5lBLfdGPf8pBv7AYQQOfN4cbOUablqz1thbfOXeZ wqT6asg9Kd8z52StwMzoEtaIxtQPMmybDrocwwj2TCguuNG5CdGP+N8JNjQGAyLgxrY7 mwtQ== X-Gm-Message-State: AOAM532wwOBpB7jMjq8/tAeJPjxmZ7SN2I9miEpA7MWY/B0maYaV9ro2 fHNQN/hTPFUcn3xpDt7ibOOeaQ== X-Received: by 2002:a2e:9e8e:: with SMTP id f14mr6069954ljk.502.1627761037354; Sat, 31 Jul 2021 12:50:37 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id f3sm469827lfm.76.2021.07.31.12.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 12:50:37 -0700 (PDT) From: Dmitry Baryshkov To: "Rafael J. Wysocki" , Pavel Machek , Greg Kroah-Hartman , Stephen Boyd , Taniya Das , Michael Turquette , Andy Gross , Bjorn Andersson Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v3 1/3] PM: runtime: add devm_pm_runtime_enable helper Date: Sat, 31 Jul 2021 22:50:32 +0300 Message-Id: <20210731195034.979084-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210731195034.979084-1-dmitry.baryshkov@linaro.org> References: <20210731195034.979084-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org A typical code pattern for pm_runtime_enable() call is to call it in the _probe function and to call pm_runtime_disable() both from _probe error path and from _remove function. For some drivers the whole remove function would consist of the call to pm_remove_disable(). Add helper function to replace this bolierplate piece of code. Calling devm_pm_runtime_enable() removes the need for calling pm_runtime_disable() both in the probe()'s error path and in the remove() function. Signed-off-by: Dmitry Baryshkov --- drivers/base/power/runtime.c | 17 +++++++++++++++++ include/linux/pm_runtime.h | 4 ++++ 2 files changed, 21 insertions(+) -- 2.30.2 Acked-by: Rafael J. Wysocki diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 8a66eaf731e4..ec94049442b9 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1447,6 +1447,23 @@ void pm_runtime_enable(struct device *dev) } EXPORT_SYMBOL_GPL(pm_runtime_enable); +static void pm_runtime_disable_action(void *data) +{ + pm_runtime_disable(data); +} + +/** + * devm_pm_runtime_enable - devres-enabled version of pm_runtime_enable. + * @dev: Device to handle. + */ +int devm_pm_runtime_enable(struct device *dev) +{ + pm_runtime_enable(dev); + + return devm_add_action_or_reset(dev, pm_runtime_disable_action, dev); +} +EXPORT_SYMBOL_GPL(devm_pm_runtime_enable); + /** * pm_runtime_forbid - Block runtime PM of a device. * @dev: Device to handle. diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index aab8b35e9f8a..222da43b7096 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -59,6 +59,8 @@ extern void pm_runtime_put_suppliers(struct device *dev); extern void pm_runtime_new_link(struct device *dev); extern void pm_runtime_drop_link(struct device_link *link); +extern int devm_pm_runtime_enable(struct device *dev); + /** * pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter. * @dev: Target device. @@ -253,6 +255,8 @@ static inline void __pm_runtime_disable(struct device *dev, bool c) {} static inline void pm_runtime_allow(struct device *dev) {} static inline void pm_runtime_forbid(struct device *dev) {} +static inline int devm_pm_runtime_enable(struct device *dev) { return 0; } + static inline void pm_suspend_ignore_children(struct device *dev, bool enable) {} static inline void pm_runtime_get_noresume(struct device *dev) {} static inline void pm_runtime_put_noidle(struct device *dev) {}