From patchwork Mon Jun 12 19:44:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9782691 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 D39C46038F for ; Mon, 12 Jun 2017 19:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1D66284F1 for ; Mon, 12 Jun 2017 19:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B60FB286B7; Mon, 12 Jun 2017 19:45:25 +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=unavailable 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 17346284F1 for ; Mon, 12 Jun 2017 19:45:24 +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=Pik1OqoPYneMGHCYi53cFCcN5sfcp0jAQKeGxZltI4g=; b=WqNQPS8SaSJ0/L6fPEOsj04Hzd Cl0aAFEMsTmgZyADZsh6vKS1WQ97kKih1a5jvGgbHNG1913c5xcBFwa/m7Ejt5Vb8ueTh6JuWvQpD tZP8xAdQeswWWx112X/fY//i1H19JP+kdJn4iwI0bkPUdMhj2W8xKHAxNObKWa4d4o/s0kNLnFOpT WyL81Eh3U3mDIrehGppDbJ0Vsg44Q6HfxvFeelIYDNMaT3xhBzEEWX6uOWldrlVAmmayDRvOQ55PI 0RyvkBWB3rNu4J6C8iKIlZh40kEwtHkITpTxwJCaE5SmXXpxp5o+g3rguldj9TtyrTxzcP4fH1jcT 2H/U/e3g==; 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 1dKVH1-0004jF-Ja; Mon, 12 Jun 2017 19:45:15 +0000 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKVGu-0003QX-P9 for linux-amlogic@lists.infradead.org; Mon, 12 Jun 2017 19:45:12 +0000 Received: by mail-wr0-x22e.google.com with SMTP id v111so110848213wrc.3 for ; Mon, 12 Jun 2017 12:44:48 -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=nrMnHGML8dCnvIltWFV38MjWiIbtCIbqAzWNgTaxHb8=; b=bH3PnZLtEuqBp6sQBjDZxLxu8Lls3Gjs/qVTHt6/lsFPA7T4ad2u5sIiAXQUbcJdbI SV0c+55TAi+48NJfi9WEEDrhGx9QRaVMFk6ecp0Rxl9ecu/K02jpzj+I/VYcLQAJIm/m 3lKhm9cCTbnse7y2rxKhO95aljfBv9MG56ZxXee83IyNa7y39JRDBZKHhl/yTmcvzWkM LxsGo3vd/4X8IwtB0Yn/QDFbZSOkGM3nKM8IGup/nqLQaUkoJLDy7lDCq3ghev4axoLv LAoPgXdowJzSuk6E10D43qRGYSaJYtcN8CH9ov6o9Y87rjVwR3NAgc/TUBcdU9dHxU/H GdwA== 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=nrMnHGML8dCnvIltWFV38MjWiIbtCIbqAzWNgTaxHb8=; b=FWv8Vyw4gYXOe+jE/aPLXbXDPSP/1QoZIfb0UwVvSRIl5L4kvQSnxP7swKZubH0Rdd 0Zw9zUofltxiVGDaMsLhJHoMAYZ3O54F5HSWB8KAupRwrTCrgTRFaDNaZI6bKqhAZgfP s+cnKIOIiMlyEbX8JamaVvErLHYYJS07vQ+C/k525RZVEM4Ldc7PmGsWMPqF077o3yuv ahfVHWFGi9qyiru0A6KfHJwtn61BOONowIMGSbor+akH7iiVFzbz2Eha49HdEcuLPsS5 taXf0tpk2y3BXWa07cJ0lAPm2iwDRWa+EPgn1myzWKKfNFXiIuPFOTi2T7aw3+LIShLz F65g== X-Gm-Message-State: AKS2vOwbeNHJPaTC1NeL+ApruD1p62K3gVKPLmPTzjylMvQ1TfDmZZs1 Te23FZZAjGEfzBhh X-Received: by 10.223.149.99 with SMTP id 90mr341591wrs.142.1497296686841; Mon, 12 Jun 2017 12:44:46 -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 70sm13250797wmu.28.2017.06.12.12.44.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 12:44:46 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH v3 01/10] clk: take the prepare lock out of clk_core_set_parent Date: Mon, 12 Jun 2017 21:44:29 +0200 Message-Id: <20170612194438.12298-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170612194438.12298-1-jbrunet@baylibre.com> References: <20170612194438.12298-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170612_124508_974650_36FB21A7 X-CRM114-Status: GOOD ( 14.35 ) 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: Boris Brezillon , Kevin Hilman , Linus Walleij , Russell King , linux-amlogic@lists.infradead.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 | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index fc58c52a26b4..f5c371532509 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1787,7 +1787,8 @@ 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; @@ -1796,23 +1797,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) { @@ -1820,8 +1814,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 +1824,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 +1837,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 +1859,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 +2750,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);