Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751988AbbBQQ6b (ORCPT ); Tue, 17 Feb 2015 11:58:31 -0500 Received: from hqemgate15.nvidia.com ([216.228.121.64]:11211 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbbBQQ6a (ORCPT ); Tue, 17 Feb 2015 11:58:30 -0500 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Tue, 17 Feb 2015 08:57:46 -0800 Message-ID: <54E37335.8000305@nvidia.com> Date: Tue, 17 Feb 2015 11:58:29 -0500 From: Rhyland Klein User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Mans Rullgard , Mike Turquette , Stephen Boyd , Subject: Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init() References: <1424003629-11383-1-git-send-email-mans@mansr.com> In-Reply-To: <1424003629-11383-1-git-send-email-mans@mansr.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1734 Lines: 47 On 2/15/2015 7:33 AM, Mans Rullgard wrote: > If a mux clock is initialised (by hardware or firmware) with an > invalid parent, its ->get_parent() can return an out of range > index. For example, the generic mux clock attempts to return > -EINVAL, which due to the u8 return type ends up a rather large > number. Using this index with the parent_names[] array results > in an invalid pointer and (usually) a crash in the following > strcmp(). > > This patch adds a check for the parent index being in range, > ignoring clocks reporting invalid values. > > Signed-off-by: Mans Rullgard > Cc: Rhyland Klein > --- > drivers/clk/clk.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index d48ac71..bc0662b 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -1950,7 +1950,8 @@ int __clk_init(struct device *dev, struct clk *clk) > hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) { > if (orphan->num_parents && orphan->ops->get_parent) { > i = orphan->ops->get_parent(orphan->hw); > - if (!strcmp(clk->name, orphan->parent_names[i])) > + if (i >= 0 && i < orphan->num_parents && > + !strcmp(clk->name, orphan->parent_names[i])) > __clk_reparent(orphan, clk); > continue; > } > This works for me and is less invasive than the original patch series. Tested-by: Rhyland Klein -rhyland -- nvpublic -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/