From patchwork Thu Sep 5 13:33:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2854138 Return-Path: X-Original-To: patchwork-linux-arm@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 40DB79F557 for ; Thu, 5 Sep 2013 13:34:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C0B9204A2 for ; Thu, 5 Sep 2013 13:34:17 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CEA8D20454 for ; Thu, 5 Sep 2013 13:34:15 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VHZh8-0004Xn-Df; Thu, 05 Sep 2013 13:33:58 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VHZh0-0002AO-Sy; Thu, 05 Sep 2013 13:33:50 +0000 Received: from mail-ob0-f171.google.com ([209.85.214.171]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VHZgv-00028Q-Lg for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2013 13:33:46 +0000 Received: by mail-ob0-f171.google.com with SMTP id tb18so1982861obb.30 for ; Thu, 05 Sep 2013 06:33:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding; bh=Hk0rhMNOQbDF0IupzhDImdfgrL/Dw1PTzE2y0ib62FI=; b=U3qWkEOR9d30I8S8vulonSKf1x4QT3yqGXhIFzfdsRb4OnqtH/b01unT9CGp5A4Suf ZYu/MWezkYFMMuI3GXK5WEwyY6u1yPWUazRN+XexY7O6gwVyPllS4aqaGDi4muDRtVGm C/drxEOYg4rM/uAtMRNbnwcKoJ8JhpfG09DQiKPNhECAq3tLxk2n5vxsNEOjQ+QRWbns HYAao5wt7wNogGzCsUIlaujnvwaKlsVJ1AWQ+Me5spnShYH/q3nCvG0IcU2nxkc6Pid/ XZaHMB8BPv91JINVFV3iPcv5ixNyvcKoqk54murp35HEGhZN7x6yod0OGJUgrVtCoBh0 Y3ZA== X-Gm-Message-State: ALoCoQnlGEMBFAmGGIXtaSbcipXSdR7RaV9+an3m+86NhAAmb65L1k5AdfBe6zgeOuQU+SeU+Dtk X-Received: by 10.60.42.3 with SMTP id j3mr653893oel.70.1378388004329; Thu, 05 Sep 2013 06:33:24 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id bq4sm29448281obb.1.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Sep 2013 06:33:23 -0700 (PDT) Message-ID: <52288824.1060905@linaro.org> Date: Thu, 05 Sep 2013 08:33:24 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8 MIME-Version: 1.0 To: Mike Turquette Subject: [PATCH] clk: only call get_parent if there is one X-Enigmail-Version: 1.4.6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130905_093345_778169_E6877D15 X-CRM114-Status: GOOD ( 12.51 ) X-Spam-Score: -2.6 (--) Cc: LKML , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.6 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 X-Virus-Scanned: ClamAV using ClamSMTP In __clk_init(), after a clock is mostly initialized, a scan is done of the orphan clocks to see if the clock being registered is the parent of any of them. This code assumes that any clock that provides a get_parent method actually has at least one parent, and that's not a valid assumption. As a result, an orphan clock with no parent can return *something* as the parent index, and that value is blindly used to dereference the orphan's parent_names[] array (which will be ZERO_SIZE_PTR or NULL). Fix this by ensuring get_parent is only called for orphans with at least one parent. Signed-off-by: Alex Elder --- drivers/clk/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 54a191c..ea8ff15 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1628,7 +1628,7 @@ int __clk_init(struct device *dev, struct clk *clk) * this clock */ hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) { - if (orphan->ops->get_parent) { + if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent(orphan->hw); if (!strcmp(clk->name, orphan->parent_names[i])) __clk_reparent(orphan, clk);