From nobody Sun May 10 19:52:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29B29C433F5 for ; Tue, 26 Apr 2022 02:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240259AbiDZDAI (ORCPT ); Mon, 25 Apr 2022 23:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbiDZDAE (ORCPT ); Mon, 25 Apr 2022 23:00:04 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F36E3B017 for ; Mon, 25 Apr 2022 19:56:58 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KnRNr12hFzhYhx; Tue, 26 Apr 2022 10:56:44 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 26 Apr 2022 10:56:56 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 26 Apr 2022 10:56:55 +0800 From: Yang Yingliang To: CC: , , Subject: [PATCH] mfd: davinci_voicecodec: fix possible null-ptr-deref davinci_vc_probe() Date: Tue, 26 Apr 2022 11:08:57 +0800 Message-ID: <20220426030857.3539336-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It will cause null-ptr-deref when using 'res', if platform_get_resource() returns NULL, so move using 'res' after devm_ioremap_resource() that will check it to avoid null-ptr-deref. And use devm_platform_get_and_ioremap_resource() to simplify code. Fixes: b5e29aa880be ("mfd: davinci_voicecodec: Remove pointless #include") Signed-off-by: Yang Yingliang --- drivers/mfd/davinci_voicecodec.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/mfd/davinci_voicecodec.c b/drivers/mfd/davinci_voiceco= dec.c index e5c8bc998eb4..965820481f1e 100644 --- a/drivers/mfd/davinci_voicecodec.c +++ b/drivers/mfd/davinci_voicecodec.c @@ -46,14 +46,12 @@ static int __init davinci_vc_probe(struct platform_devi= ce *pdev) } clk_enable(davinci_vc->clk); =20 - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - - fifo_base =3D (dma_addr_t)res->start; - davinci_vc->base =3D devm_ioremap_resource(&pdev->dev, res); + davinci_vc->base =3D devm_platform_get_and_ioremap_resource(pdev, 0, &res= ); if (IS_ERR(davinci_vc->base)) { ret =3D PTR_ERR(davinci_vc->base); goto fail; } + fifo_base =3D (dma_addr_t)res->start; =20 davinci_vc->regmap =3D devm_regmap_init_mmio(&pdev->dev, davinci_vc->base, --=20 2.25.1