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: 9637347 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 73AB960327 for ; Tue, 21 Mar 2017 18:43:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67D8F28418 for ; Tue, 21 Mar 2017 18:43:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C8382840E; Tue, 21 Mar 2017 18:43:15 +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 CF07D28405 for ; Tue, 21 Mar 2017 18:43:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933158AbdCUSnL (ORCPT ); Tue, 21 Mar 2017 14:43:11 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:33659 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933128AbdCUSmz (ORCPT ); Tue, 21 Mar 2017 14:42:55 -0400 Received: by mail-wr0-f173.google.com with SMTP id u48so117582609wrc.0 for ; Tue, 21 Mar 2017 11:42:54 -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=mqAGaT+LKg3f6g7B0ic00RVieDM/RQe2kuGCwCd+HQp/Pvhu/jWE/6aMfmQAj+3Att vFDUCvSmUrlRiIxs/yG3mA3649EaRXHOCtXayQQJTpAKf86irIJeNTB9GNLPeAeK7wb0 RKEqoN6bBG/qTwc8QTZ4xskxYhJ/ZAdl1a2eJ9c0k/K2hGJwz5XcGGRPIhpUdwP8yVBc mc2x9Hz3YTNsPVbnr6QfcdmDBQdRKmyxH0+F6QV8J275ySNZB+dwpezBPirwIEi8lH8U iHY4uvZyYClTAqLoRF2a0QAfQpMvBaFHz6pq0EpaOgTspXyaheJIPQXet8G/T8E0vaTa ghpQ== X-Gm-Message-State: AFeK/H1MwWHBLVED9NpJbljdgpm7WOVA05WrqWtzp+sUgNakUDNXmv4D5RPt3Yi683bev5a7 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 Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org 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> 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. 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);