From patchwork Fri Jan 25 11:40:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14286 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 2A62123F02 for ; Fri, 25 Jan 2013 11:41:22 +0000 (UTC) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by fiordland.canonical.com (Postfix) with ESMTP id B901EA182BC for ; Fri, 25 Jan 2013 11:41:21 +0000 (UTC) Received: by mail-vb0-f43.google.com with SMTP id fr13so181925vbb.2 for ; Fri, 25 Jan 2013 03:41:21 -0800 (PST) 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=YOAJbB0FfOxXbQYcJ6imI1GEZhhXANqx2x5KElwx3pc=; b=mWWw4bcqjWfM7dF0fKd8EcZHbGI1Wgq2sW8OS3cMqWdWrGmGFU1OaGBJZ8/+AuLGwd TxS3imys/ZULmKanEgucHYGK2Be3HwRJMz9h0gZViPwqoFjiqgOcrNoKNL/f+VlvFP3l KYTh6w7SNKhlOAL4sat+T3rQXGYFK+5vnizbCkl+3O3GvRypFwAa4i6C3sREZlHPAAjp c17cvq1WJmyUCgvqRc8nJ9atvSkUuftdGJEXxBG5vIKSseKGtP9dsB6TKeyqsWN2t8Ys SVGCvhLr7tTpXZ2uB+i/Ctdm1UMnOT/GZK6PoVxoNoG4nychX3wUyBsl2zq7+27JMliE BCrA== X-Received: by 10.221.0.79 with SMTP id nl15mr5572172vcb.41.1359114081173; Fri, 25 Jan 2013 03:41:21 -0800 (PST) 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.145.101 with SMTP id st5csp111819veb; Fri, 25 Jan 2013 03:41:20 -0800 (PST) X-Received: by 10.180.109.10 with SMTP id ho10mr8362452wib.9.1359114080017; Fri, 25 Jan 2013 03:41:20 -0800 (PST) Received: from eu1sys200aog108.obsmtp.com (eu1sys200aog108.obsmtp.com [207.126.144.125]) by mx.google.com with SMTP id g49si1210225eep.176.2013.01.25.03.41.16 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 25 Jan 2013 03:41:20 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.125 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.125; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.125 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-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob108.postini.com ([207.126.147.11]) with SMTP ID DSNKUQJvXL9n4nAdSddzOXxGKVbpQj2aSlqf@postini.com; Fri, 25 Jan 2013 11:41:19 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4C6D4161; Fri, 25 Jan 2013 11:41:09 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id ABD97488D; Fri, 25 Jan 2013 11:41:08 +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 6C3D824C07C; Fri, 25 Jan 2013 12:41:02 +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.83.0; Fri, 25 Jan 2013 12:41:07 +0100 From: Ulf Hansson To: , Mike Turquette Cc: Linus Walleij , Philippe Begnic , Ulf Hansson Subject: [PATCH 2/3] clk: Improve errorhandling for clk_set_parent Date: Fri, 25 Jan 2013 12:40:56 +0100 Message-ID: <1359114057-11681-3-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1359114057-11681-1-git-send-email-ulf.hansson@stericsson.com> References: <1359114057-11681-1-git-send-email-ulf.hansson@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmtl0eIq092KEltIJ/TLelpG/8l0xw0VAOL20IUILNULRVSSgZZmqMjAboqCob6pWBeoEE5 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 2e10cc1..a61cf6d 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1227,15 +1227,10 @@ static void clk_reparent(struct clk *clk, struct clk *new_parent) clk->parent = new_parent; } -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); @@ -1255,11 +1250,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) @@ -1272,7 +1270,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); @@ -1283,7 +1281,6 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) if (clk->prepare_count) __clk_unprepare(old_parent); -out: return ret; } @@ -1302,8 +1299,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) @@ -1315,6 +1313,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); @@ -1323,11 +1336,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) {