Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp17267rwb; Tue, 15 Nov 2022 18:18:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf4aYsaeV1eg4363yVdH6qDHmds4+0t+JemW9bfWrs7StqiSOU8845DqytSR+aelZoAtbaJv X-Received: by 2002:a17:90b:3c11:b0:218:4d16:e0c7 with SMTP id pb17-20020a17090b3c1100b002184d16e0c7mr1379648pjb.105.1668565081830; Tue, 15 Nov 2022 18:18:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668565081; cv=none; d=google.com; s=arc-20160816; b=jjz0NI88+MvygY1VqRWN1P/HB4SJDl0cca3T7wyAtrsHaLWCY10RxZDVp3h+Qv8Trz iCYk4ux+i0XdjQcdhgvV8XF7cSXXuaYh7LW/uyNcSMPHM/nxFYsCLq4mA2OnorB4BUCP 6wWe9lNsyu+Bd97cBABJCer5piDUhnFcVmBJPqek8+bCt0ojX148nflrdGXlx5KwtfEG Nl1bi7luwPaU9xNsX/vb7eJ1YmKy3o8+RBH4YsVJ2AiMkP6PuP5sCC0cJOqh8Upvxmbf OtJrQ+fB//C4noDbQjFZW6iSBnZwx7UbS2REjvv57VrkLKmjPg2oaAizDeAQjBe8vOE2 BsDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=lbw1+P5CKBYCm4XhhtcxGI7kyzeX6VEt/9czon+RcX0=; b=GMZGLGLE1C6549nyYAZ1i5I3wkopvp981OL95SC70SzdrAS/tR5Yi3AWv5OeYPUsYq hr8lZPpgpO9iuZX6tZcNWeC519FbErbQpOAFG+56vRHy/siItUsooJ9y7mZGiJY5QDFz PM0U6/cmaJzfAHUBjDs+Y3u7F/piHfCpsMlirUCFDZBOVqk+/HUIL9LX8C63CrTgZ1rD naXFXyPlh2UCxekoHKJxhPg6Bf+VBGGZNebXfmYUZfZWQa3r/4PF7Ob/TUItH04QH7jY MGdeGBE8v/MjUsR7RAKBPA/ym5wZU1BaiswC+wxEQyTuFCtzlIMAhGAAegYIAtMYPbTx 5AFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a170902d2ca00b00187073496b4si31717plc.136.2022.11.15.18.17.49; Tue, 15 Nov 2022 18:18:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231678AbiKPCJu (ORCPT + 90 others); Tue, 15 Nov 2022 21:09:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbiKPCJs (ORCPT ); Tue, 15 Nov 2022 21:09:48 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9012913F; Tue, 15 Nov 2022 18:09:47 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NBmh65L1DzRpJ7; Wed, 16 Nov 2022 10:09:26 +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:09:45 +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:09:45 +0800 From: Hui Tang To: , , , , , , CC: , , Subject: [PATCH net v3] net: mvpp2: fix possible invalid pointer dereference Date: Wed, 16 Nov 2022 10:06:17 +0800 Message-ID: <20221116020617.137247-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- 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..9c3fbb153b5b 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(priv->cm3_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) -- 2.17.1