From patchwork Sat Dec 28 12:09:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentine Barshak X-Patchwork-Id: 3413681 Return-Path: X-Original-To: patchwork-linux-sh@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 DFE7B9F491 for ; Sat, 28 Dec 2013 12:09:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B386200EC for ; Sat, 28 Dec 2013 12:09:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F0DA200DF for ; Sat, 28 Dec 2013 12:09:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755229Ab3L1MJT (ORCPT ); Sat, 28 Dec 2013 07:09:19 -0500 Received: from mail-la0-f44.google.com ([209.85.215.44]:53975 "EHLO mail-la0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755232Ab3L1MJQ (ORCPT ); Sat, 28 Dec 2013 07:09:16 -0500 Received: by mail-la0-f44.google.com with SMTP id ep20so4702296lab.17 for ; Sat, 28 Dec 2013 04:09:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Oq/YVoMx3DS//NJ3Aj7LdP/yxdYjMc8ecbsJqVN0Xak=; b=YkvWYPUDd2YEF2eg7X5sZX3Mt5Tn008t4nmMVV68+W87janJU/cHi7KQTkoJf/s5i9 +MbNulMaT7A3IuIm+26FPxURvZeSZBZVOT5bZI6HcPDNTNMxYvktrA7Ce1SRllhEGpd6 cKE7V7IboSlk485yHmMblAiP0P3cOTC91yNAwQcRmOaJNRwbrU5XIX4tr3i5AIzdTtxF JzjCShJMgT7rtyfKM4YYye/RBKWwKSsJ25L2fXke33QveyA+7qCkxqogdd6f1mhXKxyE xIK2QG0NeRa6croxZN7Sktze7yxyTgO9HKAQuwV86hDh23YYA0i1u8hjKikXHXv0+KS+ iVvQ== X-Gm-Message-State: ALoCoQmUgmeLEePNxKpAFLkGV29qCEIoN1V/WJJ7ALfOGh5W1LqEdjz+qzqTe5qN1WMwFPkMDhmd X-Received: by 10.112.133.106 with SMTP id pb10mr6556lbb.94.1388232555051; Sat, 28 Dec 2013 04:09:15 -0800 (PST) Received: from black.localnet ([93.100.122.208]) by mx.google.com with ESMTPSA id y11sm23212292lbm.13.2013.12.28.04.09.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Dec 2013 04:09:14 -0800 (PST) From: Valentine Barshak To: linux-sh@vger.kernel.org Cc: Simon Horman , Magnus Damm , Kuninori Morimoto , Laurent Pinchart , Mike Turquette Subject: [PATCH V2 2/2] clk: shmobile: Fix MSTP clock array initialization Date: Sat, 28 Dec 2013 16:09:09 +0400 Message-Id: <1388232549-6740-3-git-send-email-valentine.barshak@cogentembedded.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1388232549-6740-1-git-send-email-valentine.barshak@cogentembedded.com> References: <1388232549-6740-1-git-send-email-valentine.barshak@cogentembedded.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 be7d017..42d5912 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, clkidx, 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