Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755846AbbBLNgD (ORCPT ); Thu, 12 Feb 2015 08:36:03 -0500 Received: from bhuna.collabora.co.uk ([93.93.135.160]:48758 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755182AbbBLNgC (ORCPT ); Thu, 12 Feb 2015 08:36:02 -0500 Message-ID: <54DCAC3B.8080309@collabora.co.uk> Date: Thu, 12 Feb 2015 14:35:55 +0100 From: Javier Martinez Canillas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.2.0 MIME-Version: 1.0 To: Stephen Boyd CC: Mike Turquette , Tomeu Vizoso , Emilio L??pez , linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] clk: Don't dereference parent clock if is NULL References: <1423649612-31746-1-git-send-email-javier.martinez@collabora.co.uk> <1423649612-31746-2-git-send-email-javier.martinez@collabora.co.uk> <20150211185435.GD11190@codeaurora.org> In-Reply-To: <20150211185435.GD11190@codeaurora.org> 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: 1985 Lines: 52 Hello Stephen, Thanks a lot for your feedback. On 02/11/2015 07:54 PM, Stephen Boyd wrote: > On 02/11, Javier Martinez Canillas wrote: >> --- a/drivers/clk/clk.c >> +++ b/drivers/clk/clk.c >> @@ -799,7 +799,7 @@ clk_mux_determine_rate_flags(struct clk_hw *hw, unsigned long rate, >> /* if NO_REPARENT flag set, pass through to current parent */ >> if (core->flags & CLK_SET_RATE_NO_REPARENT) { >> parent = core->parent; >> - if (core->flags & CLK_SET_RATE_PARENT) >> + if (core->flags & CLK_SET_RATE_PARENT && parent) >> best = __clk_determine_rate(parent->hw, rate, >> min_rate, max_rate); >> else if (parent) > > Sorry this doesn't look right. Before all the recent changes to > this file we would call __clk_round_rate() which would return 0 > if the first argument was NULL. Now we're going to take the else > if path and do something different. So we need a parent ? > parent->hw : NULL here. > Right, I'm not that familiar with the common clock framework so I didn't realize I was changing the behavior, sorry about that... > Of course, I wonder why a clock has the CLK_SET_RATE_PARENT flag > set if it doesn't actually have a parent. That also seems wrong. > Yes, I did not face this issue and only patch #2 was enough to fix my problem but the theoretical NULL pointer dereference was found when reading the code. I agree that a clock with that flag set should have at least one parent but afaict there is no sanity check on clock registration. And even if that was the case, I believe that the core should be robust enough to check for NULL before trying to dereference it. I'll post a v2 passing NULL as an argument and parent->hw if parent is not NULL as you suggested. Best regards, Javier -- 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/