From patchwork Tue Jul 19 09:21:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 72278 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp570039qga; Tue, 19 Jul 2016 02:20:31 -0700 (PDT) X-Received: by 10.66.0.74 with SMTP id 10mr63352241pac.38.1468920031509; Tue, 19 Jul 2016 02:20:31 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x76si8510825pfd.200.2016.07.19.02.20.30; Tue, 19 Jul 2016 02:20:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753309AbcGSJUV (ORCPT + 29 others); Tue, 19 Jul 2016 05:20:21 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:51149 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752669AbcGSJUO (ORCPT ); Tue, 19 Jul 2016 05:20:14 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id u6J9JqMh000550; Tue, 19 Jul 2016 18:19:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com u6J9JqMh000550 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1468919995; bh=zvfpeHAIgLCrtQ6WQSFMUL8V709GhRtd4Ed3aOjpsEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=frG1TbVB8fHEITvJ89/PXkxevOQUd/F/xdcz7ZFiICYoISRUSo3mZ9EJey0RBgXbA fiMK5RT1kFGD3NrmS3UB5yah0SY8tV1C4Kng9l177u2IRl6MQHRysLVaJ6i4Xv0Y5I CXZJSlSm9dQ+RHgyR8Kzl5VH7cvqdloM8auSiEByKHJwDvKLasWbBXgwyHFTWOJh9B WObp73OhL0M2PAS0ZyPYUDNFpIojmNptfrcEMsKNYOV9c/E0iiWstsPuizBkfySs6X y4WMt7AEcNvUvJE5he9XBRvsQqxt0UyGqeWZQMZhyHv0hP7khW3a9UgKcYKtdih3kb tpUkybxeD5MCQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-clk@vger.kernel.org Cc: Masahiro Yamada , Stephen Boyd , Michael Turquette , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] clk: fix false positive EPROBE_DEFER of __of_clk_get_hw_from_provider() Date: Tue, 19 Jul 2016 18:21:37 +0900 Message-Id: <1468920098-8553-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468920098-8553-1-git-send-email-yamada.masahiro@socionext.com> References: <1468920098-8553-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, this function iterates over the whole list of OF clock providers. If the given node is found and __of_clk_get_hw_provider() fails, it continues to search for the next node. In the end, it will reach the end of the list and return -EPROBE_DEFER. This is odd. An OF clock provider is already registered for the given node, so it is not deferred probe at all. Actually, I was hit by this case when a clock is queried with a too large index against an already registered OF clock provider. In this case, of_clk_src_onecell_get() returns -EINVAL (this is correct), but clk_get() returns -EPROBE_DEFER, so the driver is visited later, where it never succeeds in getting the clock. Another good thing is this function is much more readable now. Signed-off-by: Masahiro Yamada --- drivers/clk/clk.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) -- 1.9.1 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 60daf60..2207098 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3156,25 +3156,19 @@ struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec, { struct of_clk_provider *provider; struct clk *clk = ERR_PTR(-EPROBE_DEFER); - struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); + struct clk_hw *hw; if (!clkspec) return ERR_PTR(-EINVAL); - /* Check if we have such a provider in our array */ mutex_lock(&of_clk_mutex); - list_for_each_entry(provider, &of_clk_providers, link) { - if (provider->node == clkspec->np) - hw = __of_clk_get_hw_from_provider(provider, clkspec); - if (!IS_ERR(hw)) { - clk = __clk_create_clk(hw, dev_id, con_id); - - if (!IS_ERR(clk) && !__clk_get(clk)) { - __clk_free_clk(clk); - clk = ERR_PTR(-ENOENT); - } - - break; + provider = __of_clk_find_provider(clkspec->np); + if (provider) { + hw = __of_clk_get_hw_from_provider(provider, clkspec); + clk = __clk_create_clk(hw, dev_id, con_id); + if (!IS_ERR(clk) && !__clk_get(clk)) { + __clk_free_clk(clk); + clk = ERR_PTR(-ENOENT); } } mutex_unlock(&of_clk_mutex);