Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp943506imm; Tue, 15 May 2018 11:25:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqoHXMqxQx27LZQTr7a2gvZzxCY92CO80JSAAJvKNaCj6UvVbiH04i5M4Zfwne+W/I+AnMv X-Received: by 2002:a17:902:8f93:: with SMTP id z19-v6mr15220703plo.166.1526408710910; Tue, 15 May 2018 11:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526408710; cv=none; d=google.com; s=arc-20160816; b=XGK7TJIm0wAUB2GR+aoDg0FsqzMBJjr1htO/R6FEXrjP61LmoDMia67Nn89WOF74Xd 5k1Ys+kwWrhjwFvDBEGDq7HjsKRcjPGRqqY0fuQgt7zTeiMZFg+o5C1WBOeogp+RLv4+ tr8LlDfVJnmkL+EajHGhBD6NIpu24YC3z42Tca8+8qRH7qgOFkTMTruKcEPVG5kCv+Tv g21L8afdrt7RBwt3GlFcm1fCc099/E/Hako6ErOmnVC1AicbW1NPkjsoHetE4FyOTprv yIbuz6W6XYlmS/ZiL8KgftXtOftPtd0pdZfZzyrwdB201xlzAEmdMuKBkD0ON5gZuLoy u6gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=tTaltQCIszy90dWz2zoy4OKsDcoYlJswvlfmqPPyDJ4=; b=QUYnnc8mY8xSR+LWFokjs6dNHFSj9EIzi70v3MihnObNyA8jejRovoOONa3c2EwXsy QNqnzGgBfA/1gfCGdnr+LEZEysiNEF7H1iB+bkYKlPDcduSiaPEH9xAoxVsJKpmclsii s3t3DqvzSmIkXlzz9WAFbYPb2LGho3dpSAPNLCvc7GsTEnueF6vr7dy1D1HkBSgXNOq7 pbig3igWY1TF7SUOFbacoT85+Yx2wV5IUh/K4hDR+cJ5UgIBuHPFRvQANTiQN+PXsuKu Pj6o7d7GBx1mADZ8xSG9UFEafyERFtqnRHFsXcvtPntXWWzKLwrpvvT1vlDgjo7v6Dnm BeOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14-v6si420224pgc.620.2018.05.15.11.24.56; Tue, 15 May 2018 11:25:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753279AbeEOSVQ (ORCPT + 99 others); Tue, 15 May 2018 14:21:16 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:59840 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752458AbeEOSVL (ORCPT ); Tue, 15 May 2018 14:21:11 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0509C378A19CC; Wed, 16 May 2018 02:21:07 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.202.227.234) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Wed, 16 May 2018 02:21:01 +0800 From: Salil Mehta To: CC: , , , , , , , Fuyun Liang Subject: [PATCH net-next 02/10] net: hns3: Fix for the null pointer problem occurring when initializing ae_dev failed Date: Tue, 15 May 2018 19:20:06 +0100 Message-ID: <20180515182014.42196-3-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180515182014.42196-1-salil.mehta@huawei.com> References: <20180515182014.42196-1-salil.mehta@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.202.227.234] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fuyun Liang When initializing ae_dev failed during loading hclge.ko, the drvdata will be set to null. When removing hns3.ko, we get a null ae_dev. It causes the null pointer problem. This patch removes pci_set_drvdata from error handle of hclge_init_ae_dev to fix the bug, since pci_set_drvdata has been called in hns3_remove. Also, we do not need to uninit the ae_dev which is not initialized. And it may be the one which is initialized failed. Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support") Signed-off-by: Fuyun Liang Signed-off-by: Peng Li Signed-off-by: Salil Mehta --- drivers/net/ethernet/hisilicon/hns3/hnae3.c | 6 ++++++ drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 5 +---- drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 6 ++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c b/drivers/net/ethernet/hisilicon/hns3/hnae3.c index 1686ceb..ab2e72c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c @@ -168,6 +168,9 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo) mutex_lock(&hnae3_common_lock); /* Check if there are matched ae_dev */ list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) { + if (!hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) + continue; + id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!id) continue; @@ -256,6 +259,9 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev) mutex_lock(&hnae3_common_lock); /* Check if there are matched ae_algo */ list_for_each_entry(ae_algo, &hnae3_ae_algo_list, node) { + if (!hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) + continue; + id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!id) continue; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 343197a..c2501b1 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -5379,7 +5379,7 @@ static int hclge_pci_init(struct hclge_dev *hdev) ret = pci_enable_device(pdev); if (ret) { dev_err(&pdev->dev, "failed to enable PCI device\n"); - goto err_no_drvdata; + return ret; } ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); @@ -5417,8 +5417,6 @@ static int hclge_pci_init(struct hclge_dev *hdev) pci_release_regions(pdev); err_disable_device: pci_disable_device(pdev); -err_no_drvdata: - pci_set_drvdata(pdev, NULL); return ret; } @@ -5594,7 +5592,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) pci_clear_master(pdev); pci_release_regions(pdev); pci_disable_device(pdev); - pci_set_drvdata(pdev, NULL); out: return ret; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index 2dbffce..b7578c6 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -1563,7 +1563,7 @@ static int hclgevf_pci_init(struct hclgevf_dev *hdev) ret = pci_enable_device(pdev); if (ret) { dev_err(&pdev->dev, "failed to enable PCI device\n"); - goto err_no_drvdata; + return ret; } ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); @@ -1595,8 +1595,7 @@ static int hclgevf_pci_init(struct hclgevf_dev *hdev) pci_release_regions(pdev); err_disable_device: pci_disable_device(pdev); -err_no_drvdata: - pci_set_drvdata(pdev, NULL); + return ret; } @@ -1608,7 +1607,6 @@ static void hclgevf_pci_uninit(struct hclgevf_dev *hdev) pci_clear_master(pdev); pci_release_regions(pdev); pci_disable_device(pdev); - pci_set_drvdata(pdev, NULL); } static int hclgevf_init_hdev(struct hclgevf_dev *hdev) -- 2.7.4