From patchwork Sun May 21 21:59:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9739455 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 EBD4260392 for ; Sun, 21 May 2017 22:00:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCF8D285C9 for ; Sun, 21 May 2017 22:00:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD51A285DB; Sun, 21 May 2017 22:00: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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 6853E285DB for ; Sun, 21 May 2017 22:00:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755163AbdEUWAP (ORCPT ); Sun, 21 May 2017 18:00:15 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:37102 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752186AbdEUWAO (ORCPT ); Sun, 21 May 2017 18:00:14 -0400 Received: by mail-wm0-f48.google.com with SMTP id d127so130109963wmf.0 for ; Sun, 21 May 2017 15:00:13 -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=dbMnD6GhYb06S6pUI5pj0wF05ZOnSQ2j8e24Dk0Zlig=; b=Anb6oB44KSleP80XFrCwNQplHJWmm13NERfmBlbjuv7jdIuy9NlKuGilq0BXAIgii9 UBhapoYPcW/M+2voCMmRuYDJ7gg4cBFJQX/7fIZ2nzga/Mgz/NC4aBgux30FWL1b9dhP ygjhcxXohKsFhydFbRDhUPFXIVd83acZvtH+TgKFESXvvB4NF7CMAs+kfsH8H8zFuXP4 /PSZk8ZLioP7RnjSUKY1fp8rUMSu2KMXsv6tXLv94qnuYjgJTVpAGAy89JiWgc4GBZlL oUhEXDTP+OuJUHj8nehfM1ZbyGfbpnngZLqeWwmkJf1HyRmrDksVDh3QJK8lQb+jzCmf 5h9w== 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=dbMnD6GhYb06S6pUI5pj0wF05ZOnSQ2j8e24Dk0Zlig=; b=tBmMpmTi0MOWt5IWx4S5f+N7yLu3k4xMgSXPvVBo7oveKzX4EnC61o6w5lWXpMVDd+ uaXiIWugzTzTZVH89wQI4+nYDjhJnjDarLIQqofKSxEi3BciF7A01YyxQWGoytDCJc3c RhySLmRRHZWauoVohrEwIc+0joIIKdwReYx488SAccQ9KLVsZL+qBzkV+fu71R8kZwjs gbII/PpwiNkpi8YQJJxpqr1us2Ju8CWBboYu0pKxQZ+E11F0lQQQtobHsZ9Fotd4TrEf Fw9Vh24SvXva0LtJ/iXzf6+9VymqBhviIEl0zvgdwUBHVuaIj9h4Al/y+ajD4HD7MOVJ qvJA== X-Gm-Message-State: AODbwcBYGaGRqFVP7NrSKaKREAmpEyE5MfymfFK2r8O81wYQ82MSmSjT n+IZ/FIzG6vY4mCW X-Received: by 10.223.161.141 with SMTP id u13mr9047000wru.203.1495404012994; Sun, 21 May 2017 15:00:12 -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 a73sm12812579wrc.58.2017.05.21.15.00.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 May 2017 15:00:12 -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, Linus Walleij , Boris Brezillon Subject: [PATCH v2 01/11] clk: take the prepare lock out of clk_core_set_parent Date: Sun, 21 May 2017 23:59:48 +0200 Message-Id: <20170521215958.19743-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170521215958.19743-1-jbrunet@baylibre.com> References: <20170521215958.19743-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 | 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);