From patchwork Wed Nov 16 02:06:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Tang X-Patchwork-Id: 20656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3048588wru; Tue, 15 Nov 2022 18:11:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5i1fRXqDeLI+AePpkFS1e6zoG6R8/vr3Fgm/Enfe59b/V2bBmY66RQu8c9dgzQws0DMi/n X-Received: by 2002:a17:902:a5c3:b0:188:52df:7786 with SMTP id t3-20020a170902a5c300b0018852df7786mr6841553plq.109.1668564667722; Tue, 15 Nov 2022 18:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668564667; cv=none; d=google.com; s=arc-20160816; b=ta2vEMtZW6otrlNycEFPek2/W2AH7G5m2OSHJaCrJas6538s8Rg4NoTzBVz7Gr1g7D 699O5qhMh5qKQkqC8Hj7lHoDcSuqEO6Dv21v+5O3xSSIx3EqWO/MiGAhrKeZLYUlWAmX CxPM3y4cAiqEREC+e5DB87aCUy5dSJvW3Q2dScqPwdn4Ltm6TfTE8oGaGAAla+WOk/08 TBX4tt1FJ1yXF5CIPgHxEB/RZSsQfRRzYAvnrdNFwJLYYm+kAAz+AkypsyBLFPtSz8eR XmvQ4LKVwF02N8W4GW6C0c8tXqszN/zQWKWaFbtinXW2iU2K0wPtHLLMjYe746AtRMyZ aMtg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w19-20020a170902d3d300b00176c59140c5si12721943plb.138.2022.11.15.18.10.52; Tue, 15 Nov 2022 18:11:07 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749536455467972152?= X-GMAIL-MSGID: =?utf-8?q?1749616864753108168?= 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)