From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754805AbbIOOrH (ORCPT ); Tue, 15 Sep 2015 10:47:07 -0400 Received: from unicorn.mansr.com ([81.2.72.234]:36438 "EHLO unicorn.mansr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753569AbbIOOrE convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2015 10:47:04 -0400 X-Greylist: delayed 542 seconds by postgrey-1.27 at vger.kernel.org; Tue, 15 Sep 2015 10:47:04 EDT From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Michael Turquette Cc: Rhyland Klein , "Stephen Boyd" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: check for invalid parent index of orphans in __clk_init() References: <1424003629-11383-1-git-send-email-mans@mansr.com> <54E37335.8000305@nvidia.com> <20150413191250.19585.71603@quantum> Date: Tue, 15 Sep 2015 15:37:58 +0100 In-Reply-To: <20150413191250.19585.71603@quantum> (Michael Turquette's message of "Mon, 13 Apr 2015 12:12:50 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Michael Turquette writes: > Quoting Rhyland Klein (2015-02-17 08:58:29) >> 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 > > Applied. Did this get lost somewhere? It's not in mainline, and I can't find it in the clk tree on kernel.org either. -- Måns Rullgård mans@mansr.com