From patchwork Tue Mar 21 18:33:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9637321 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 227436020B for ; Tue, 21 Mar 2017 18:34:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A472840E for ; Tue, 21 Mar 2017 18:34:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 047B72841A; Tue, 21 Mar 2017 18:34:13 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 318E22840E for ; Tue, 21 Mar 2017 18:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6hygPldOI3Hk2zXtbVrclbFfhsNofQr0iksia2pQFD8=; b=JpChD0+tQxsDm3voDSQ4tqFhyN 1cD//JyeFK8rfWINiQRQ6t7Fe8tAm7TgKqtxSe3nKKJLpGKywRaMPAkWGrXdW9f8eHbocTmBPj8cj gahVUiVTRHH1e4LU15PPn1qaoCAXSNLfoSoiTZJO3KDsx4LHfQW6s5sIqOmo2tTGHn1h2QlsXk6uq d9XqqnN2DPTcHjn7+Eo5T0uxUK80GNGvsP844y8rKw4tpllPETQXf05z/DAtgxQE6XF5q5PrM+Pqz tiVajckScSMX/JVusAR69LRTBqpxPixPMYZEsmdFcjWGKbaCCJbPyXjv1YfBS0y4959XDKCcbEfiK 5OdyTmXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqOba-0000AA-La; Tue, 21 Mar 2017 18:34:02 +0000 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqObW-00005u-Og for linux-amlogic@lists.infradead.org; Tue, 21 Mar 2017 18:34:01 +0000 Received: by mail-wr0-x232.google.com with SMTP id u108so117389970wrb.3 for ; Tue, 21 Mar 2017 11:33:38 -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=pqsDtSiSf11sXammWk+EhFFMHrSTet6QPqIMOsph0Mw=; b=uVAJzI/Nu3/AFV6Fv6wYljjPpDDBsMZ/lhe6gMbH3w9v98LNk7CGBjlZAWuDHSAL4+ bQQd34KsAk4uZhFaRfumBmT0RuEN0jStF3nPnTdMv7iCT+gCCiqNB7lhb/w3Gw+KYs9i 3ZlNJ7rxxlERRqdNkZDGxkPHnSq+4xMuTPFdms7Q4s1ilxhdfnV1twWHcf3jwwvNBiHe tc59upx6F00hMxrvgoRVHw4Rf2kAkQz3kwQs+M1JlHqHM75tB/ZmV9dQ2Ncoiw0dZYB8 qOxQelHBwWu7WR7BSR2QuBIYKwPFwPGGT3F0lvxbOmdIJVR7hR4e8jv88Ie2IolNcnfG snIA== 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=pqsDtSiSf11sXammWk+EhFFMHrSTet6QPqIMOsph0Mw=; b=clzlRUhZm6zWqMiQG0JuSxgbmX7Vl1CIF7VDvfYDJVIa9lsGVgkogo6FQS5AlkSmBi g29kLnDmzMalr1i1PQZfj0nAi0AHdtJQWiMBa/uPeA7yRgl9YXydJhAYnvf+1VCUEF+C sQ+fxRy8IhfMrCzm7+864UyoVzsDRehSPefjlvEqJvmG4IuWnz74o174uy4EaMvz9fMr 8Hk/wXPw+2o7uQ9m2zJELzRDw91MMoL65NUEcchX7ptIqBhR+o1O/nj0skYPKUGet4Nm mfWAwLcf9S5J4vwIGRDqFB+tbPjKlDVWx3r9AF94vxgD1YZYzF5kIPHHhb4ABOW3sSSc PbVg== X-Gm-Message-State: AFeK/H0Sj6SKJu+I18Le0BUEAVT9M1N2mRAMhMkW9u03v15cqAKS286KtT3K+Of+OaerL5hL X-Received: by 10.223.179.216 with SMTP id x24mr31907905wrd.171.1490121216747; Tue, 21 Mar 2017 11:33:36 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id q12sm18667504wmd.8.2017.03.21.11.33.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Mar 2017 11:33:36 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , Kevin Hilman Subject: [RFC 1/7] clk: take the prepare lock out of clk_core_set_parent Date: Tue, 21 Mar 2017 19:33:24 +0100 Message-Id: <20170321183330.26722-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170321183330.26722-1-jbrunet@baylibre.com> References: <20170321183330.26722-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170321_113359_011572_4DCA82C7 X-CRM114-Status: GOOD ( 12.86 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.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. Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 67201f67a14a..e77f03a47da6 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1794,23 +1794,16 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) 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 = -ENOSYS; - goto out; - } + if ((core->num_parents > 1) && (!core->ops->set_parent)) + return -ENOSYS; /* 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) { @@ -1818,8 +1811,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; } @@ -1829,7 +1821,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); @@ -1842,7 +1834,16 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) __clk_recalc_accuracies(core); } -out: + return ret; +} + +static int clk_core_set_parent_lock(struct clk_core *core, + struct clk_core *parent) +{ + int ret; + + clk_prepare_lock(); + ret = clk_core_set_parent(core, parent); clk_prepare_unlock(); return ret; @@ -1870,7 +1871,8 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (!clk) return 0; - return clk_core_set_parent(clk->core, parent ? parent->core : NULL); + return clk_core_set_parent_lock(clk->core, + parent ? parent->core : NULL); } EXPORT_SYMBOL_GPL(clk_set_parent); @@ -2720,7 +2722,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_lock(child, NULL); } hlist_del_init(&clk->core->child_node);