From patchwork Thu Mar 21 13:48:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 15470 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5FB9B23E3E for ; Thu, 21 Mar 2013 13:48:35 +0000 (UTC) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by fiordland.canonical.com (Postfix) with ESMTP id 03BE3A18434 for ; Thu, 21 Mar 2013 13:48:34 +0000 (UTC) Received: by mail-ve0-f169.google.com with SMTP id 15so2459591vea.28 for ; Thu, 21 Mar 2013 06:48:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type:x-gm-message-state; bh=g5xmHnrNIPx1cAzNj/XZc7YtyxqhmOZwoQKwpr1gWf8=; b=c309iWfvFsplv8xqP54+Rsds67OnV1CLMFECb39zOjWmvVwlrjkxvIA+nkDy7xKhUA QwH2f18pFg7Bg3fB55/49Zlo10QpA52ysvlhhM+QxOp6H6p/o/OiZFXhqQtUO/Wn8yYC PcmlF751IbDkemW2untTp4DWBZHnVffR6cEInM2D59Qh1F76TRNLsPDRN2v46dh2QxZB 3JXpNZDMSY073VibguYikRqtfdoiXZqEl2D9m4nZ7adlHg8rGsB04IjzmW0QfIG0Enrs XAx5IQFoyUkL+FvTa+B499MY9tBog3uMICPq3egLz3E9JWbKZ2HJv5ta6/a/H7fP+SNr tF+w== X-Received: by 10.52.20.239 with SMTP id q15mr11513502vde.73.1363873714487; Thu, 21 Mar 2013 06:48:34 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.233.198 with SMTP id ty6csp61164vec; Thu, 21 Mar 2013 06:48:33 -0700 (PDT) X-Received: by 10.180.100.10 with SMTP id eu10mr5151186wib.4.1363873713225; Thu, 21 Mar 2013 06:48:33 -0700 (PDT) Received: from eu1sys200aog110.obsmtp.com (eu1sys200aog110.obsmtp.com [207.126.144.129]) by mx.google.com with SMTP id 3si8928871eeb.16.2013.03.21.06.48.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 21 Mar 2013 06:48:33 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.129 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.129; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.129 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) smtp.mail=ulf.hansson@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob110.postini.com ([207.126.147.11]) with SMTP ID DSNKUUsPrNyar9KHQfw+CJCJ3BVxRDIVFvHm@postini.com; Thu, 21 Mar 2013 13:48:32 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 0945055; Thu, 21 Mar 2013 13:47:34 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 4546754; Thu, 21 Mar 2013 07:21:38 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id B2CB024C080; Thu, 21 Mar 2013 14:48:18 +0100 (CET) Received: from steludxu1397.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.279.5; Thu, 21 Mar 2013 14:48:25 +0100 From: Ulf Hansson To: , Mike Turquette Cc: Linus Walleij , Par-Olof Hakansson , Ulf Hansson Subject: [PATCH V2 2/3] clk: Improve errorhandling for clk_set_parent Date: Thu, 21 Mar 2013 14:48:12 +0100 Message-ID: <1363873693-30902-3-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1363873693-30902-1-git-send-email-ulf.hansson@stericsson.com> References: <1363873693-30902-1-git-send-email-ulf.hansson@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlUgpQ3UqTS/L4kRHZF2ESUmmMAldeUY+Wvlt21ts6La5M7350tFgEitatb29z+ukFoDbil From: Ulf Hansson By verifying all the needed static information before doing the clk notifications, we minimize number of unwanted rollback notifications with ABORT_RATE_CHANGE message to occur. Additionally make sure the parent are valid pointer before using it. Signed-off-by: Ulf Hansson --- drivers/clk/clk.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index d73fb0f..c7eb0d7 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1269,15 +1269,10 @@ void __clk_reparent(struct clk *clk, struct clk *new_parent) __clk_recalc_rates(clk, POST_RATE_CHANGE); } -static int __clk_set_parent(struct clk *clk, struct clk *parent) +static u8 clk_fetch_parent_index(struct clk *clk, struct clk *parent) { - struct clk *old_parent; - unsigned long flags; - int ret = -EINVAL; u8 i; - old_parent = clk->parent; - if (!clk->parents) clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), GFP_KERNEL); @@ -1297,11 +1292,14 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) } } - if (i == clk->num_parents) { - pr_debug("%s: clock %s is not a possible parent of clock %s\n", - __func__, parent->name, clk->name); - goto out; - } + return i; +} + +static int __clk_set_parent(struct clk *clk, struct clk *parent, u8 p_index) +{ + unsigned long flags; + int ret; + struct clk *old_parent = clk->parent; /* migrate prepare and enable */ if (clk->prepare_count) @@ -1314,7 +1312,7 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) spin_unlock_irqrestore(&enable_lock, flags); /* change clock input source */ - ret = clk->ops->set_parent(clk->hw, i); + ret = clk->ops->set_parent(clk->hw, p_index); /* clean up old prepare and enable */ spin_lock_irqsave(&enable_lock, flags); @@ -1325,7 +1323,6 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) if (clk->prepare_count) __clk_unprepare(old_parent); -out: return ret; } @@ -1344,8 +1341,9 @@ out: int clk_set_parent(struct clk *clk, struct clk *parent) { int ret = 0; + u8 p_index; - if (!clk || !clk->ops) + if (!clk || !clk->ops || !parent) return -EINVAL; if (!clk->ops->set_parent) @@ -1357,6 +1355,21 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (clk->parent == parent) goto out; + /* check that we are allowed to re-parent if the clock is in use */ + if ((clk->flags & CLK_SET_PARENT_GATE) && clk->prepare_count) { + ret = -EBUSY; + goto out; + } + + /* try finding the new parent index */ + p_index = clk_fetch_parent_index(clk, parent); + if (p_index == clk->num_parents) { + pr_debug("%s: clock %s is not a possible parent of clock %s\n", + __func__, parent->name, clk->name); + ret = -EINVAL; + goto out; + } + /* propagate PRE_RATE_CHANGE notifications */ if (clk->notifier_count) ret = __clk_speculate_rates(clk, parent->rate); @@ -1365,11 +1378,8 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (ret == NOTIFY_STOP) goto out; - /* only re-parent if the clock is not in use */ - if ((clk->flags & CLK_SET_PARENT_GATE) && clk->prepare_count) - ret = -EBUSY; - else - ret = __clk_set_parent(clk, parent); + /* do the re-parent */ + ret = __clk_set_parent(clk, parent, p_index); /* propagate ABORT_RATE_CHANGE if .set_parent failed */ if (ret) {