From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB0FBC2BB1D for ; Thu, 12 Mar 2020 23:13:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4EB020716 for ; Thu, 12 Mar 2020 23:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584054838; bh=KdJ376DrupqSBe4hSilpFPULBV8+maazUojKqMfa2Hs=; h=In-Reply-To:References:Subject:From:Cc:To:Date:List-ID:From; b=GLN8eLkjdBE9lM2lqT3V8VhLCn/y+nrz8cNKR5sw1yetGHzbz3ce02WxNxX26NV9G 1un/MnIj2RSZI8yuru0Eu0l1WCvcxDZFwK41LHQLnlplwdmKCFdnvFa1FO2zlXFLaY 7AvzXJYQbNF7lKE3Tk6s0wP/fzQ6znuD4SDGfzlU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726834AbgCLXN6 (ORCPT ); Thu, 12 Mar 2020 19:13:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:59326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbgCLXN5 (ORCPT ); Thu, 12 Mar 2020 19:13:57 -0400 Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC2D3206F7; Thu, 12 Mar 2020 23:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584054837; bh=KdJ376DrupqSBe4hSilpFPULBV8+maazUojKqMfa2Hs=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=OPQZ9/crlt1D8ScrMECNiBOu3Ewxf1OnMJkB6zbrAZUkT4KA0/XSQZ7E+XiLRoIfV CtME35UK548pS59QOb5MmyuPCYA7AxrPTGjW6qQ6ZPj2wTNFRaQY4DFbg0bNE2EKMr AGmSq5wEHbayZYhgGVSng7s7xs0zFYDuiL3S8eZI= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: Subject: Re: [PATCH 05/89] clk: Return error code when of provider pointer is NULL From: Stephen Boyd Cc: dri-devel@lists.freedesktop.org, linux-rpi-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Stevenson , Tim Gover , Phil Elwell , Maxime Ripard , Michael Turquette , linux-clk@vger.kernel.org To: Eric Anholt , Maxime Ripard , Nicolas Saenz Julienne Date: Thu, 12 Mar 2020 16:13:56 -0700 Message-ID: <158405483605.149997.16173757299414738003@swboyd.mtv.corp.google.com> User-Agent: alot/0.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Maxime Ripard (2020-02-24 01:06:07) > The clock framework DT provider helpers don't check the pointers in the > array registered by the clock provider before returning it. >=20 > This means that if the array is sparse, we will end up returning a NULL > pointer while the caller expects an error pointer, resulting in a crash. >=20 > Let's test the pointer returned and properly return an error if the point= er > is NULL. >=20 > Cc: Michael Turquette > Cc: Stephen Boyd > Cc: linux-clk@vger.kernel.org > Signed-off-by: Maxime Ripard > --- > drivers/clk/clk.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index f0f2b599fd7e..8532b5ed1060 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -4318,13 +4318,18 @@ struct clk *of_clk_src_onecell_get(struct of_phan= dle_args *clkspec, void *data) > { > struct clk_onecell_data *clk_data =3D data; > unsigned int idx =3D clkspec->args[0]; > + struct clk *clk; > =20 > if (idx >=3D clk_data->clk_num) { > pr_err("%s: invalid clock index %u\n", __func__, idx); > return ERR_PTR(-EINVAL); > } > =20 > - return clk_data->clks[idx]; > + clk =3D clk_data->clks[idx]; > + if (!clk) NULL is a valid clk. That should keep working and not be overriden with an error pointer. If you want to return an error pointer either fill it in with an error pointer or write your own version of this. > + return ERR_PTR(-ENODEV); > + > + return clk; > } > EXPORT_SYMBOL_GPL(of_clk_src_onecell_get); > =20 > @@ -4333,13 +4338,18 @@ of_clk_hw_onecell_get(struct of_phandle_args *clk= spec, void *data) > { > struct clk_hw_onecell_data *hw_data =3D data; > unsigned int idx =3D clkspec->args[0]; > + struct clk_hw *hw; > =20 > if (idx >=3D hw_data->num) { > pr_err("%s: invalid index %u\n", __func__, idx); > return ERR_PTR(-EINVAL); > } > =20 > - return hw_data->hws[idx]; > + hw =3D hw_data->hws[idx]; > + if (!hw) And this one is the same. We let NULL be returned so that it can be returned as a NULL pointer to the caller if desired. That indicates a clk that does nothing when used. > + return ERR_PTR(-ENODEV); > + > + return hw; > } > EXPORT_SYMBOL_GPL(of_clk_hw_onecell_get); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79F8EC10DCE for ; Thu, 12 Mar 2020 23:14:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50AA8206F7 for ; Thu, 12 Mar 2020 23:14:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NGGpJn6N"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="OPQZ9/cr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50AA8206F7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Message-ID:Date:To:From:Subject: References:In-Reply-To:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VmFiNPvPA+Q10uwEeYcBosEwmp/9710dPQx7h9r2LQg=; b=NGGpJn6NXTCw4u 2IIz0ICe4XMsObIzqL3NVYo2p9/aIfYu7SIO8B7xxFEFdeWNMMW7FoqdBl0voTrs+fqk1v4twHevq 5jjuol5nUSdFJ4Ei6KQD4kvYmJc9dgCnlob+UNRa1rnjoJzbz/r0BVT+RvmXeNyh+H024efc9ijkG 6/yym7KWlShQEB3QccQZ/NYRsce2r1HzZRbvipQ1jdXwhYcD8/1emSpBvBjdygpDXjI0Ym9WTHZvk OyYKUv77QWQz+hirAfJK2tazuK/MhnwtNeHw6qGiqZ11YQNtaiTjlb7zCuMVDbC8sCh2EVLbOuJMF EUnHnoffbOh1rxQXfRpA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCX1e-0007Ar-MR; Thu, 12 Mar 2020 23:14:02 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCX1b-0007AB-OU; Thu, 12 Mar 2020 23:14:01 +0000 Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC2D3206F7; Thu, 12 Mar 2020 23:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584054837; bh=KdJ376DrupqSBe4hSilpFPULBV8+maazUojKqMfa2Hs=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=OPQZ9/crlt1D8ScrMECNiBOu3Ewxf1OnMJkB6zbrAZUkT4KA0/XSQZ7E+XiLRoIfV CtME35UK548pS59QOb5MmyuPCYA7AxrPTGjW6qQ6ZPj2wTNFRaQY4DFbg0bNE2EKMr AGmSq5wEHbayZYhgGVSng7s7xs0zFYDuiL3S8eZI= MIME-Version: 1.0 In-Reply-To: References: Subject: Re: [PATCH 05/89] clk: Return error code when of provider pointer is NULL From: Stephen Boyd To: Eric Anholt , Maxime Ripard , Nicolas Saenz Julienne Date: Thu, 12 Mar 2020 16:13:56 -0700 Message-ID: <158405483605.149997.16173757299414738003@swboyd.mtv.corp.google.com> User-Agent: alot/0.9 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200312_161359_840268_9E2C1C95 X-CRM114-Status: GOOD ( 18.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Gover , Dave Stevenson , Michael Turquette , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-clk@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, Phil Elwell , linux-arm-kernel@lists.infradead.org, Maxime Ripard Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Quoting Maxime Ripard (2020-02-24 01:06:07) > The clock framework DT provider helpers don't check the pointers in the > array registered by the clock provider before returning it. > > This means that if the array is sparse, we will end up returning a NULL > pointer while the caller expects an error pointer, resulting in a crash. > > Let's test the pointer returned and properly return an error if the pointer > is NULL. > > Cc: Michael Turquette > Cc: Stephen Boyd > Cc: linux-clk@vger.kernel.org > Signed-off-by: Maxime Ripard > --- > drivers/clk/clk.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index f0f2b599fd7e..8532b5ed1060 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -4318,13 +4318,18 @@ struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) > { > struct clk_onecell_data *clk_data = data; > unsigned int idx = clkspec->args[0]; > + struct clk *clk; > > if (idx >= clk_data->clk_num) { > pr_err("%s: invalid clock index %u\n", __func__, idx); > return ERR_PTR(-EINVAL); > } > > - return clk_data->clks[idx]; > + clk = clk_data->clks[idx]; > + if (!clk) NULL is a valid clk. That should keep working and not be overriden with an error pointer. If you want to return an error pointer either fill it in with an error pointer or write your own version of this. > + return ERR_PTR(-ENODEV); > + > + return clk; > } > EXPORT_SYMBOL_GPL(of_clk_src_onecell_get); > > @@ -4333,13 +4338,18 @@ of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data) > { > struct clk_hw_onecell_data *hw_data = data; > unsigned int idx = clkspec->args[0]; > + struct clk_hw *hw; > > if (idx >= hw_data->num) { > pr_err("%s: invalid index %u\n", __func__, idx); > return ERR_PTR(-EINVAL); > } > > - return hw_data->hws[idx]; > + hw = hw_data->hws[idx]; > + if (!hw) And this one is the same. We let NULL be returned so that it can be returned as a NULL pointer to the caller if desired. That indicates a clk that does nothing when used. > + return ERR_PTR(-ENODEV); > + > + return hw; > } > EXPORT_SYMBOL_GPL(of_clk_hw_onecell_get); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B801C4CECE for ; Thu, 12 Mar 2020 23:14:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D90E720716 for ; Thu, 12 Mar 2020 23:13:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="OPQZ9/cr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D90E720716 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E9DF36EB54; Thu, 12 Mar 2020 23:13:58 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3D1FE6EB54 for ; Thu, 12 Mar 2020 23:13:57 +0000 (UTC) Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC2D3206F7; Thu, 12 Mar 2020 23:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584054837; bh=KdJ376DrupqSBe4hSilpFPULBV8+maazUojKqMfa2Hs=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=OPQZ9/crlt1D8ScrMECNiBOu3Ewxf1OnMJkB6zbrAZUkT4KA0/XSQZ7E+XiLRoIfV CtME35UK548pS59QOb5MmyuPCYA7AxrPTGjW6qQ6ZPj2wTNFRaQY4DFbg0bNE2EKMr AGmSq5wEHbayZYhgGVSng7s7xs0zFYDuiL3S8eZI= MIME-Version: 1.0 In-Reply-To: References: Subject: Re: [PATCH 05/89] clk: Return error code when of provider pointer is NULL From: Stephen Boyd To: Eric Anholt , Maxime Ripard , Nicolas Saenz Julienne Date: Thu, 12 Mar 2020 16:13:56 -0700 Message-ID: <158405483605.149997.16173757299414738003@swboyd.mtv.corp.google.com> User-Agent: alot/0.9 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Gover , Dave Stevenson , Michael Turquette , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-clk@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, Phil Elwell , linux-arm-kernel@lists.infradead.org, Maxime Ripard Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Quoting Maxime Ripard (2020-02-24 01:06:07) > The clock framework DT provider helpers don't check the pointers in the > array registered by the clock provider before returning it. > > This means that if the array is sparse, we will end up returning a NULL > pointer while the caller expects an error pointer, resulting in a crash. > > Let's test the pointer returned and properly return an error if the pointer > is NULL. > > Cc: Michael Turquette > Cc: Stephen Boyd > Cc: linux-clk@vger.kernel.org > Signed-off-by: Maxime Ripard > --- > drivers/clk/clk.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index f0f2b599fd7e..8532b5ed1060 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -4318,13 +4318,18 @@ struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) > { > struct clk_onecell_data *clk_data = data; > unsigned int idx = clkspec->args[0]; > + struct clk *clk; > > if (idx >= clk_data->clk_num) { > pr_err("%s: invalid clock index %u\n", __func__, idx); > return ERR_PTR(-EINVAL); > } > > - return clk_data->clks[idx]; > + clk = clk_data->clks[idx]; > + if (!clk) NULL is a valid clk. That should keep working and not be overriden with an error pointer. If you want to return an error pointer either fill it in with an error pointer or write your own version of this. > + return ERR_PTR(-ENODEV); > + > + return clk; > } > EXPORT_SYMBOL_GPL(of_clk_src_onecell_get); > > @@ -4333,13 +4338,18 @@ of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data) > { > struct clk_hw_onecell_data *hw_data = data; > unsigned int idx = clkspec->args[0]; > + struct clk_hw *hw; > > if (idx >= hw_data->num) { > pr_err("%s: invalid index %u\n", __func__, idx); > return ERR_PTR(-EINVAL); > } > > - return hw_data->hws[idx]; > + hw = hw_data->hws[idx]; > + if (!hw) And this one is the same. We let NULL be returned so that it can be returned as a NULL pointer to the caller if desired. That indicates a clk that does nothing when used. > + return ERR_PTR(-ENODEV); > + > + return hw; > } > EXPORT_SYMBOL_GPL(of_clk_hw_onecell_get); _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel