From patchwork Sun Sep 24 20:00:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9968201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6405602CB for ; Sun, 24 Sep 2017 20:02:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B970E288BB for ; Sun, 24 Sep 2017 20:02:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE3BB28C28; Sun, 24 Sep 2017 20:02:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D53F288BB for ; Sun, 24 Sep 2017 20:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752901AbdIXUAm (ORCPT ); Sun, 24 Sep 2017 16:00:42 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:48103 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752882AbdIXUAk (ORCPT ); Sun, 24 Sep 2017 16:00:40 -0400 Received: by mail-wr0-f172.google.com with SMTP id k20so4628511wre.4 for ; Sun, 24 Sep 2017 13:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AfhENWZl2LANeZabV4mdMhMwMkfHVkaU4FKcufEJiec=; b=ekYRbl3kpCAuq7B4OQgRGpoK3sIrNUXgi0detlRWJbmARS7GgOhvNEc1I1e0aKTb8e CGDCwb9xYgy6rqEB5wxl9MteBMTkwK9Lh3nxNwzrAS221SnnSbQ8vQR/cV6TTgj27Lwb cNsymjWBEzUZ5nQartM1NjCGLxd99aITaSX6ft7kFOWWf14A7Q0nt8NAORLG6FAVD5xo zO/SLyKqlfXwbkN/TcFE+nfZr4P87txRSRo96+T+jZ+UTy409oI/XZAyY6PsZdozXJnb EjOQRleTMATn2S01DfKG5+07x0ZQImhQGpit/LrCpkeVEY5KPyUHaS5ylnAPETYhYoYu IStg== 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; bh=AfhENWZl2LANeZabV4mdMhMwMkfHVkaU4FKcufEJiec=; b=alg2b8ifCVLhTvUXRUGrNo8lGDix5IlJ5wBprSwQrRZqr/eEqWBUPcZ4R1ah19BJew vZjTxRB7sLRmU8r9o1W05YkLTpnypSrKp5BlBSIgKzjyfrtoj1dkDksatD2RiERdQLB6 E6Qh8FnfU283XwLdxxoUXCrjB/Wvl4pO4AJ99T30X1uxiQg/7CCSWcaIwiqysSKcDp9h niW6WrwsY4UDL08R0pqBtVvM/JBmLD7t57bIQef+CvHEcpQ2nZ3xdKkEB6lzJ/uH3qt2 i7My54miX1+XvdR2NVpWnm4nV4S6NCHwu4bDEqE8eyV1L6aHHRHh0RAeOyHe5tkRd5Oq pWsQ== X-Gm-Message-State: AHPjjUhMRvCLTCEyKRQA+z/OKNu9jiGwiv4bfu4XusIPi1KJwepaGvmu Mb9w+89YLCUg3uVifHKN3yRrzA== X-Google-Smtp-Source: AOwi7QDTkwzfQrB8onMF+LHQJ3c3teY8Evjf2CaIpCikXRVCtrC/hjti1grv0ZNYbDqMKXvo+vg2hg== X-Received: by 10.223.157.142 with SMTP id p14mr3817079wre.104.1506283238993; Sun, 24 Sep 2017 13:00:38 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:38 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 02/10] clk: take the prepare lock out of clk_core_set_parent Date: Sun, 24 Sep 2017 22:00:22 +0200 Message-Id: <20170924200030.6227-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rework set_parent core function so it can be called when the prepare lock is already held by the caller. This rework is done to ease the integration of the "protected" clock functionality. Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b31e56b09e25..3518f251cfd5 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1787,32 +1787,28 @@ bool clk_has_parent(struct clk *clk, struct clk *parent) } EXPORT_SYMBOL_GPL(clk_has_parent); -static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) +static int clk_core_set_parent_nolock(struct clk_core *core, + struct clk_core *parent) { int ret = 0; int p_index = 0; unsigned long p_rate = 0; + lockdep_assert_held(&prepare_lock); + if (!core) return 0; - /* prevent racing with updates to the clock topology */ - clk_prepare_lock(); - if (core->parent == parent) - goto out; + return 0; /* verify ops for for multi-parent clks */ - if ((core->num_parents > 1) && (!core->ops->set_parent)) { - ret = -EPERM; - goto out; - } + if (core->num_parents > 1 && !core->ops->set_parent) + return -EPERM; /* check that we are allowed to re-parent if the clock is in use */ - if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { - ret = -EBUSY; - goto out; - } + if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) + return -EBUSY; /* try finding the new parent index */ if (parent) { @@ -1820,8 +1816,7 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) if (p_index < 0) { pr_debug("%s: clk %s can not be parent of clk %s\n", __func__, parent->name, core->name); - ret = p_index; - goto out; + return p_index; } p_rate = parent->rate; } @@ -1831,7 +1826,7 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) /* abort if a driver objects */ if (ret & NOTIFY_STOP_MASK) - goto out; + return ret; /* do the re-parent */ ret = __clk_set_parent(core, parent, p_index); @@ -1844,9 +1839,6 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) __clk_recalc_accuracies(core); } -out: - clk_prepare_unlock(); - return ret; } @@ -1869,10 +1861,17 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) */ int clk_set_parent(struct clk *clk, struct clk *parent) { + int ret; + if (!clk) return 0; - return clk_core_set_parent(clk->core, parent ? parent->core : NULL); + clk_prepare_lock(); + ret = clk_core_set_parent_nolock(clk->core, + parent ? parent->core : NULL); + clk_prepare_unlock(); + + return ret; } EXPORT_SYMBOL_GPL(clk_set_parent); @@ -2753,7 +2752,7 @@ void clk_unregister(struct clk *clk) /* Reparent all children to the orphan list. */ hlist_for_each_entry_safe(child, t, &clk->core->children, child_node) - clk_core_set_parent(child, NULL); + clk_core_set_parent_nolock(child, NULL); } hlist_del_init(&clk->core->child_node);