From patchwork Thu Nov 17 08:40:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Tang X-Patchwork-Id: 21508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp285786wrr; Thu, 17 Nov 2022 00:48:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf7XaDoQg5sfjPyMEcg7VzsExZSXf7OfXod+Kg57mQzluIJLsR3ZFD7ra3NvrceVDNjlOcCo X-Received: by 2002:a17:906:395:b0:7a0:b505:e8fb with SMTP id b21-20020a170906039500b007a0b505e8fbmr1332916eja.281.1668674905216; Thu, 17 Nov 2022 00:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668674905; cv=none; d=google.com; s=arc-20160816; b=y+sghrEFtSbMhhMZwtYdD09Fgd+8uzfrv8M+4ujrQmpvVlx/qisOT6+cJMaprgSzO3 rx5x96KNmTscfkrBHASRQC+fQUJusRmIuFGr07gi+kAJbhylVmFQKvr3HTWqdxByMTL/ UWkjgX69LldZ8EGuzMRDO9YbfwF8rFIsY3sURxY9Zp/v0te9WRlENFxcRYAi3PO0QZSN hY0VpD3a8AEKLUgm49T+VP/Jtw3xHFC6VehfmjuZ736ziyuhZ5n8jB42EXmGc1782dZK R+TuvUq4BmlYyroAPk3o96xsG+U6VR5o4iRg85N+UuEpSdcvHAyfa7ilU5/zjPFmvaE6 Ialw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=YNE7g8TyB0SF58DfyNwwKnePSolRua1PwP49l5ag0Xc=; b=hn9zVUqgFgNoEtSrH/NiPp7Q4q+DyG+7gUEC2OnqkDoGWcXqrcJBkyLQMMQNzdakX1 pqTpg3BoJdNpVPEv7A0lnXgya1xUF/Bo6maIlofZnknyPIGfOGQlUlgKdbYmYgZMFq4q +dPkDRuy5MiOXA4yh8qxGUqcPZsKoVKO/REvD93pTrJm2CUum7KuqVRvYVgMAHHz4mJb 7ooNBozdHfbUL1v4ecV2bZOjX8kszMLLIS66uhhGCjsSCFqaH9W7hXhqSC52RKr1OL6J nRKvNuo/oWP0DO3wE+l4wycSi6LTSzmUConeZJ3I+z0lNMg+EMi2jgpJT9mHoXhV0i// m+Cg== 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 wu10-20020a170906eeca00b0072b0f6f1456si107628ejb.612.2022.11.17.00.48.01; Thu, 17 Nov 2022 00:48:25 -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 S239413AbiKQIos (ORCPT + 99 others); Thu, 17 Nov 2022 03:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239270AbiKQIoa (ORCPT ); Thu, 17 Nov 2022 03:44:30 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58B3A69DE6; Thu, 17 Nov 2022 00:43:49 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NCYN427WvzHw2L; Thu, 17 Nov 2022 16:43:16 +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; Thu, 17 Nov 2022 16:43:43 +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; Thu, 17 Nov 2022 16:43:42 +0800 From: Hui Tang To: , , , , , , CC: , , Subject: [PATCH net v5] net: mvpp2: fix possible invalid pointer dereference Date: Thu, 17 Nov 2022 16:40:32 +0800 Message-ID: <20221117084032.101144-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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?1749732457678553751?= X-GMAIL-MSGID: =?utf-8?q?1749732457678553751?= 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) v4 -> v5: use the idiomatic error handling, keep success path un-indented --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 8 ++++++-- 1 file changed, 6 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..4f3c1757620c 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,12 @@ 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)) + return PTR_ERR(base); - return PTR_ERR_OR_ZERO(priv->cm3_base); + priv->cm3_base = base; + return 0; } static int mvpp2_probe(struct platform_device *pdev)