From patchwork Mon Apr 28 00:38:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 4073181 Return-Path: X-Original-To: patchwork-ltsi-dev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 23F659F319 for ; Mon, 28 Apr 2014 00:39:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3FF6720218 for ; Mon, 28 Apr 2014 00:39:22 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) by mail.kernel.org (Postfix) with ESMTP id 312AA2020E for ; Mon, 28 Apr 2014 00:39:21 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [IPv6:::1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D57CD9C3; Mon, 28 Apr 2014 00:39:05 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTP id 260AD942 for ; Mon, 28 Apr 2014 00:39:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from kirsty.vergenet.net (kirsty.vergenet.net [202.4.237.240]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 6EB06200D6 for ; Mon, 28 Apr 2014 00:39:04 +0000 (UTC) Received: from ayumi.isobedori.kobe.vergenet.net (p2182-ipbfp905kobeminato.hyogo.ocn.ne.jp [122.21.197.182]) by kirsty.vergenet.net (Postfix) with ESMTP id 2610C266CED; Mon, 28 Apr 2014 10:39:01 +1000 (EST) Received: by ayumi.isobedori.kobe.vergenet.net (Postfix, from userid 7100) id 798CCEDE6F1; Mon, 28 Apr 2014 09:38:54 +0900 (JST) From: Simon Horman To: ltsi-dev@lists.linuxfoundation.org Date: Mon, 28 Apr 2014 09:38:40 +0900 Message-Id: <1398645529-32321-3-git-send-email-horms+renesas@verge.net.au> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1398645529-32321-1-git-send-email-horms+renesas@verge.net.au> References: <1398645529-32321-1-git-send-email-horms+renesas@verge.net.au> X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org Cc: Magnus Damm Subject: [LTSI-dev] [PATCH v2 02/11] clk: shmobile: Fix MSTP clock array initialization X-BeenThere: ltsi-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "A list to discuss patches, development, and other things related to the LTSI project" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ltsi-dev-bounces@lists.linuxfoundation.org Errors-To: ltsi-dev-bounces@lists.linuxfoundation.org X-Virus-Scanned: ClamAV using ClamSMTP From: Valentine Barshak The clks member of the clk_onecell_data structure should point to a valid clk array (no NULL entries allowed), and the clk_num should be equal to the number of elements in the clks array. The MSTP driver fails to satisfy the above conditions. The clks array may contain NULL entries if not all clock-indices are initialized in the device tree. Thus, if the clock indices are interleaved we end up with NULL pointers in-between. The other problem is the driver uses maximum clock index as the number of clocks, which is incorrect (less than the actual number of clocks by 1). Fix the first issue by pre-setting the whole clks array with ERR_PTR(-ENOENT) pointers instead of zeros; and use maximum clkidx + 1 as the number of clocks to fix the other one. This should make of_clk_src_onecell_get() return the following: * valid clk pointers for all clocks registered; * ERR_PTR(-EINVAL) if (idx >= clk_data->clk_num); * ERR_PTR(-ENOENT) if the clock at the selected index was not initialized in the device tree (and was not registered). Changes in V2: * removed brackets from the one-line for loop Signed-off-by: Valentine Barshak Acked-by: Laurent Pinchart Tested-by: Ben Dooks Signed-off-by: Mike Turquette (cherry picked from commit 209f4fedcfdeeecfc9e87c045990230cc2162169) Signed-off-by: Simon Horman --- drivers/clk/shmobile/clk-mstp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/clk/shmobile/clk-mstp.c b/drivers/clk/shmobile/clk-mstp.c index e576b60..c79d13a 100644 --- a/drivers/clk/shmobile/clk-mstp.c +++ b/drivers/clk/shmobile/clk-mstp.c @@ -160,7 +160,7 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) unsigned int i; group = kzalloc(sizeof(*group), GFP_KERNEL); - clks = kzalloc(MSTP_MAX_CLOCKS * sizeof(*clks), GFP_KERNEL); + clks = kmalloc(MSTP_MAX_CLOCKS * sizeof(*clks), GFP_KERNEL); if (group == NULL || clks == NULL) { kfree(group); kfree(clks); @@ -181,6 +181,9 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) return; } + for (i = 0; i < MSTP_MAX_CLOCKS; ++i) + clks[i] = ERR_PTR(-ENOENT); + for (i = 0; i < MSTP_MAX_CLOCKS; ++i) { const char *parent_name; const char *name; @@ -208,7 +211,8 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) clks[clkidx] = cpg_mstp_clock_register(name, parent_name, i, group); if (!IS_ERR(clks[clkidx])) { - group->data.clk_num = max(group->data.clk_num, clkidx); + group->data.clk_num = max(group->data.clk_num, + clkidx + 1); /* * Register a clkdev to let board code retrieve the * clock by name and register aliases for non-DT