From patchwork Thu Nov 24 01:56:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ziyang Xuan X-Patchwork-Id: 25285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3140699wrr; Wed, 23 Nov 2022 18:03:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6JVv2zEbwTwGlnlSqDc9fd6mHGdlEXxbHPGM3bC14s/6osOMG31p80MztuMotLaAOHgugb X-Received: by 2002:a17:906:e0d7:b0:7b9:a74b:f16a with SMTP id gl23-20020a170906e0d700b007b9a74bf16amr5130710ejb.192.1669255383213; Wed, 23 Nov 2022 18:03:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669255383; cv=none; d=google.com; s=arc-20160816; b=iXiau/W0qfTE8sH3w0Sm68b4IRIgyadZ/p+wvxlIeUaUr8WjkvylL+uF3CDT3h85RO kWGDkr6wclKG6VQN4/g2d919WqcEvtqJWd/un3kLdL1B056atlVgfu5Hyju3L6hghYLD I5UFSph/qPwdzntHP3+HeP1uhzouXoDHFioszuDOEbhUW7qRTULelH7kS2CjkE0nf7Az njJJR6XeP6mcGyHSJLK9RBj0amDvcxrDwTWQv4MS/fpTdaWVwrlX6BAKLrMQGdaXRMUT YUJGf1xWu8SNQmB4JmjqA7WJTicB9mnyPcs4twMKQr5mJPPE3OqPV86a6WmPxwYgPj5S 9FQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0EdSWlINfoNEmHAxSq6iJlr8oUiB/cJI+8g/dxrJqhs=; b=ZHu8/DIkACKvIpZ7MjldmVHTGsLRtqgJr0jxp42I+/lBI5yJHV062iqsOG1ZCojhdq a8VNHzwfEKYmjmRh8cNp/WuglmVSi1SF981u8OM+kt5rV0LFYQxwuFI0kvWJaykVAD5r OPBduRrVeJrtuLc1TAH9aff8l8NAuVY18fIy5JzoimZsbvHg9fpVtD+BULQXTpI6Esbb u62Z/gUYoem69Y4L7W+pe9IU3AB0L/PUVfs6XJfOcKGBSdkiXYhN+kdamVphz3PtvxnB QbZpLnKkR63LtzupsaDrUNncXRbaWkaTPJwr6P+/8QP6mtfqxRm+xEuRTqH+mslASTIM IThQ== 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 fj4-20020a1709069c8400b00797e151e584si188392ejc.605.2022.11.23.18.02.34; Wed, 23 Nov 2022 18:03:03 -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 S229631AbiKXB4y (ORCPT + 99 others); Wed, 23 Nov 2022 20:56:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229644AbiKXB4u (ORCPT ); Wed, 23 Nov 2022 20:56:50 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405AF74AB5; Wed, 23 Nov 2022 17:56:49 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NHh161wlRzHw47; Thu, 24 Nov 2022 09:56:10 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 24 Nov 2022 09:56:46 +0800 From: Ziyang Xuan To: , , , , , , , , CC: , , Subject: [PATCH net 1/2] octeontx2-pf: Fix possible memory leak in otx2_probe() Date: Thu, 24 Nov 2022 09:56:43 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500006.china.huawei.com (7.192.105.130) 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?1750341132621303066?= X-GMAIL-MSGID: =?utf-8?q?1750341132621303066?= In otx2_probe(), there are several possible memory leak bugs in exception paths as follows: 1. Do not release pf->otx2_wq when excute otx2_init_tc() failed. 2. Do not shutdown tc when excute otx2_register_dl() failed. 3. Do not unregister devlink when initialize SR-IOV failed. Fixes: 1d4d9e42c240 ("octeontx2-pf: Add tc flower hardware offload on ingress traffic") Fixes: 2da489432747 ("octeontx2-pf: devlink params support to set mcam entry count") Signed-off-by: Ziyang Xuan --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c index 303930499a4c..8d7f2c3b0cfd 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -2900,7 +2900,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = otx2_register_dl(pf); if (err) - goto err_mcam_flow_del; + goto err_register_dl; /* Initialize SR-IOV resources */ err = otx2_sriov_vfcfg_init(pf); @@ -2919,8 +2919,11 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) return 0; err_pf_sriov_init: + otx2_unregister_dl(pf); +err_register_dl: otx2_shutdown_tc(pf); err_mcam_flow_del: + destroy_workqueue(pf->otx2_wq); otx2_mcam_flow_del(pf); err_unreg_netdev: unregister_netdev(netdev); From patchwork Thu Nov 24 01:56:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ziyang Xuan X-Patchwork-Id: 25286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3141308wrr; Wed, 23 Nov 2022 18:04:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf71zzuUd8R0aPML4BoY3xGhEmmEj97jf7+fwzJisLMpWVgUQtU/SJsSVEwaXcZ7ciQLadkS X-Received: by 2002:a05:6402:68c:b0:461:b506:6b8a with SMTP id f12-20020a056402068c00b00461b5066b8amr27954986edy.208.1669255478447; Wed, 23 Nov 2022 18:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669255478; cv=none; d=google.com; s=arc-20160816; b=TdIFyZQT6j67LetDDi+xdejaNE3WsDQMjdlT0O7IoTLwqoBbzWb143rFf1VmlevWQm PViThIj/poMoU7pM8ZVdjWPiBi6F3B0yiPQ+5fC+/ty/4c4C/rlxN140EKl2l3HD7h+9 UHzRIxY+9CGijUaqw8WVDbsTKTpiCb1OBaQgf3OsJgyhiiYlGT9m0eKoUNGI7DiY+2hW RudzR4kiHed1IUhFzsiXoLFxpbqAw15R8w+9SniXjJ6IAV7V3ABzZ+TkJLs9Xke7UCKR T0kRoYvShW3vCJVJOeen6bSiIFhotMZlgPU3dQxogbBKGqbNWdpNGd/5vc3PFdB7cWGj iErA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=i3F8OEs9KitVlYra7nstmePww1FPq0pS39F4RzrBW84=; b=miOvKI8Ja0doHJd87dGVjrq9VLWImfOcN7vBI2R9XV+w/O/2oY6j3hsvznQGVtkrQz geSU2tPyqX2kmO5V9nOCq5KfTAP/KCMRUt1EPJHUlq2EtxIcoYqrU880A2Td8OpUUT42 c1EN2S6AjhhvMxIImlbeC7WGP3hXt7y84KDn5f7yeBYwSpqGR7qju+kZuq49wur1/1C3 tR7Dx63QAZ1dfWL6A0KEYoj46NqVQbjokbLzqOXdNjtPxLwQTiB8z2I4e3EBphURElnK Si8XAKKTuExJwbz5ygpf8vYX9C7BI5j+MNd2npGo6dGdE403ceQAJB3noUGF8zH2flPG 3Jfg== 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 be1-20020a1709070a4100b0078d85777c4fsi4741433ejc.700.2022.11.23.18.04.14; Wed, 23 Nov 2022 18:04:38 -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 S229676AbiKXB5G (ORCPT + 99 others); Wed, 23 Nov 2022 20:57:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbiKXB5D (ORCPT ); Wed, 23 Nov 2022 20:57:03 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F00E0743; Wed, 23 Nov 2022 17:57:02 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NHh1M6rGhzHw5L; Thu, 24 Nov 2022 09:56:23 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 24 Nov 2022 09:57:00 +0800 From: Ziyang Xuan To: , , , , , , , , CC: , , Subject: [PATCH net 2/2] octeontx2-vf: Fix possible memory leak in otx2vf_probe() Date: Thu, 24 Nov 2022 09:56:56 +0800 Message-ID: <3828ba413173643c0e04d33f09754eec03c43cfc.1669253985.git.william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500006.china.huawei.com (7.192.105.130) 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?1750341232873748117?= X-GMAIL-MSGID: =?utf-8?q?1750341232873748117?= In otx2vf_probe(), there are several possible memory leak bugs in exception paths as follows: 1. Do not release vf->otx2_wq when excute otx2vf_mcam_flow_init() and otx2_init_tc() failed. 2. Do not unregister devlink when excute otx2_dcbnl_set_ops() failed. Fixes: 4b0385bc8e6a ("octeontx2-pf: Add TC feature for VFs") Fixes: 8e67558177f8 ("octeontx2-pf: PFC config support with DCBx") Fixes: 3cffaed2136c ("octeontx2-pf: Ntuple filters support for VF netdev") Signed-off-by: Ziyang Xuan --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c index 86653bb8e403..f1b47fecd379 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c @@ -684,11 +684,11 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = otx2vf_mcam_flow_init(vf); if (err) - goto err_unreg_netdev; + goto err_destroy_wq; err = otx2_init_tc(vf); if (err) - goto err_unreg_netdev; + goto err_destroy_wq; err = otx2_register_dl(vf); if (err) @@ -697,13 +697,19 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) #ifdef CONFIG_DCB err = otx2_dcbnl_set_ops(netdev); if (err) - goto err_shutdown_tc; + goto err_unreg_dl; #endif return 0; +#ifdef CONFIG_DCB +err_unreg_dl: + otx2_unregister_dl(vf); +#endif err_shutdown_tc: otx2_shutdown_tc(vf); +err_destroy_wq: + destroy_workqueue(vf->otx2_wq); err_unreg_netdev: unregister_netdev(netdev); err_ptp_destroy: