From patchwork Mon Nov 20 19:12:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10067063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0762D6038F for ; Mon, 20 Nov 2017 19:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC0D029334 for ; Mon, 20 Nov 2017 19:12:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0CC629343; Mon, 20 Nov 2017 19:12:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 974D829334 for ; Mon, 20 Nov 2017 19:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752304AbdKTTM3 (ORCPT ); Mon, 20 Nov 2017 14:12:29 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:34324 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752298AbdKTTM2 (ORCPT ); Mon, 20 Nov 2017 14:12:28 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id C7E846080C; Mon, 20 Nov 2017 19:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511205147; bh=YG5J+r2D0NZ0/xw4o/QrhGionQzlqO6mWxeFgK3+uRs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fahuVJmTp4KRc1bg9q/LTf6f/7WyAbrRXVubdUEBIz+9XS6KTDtOqoXEOBnuS1q26 9vncEtxqTqUepovMkK/cBCyvb5Qic9+v/OY66yC0rHDDeBYEsJPqXwQS+RVyojegRl v8n/4gE7O98o3Ll/89ahasGnOFm8Od//5TP5aoto= Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2ECCA607E8; Mon, 20 Nov 2017 19:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511205140; bh=YG5J+r2D0NZ0/xw4o/QrhGionQzlqO6mWxeFgK3+uRs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kUxQ61QQxjKu4s5kXcLuL3vnUA53mHCkVk+GPn4bOUPN3ypUB1W1UzvjUP++QcvQi yL6lttStesUUOa+wAUX8A3RKVistIx0PUqVnjWE8eUyc7kR0wX+gaH7NjgewWLUoIz usefb9x4Oz4GQ5tYyZwzRqNuS2bWbts2Xzn3ld8k= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2ECCA607E8 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sboyd@codeaurora.org Date: Mon, 20 Nov 2017 11:12:19 -0800 From: Stephen Boyd To: Chunyan Zhang Cc: Michael Turquette , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Cai Li , Orson Zhai , Chunyan Zhang Subject: Re: [PATCH] clk: fix a panic error caused by accessing NULL pointer Message-ID: <20171120191219.GD18379@codeaurora.org> References: <20171120033816.28414-1-chunyan.zhang@spreadtrum.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171120033816.28414-1-chunyan.zhang@spreadtrum.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 11/20, Chunyan Zhang wrote: > From: Cai Li > > In some cases the clock parent would be set NULL when doing re-parent, > it will cause a NULL pointer accessing if clk_set trace event is enabled, > since the trace event function would not check the input parameter. > > Signed-off-by: Cai Li > Signed-off-by: Chunyan Zhang Fixes: tag? > --- > drivers/clk/clk.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index c8d83ac..64efaf0 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -1242,13 +1242,12 @@ static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, > > old_parent = __clk_set_parent_before(core, parent); > > - trace_clk_set_parent(core, parent); > - > /* change clock input source */ > - if (parent && core->ops->set_parent) > + if (parent && core->ops->set_parent) { > + trace_clk_set_parent(core, parent); > ret = core->ops->set_parent(core->hw, p_index); > - > - trace_clk_set_parent_complete(core, parent); > + trace_clk_set_parent_complete(core, parent); > + } Is the problem that parent may be NULL and the tracepoint dereferences it? Perhaps we need to update the tracepoint code instead so that we always see that the tracepoint is called even if we don't actually touch the hardware. Something like the patch below instead. ---8<---- diff --git a/include/trace/events/clk.h b/include/trace/events/clk.h index 758607226bfd..5a85ea2090c4 100644 --- a/include/trace/events/clk.h +++ b/include/trace/events/clk.h @@ -139,7 +139,7 @@ DECLARE_EVENT_CLASS(clk_parent, TP_fast_assign( __assign_str(name, core->name); - __assign_str(pname, parent->name); + __assign_str(pname, parent ? parent->name : NULL); ), TP_printk("%s %s", __get_str(name), __get_str(pname))