Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4418338ybi; Mon, 15 Jul 2019 08:37:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxv3UHG1PCT381SOGHIFo+8otTcXZA6KfVZJbOWb303upJs+Q2LbBxqigCdUdSYQ31qAVXs X-Received: by 2002:a63:5452:: with SMTP id e18mr11136771pgm.232.1563205068929; Mon, 15 Jul 2019 08:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563205068; cv=none; d=google.com; s=arc-20160816; b=gyIyn/PU7aH1y6MMkkzMS6DEaI8pIHfr4Ke3jJDTNre3svEJ++Is/vJHu0MQyLEl97 OHj4v8i8e87uuOJMIUFGbOVVwXEBysu0C+UO/ycNb1QKOxWqtqujNHXBuIu0hmtvMPmq RzZSE3+pkeXQthG/2AmM8uDztn23exSoKqqgkZ0EGrDxp84DY6x4fLF6UsuFlaWs8HHb CwHzNdTov56DuXzWFk5rm8fUp/70GBG5x1xnaTr/lMh1E6h98IlHfSsuWxK6Bvn1FYKT y58M5zIHjzkU6WxNjSV4iBVTrsP3kM3b60KuFHsDXQQsIzvazT6AMDN7UZr25/Dq5LFP J9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to; bh=cpVknBL+RIV4OLX1JVv/XoCkYRDgfvyIZ2e7v8Xvlf4=; b=nu21BGWCMgwwZVk7OpBfmx2ntz/kXL0AfkJ/e2HSeZSF5ufE9Ng4LgJPyYPlY3V8e3 O9WDHf0tR6pciSrOe0uEztveiIrWg8MnlLMDgzuXpFiGyR3dJ3+P5OIBEMaICH8scglK PLs1vljq97rj3RZDVjK04UC7wvHLe0RHSie0IhqrD7rqFl/KU47+iHoMMoUxib0idukQ 5ArrHuaUr2F8MZk+V7h+tqORyPiGOJidkbt+30n+zaTkQXx4OOfYrP0iBGzQsdz4LvBY 3NzNys4DapoIDrgydRyQi4XF73jCM1T253bcYnZnOY/kG2pdXaVDMiZe19Cz+VbANvL1 jkdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si15454308pgp.296.2019.07.15.08.37.32; Mon, 15 Jul 2019 08:37:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730697AbfGOPei (ORCPT + 99 others); Mon, 15 Jul 2019 11:34:38 -0400 Received: from ns.iliad.fr ([212.27.33.1]:57348 "EHLO ns.iliad.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730296AbfGOPee (ORCPT ); Mon, 15 Jul 2019 11:34:34 -0400 Received: from ns.iliad.fr (localhost [127.0.0.1]) by ns.iliad.fr (Postfix) with ESMTP id 5E0A5202B3; Mon, 15 Jul 2019 17:34:32 +0200 (CEST) Received: from [192.168.108.49] (freebox.vlq16.iliad.fr [213.36.7.13]) by ns.iliad.fr (Postfix) with ESMTP id 441271FF44; Mon, 15 Jul 2019 17:34:32 +0200 (CEST) To: Stephen Boyd , Michael Turquette Cc: linux-clk , LKML , =?UTF-8?Q?Jonathan_Neusch=c3=a4fer?= , Bjorn Andersson , Guenter Roeck From: Marc Gonzalez Subject: [PATCH v1] clk: Add devm_clk_{prepare,enable,prepare_enable} Message-ID: <1d7a1b3b-e9bf-1d80-609d-a9c0c932b15a@free.fr> Date: Mon, 15 Jul 2019 17:34:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP ; ns.iliad.fr ; Mon Jul 15 17:34:32 2019 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide devm variants for automatic resource release on device removal. probe() error-handling is simpler, and remove is no longer required. Signed-off-by: Marc Gonzalez --- Documentation/driver-model/devres.rst | 3 +++ drivers/clk/clk.c | 24 ++++++++++++++++++++++++ include/linux/clk.h | 8 ++++++++ 3 files changed, 35 insertions(+) diff --git a/Documentation/driver-model/devres.rst b/Documentation/driver-model/devres.rst index 1b6ced8e4294..9357260576ef 100644 --- a/Documentation/driver-model/devres.rst +++ b/Documentation/driver-model/devres.rst @@ -253,6 +253,9 @@ CLOCK devm_clk_hw_register() devm_of_clk_add_hw_provider() devm_clk_hw_register_clkdev() + devm_clk_prepare() + devm_clk_enable() + devm_clk_prepare_enable() DMA dmaenginem_async_device_register() diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c0990703ce54..5e85548357c0 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -914,6 +914,18 @@ int clk_prepare(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_prepare); +static void unprepare(void *clk) +{ + clk_unprepare(clk); +} + +int devm_clk_prepare(struct device *dev, struct clk *clk) +{ + int rc = clk_prepare(clk); + return rc ? : devm_add_action_or_reset(dev, unprepare, clk); +} +EXPORT_SYMBOL_GPL(devm_clk_prepare); + static void clk_core_disable(struct clk_core *core) { lockdep_assert_held(&enable_lock); @@ -1136,6 +1148,18 @@ int clk_enable(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_enable); +static void disable(void *clk) +{ + clk_disable(clk); +} + +int devm_clk_enable(struct device *dev, struct clk *clk) +{ + int rc = clk_enable(clk); + return rc ? : devm_add_action_or_reset(dev, disable, clk); +} +EXPORT_SYMBOL_GPL(devm_clk_enable); + static int clk_core_prepare_enable(struct clk_core *core) { int ret; diff --git a/include/linux/clk.h b/include/linux/clk.h index 3c096c7a51dc..d09b5207e3f1 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -895,6 +895,14 @@ static inline void clk_restore_context(void) {} #endif +int devm_clk_prepare(struct device *dev, struct clk *clk); +int devm_clk_enable(struct device *dev, struct clk *clk); +static inline int devm_clk_prepare_enable(struct device *dev, struct clk *clk) +{ + int rc = devm_clk_prepare(dev, clk); + return rc ? : devm_clk_enable(dev, clk); +} + /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ static inline int clk_prepare_enable(struct clk *clk) { -- 2.17.1