From patchwork Wed Nov 16 02:14:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Tang X-Patchwork-Id: 13044349 X-Patchwork-Delegate: kuba@kernel.org 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 D0B49C433FE for ; Wed, 16 Nov 2022 02:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbiKPCR4 (ORCPT ); Tue, 15 Nov 2022 21:17:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbiKPCRv (ORCPT ); Tue, 15 Nov 2022 21:17:51 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FEA731DF4; Tue, 15 Nov 2022 18:17:50 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NBmsM0kzJz15Mgn; Wed, 16 Nov 2022 10:17:27 +0800 (CST) Received: from kwepemm600005.china.huawei.com (7.193.23.191) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 10:17:48 +0800 Received: from ubuntu1804.huawei.com (10.67.175.30) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 10:17:47 +0800 From: Hui Tang To: , , , , , , CC: , , Subject: [PATCH net v4] net: mvpp2: fix possible invalid pointer dereference Date: Wed, 16 Nov 2022 10:14:37 +0800 Message-ID: <20221116021437.145204-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221116020617.137247-1-tanghui20@huawei.com> References: <20221116020617.137247-1-tanghui20@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It will cause invalid pointer dereference to priv->cm3_base behind, if PTR_ERR(priv->cm3_base) in mvpp2_get_sram(). Fixes: a59d354208a7 ("net: mvpp2: enable global flow control") Signed-off-by: Hui Tang --- v1 -> v2: patch title include target v2 -> v3: keep priv->cm3_base NULL if devm_ioremap_resource() failed v3 -> v4: change if (priv->cm3_base) to if (base) --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index d98f7e9a480e..efb582b63640 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7349,6 +7349,7 @@ static int mvpp2_get_sram(struct platform_device *pdev, struct mvpp2 *priv) { struct resource *res; + void __iomem *base; res = platform_get_resource(pdev, IORESOURCE_MEM, 2); if (!res) { @@ -7359,9 +7360,11 @@ static int mvpp2_get_sram(struct platform_device *pdev, return 0; } - priv->cm3_base = devm_ioremap_resource(&pdev->dev, res); + base = devm_ioremap_resource(&pdev->dev, res); + if (!IS_ERR(base)) + priv->cm3_base = base; - return PTR_ERR_OR_ZERO(priv->cm3_base); + return PTR_ERR_OR_ZERO(base); } static int mvpp2_probe(struct platform_device *pdev)