From patchwork Tue May 15 18:20:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 135915 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1371382lji; Tue, 15 May 2018 11:21:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp12JZtn1VE4uLAEvh2fClepHcOxEOh592z14FQ/k0C+cSux+CWIElTVKouPboVJtrB+kXS X-Received: by 2002:a17:902:8d8c:: with SMTP id v12-v6mr15440560plo.366.1526408477688; Tue, 15 May 2018 11:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526408477; cv=none; d=google.com; s=arc-20160816; b=VbigrlCcD2Rbmwh8E9JZ/ameAfly/tMpkXS9bj8W/lOTTPY9pxNhZjwBYA+4SU7P8S /v7Ob/OOMFu1L1ItSOjDqK9pP6Laegk/nE6SxolJJrs3+odEsB98hcC6TDI0HxySJ9D+ F9KGsDyNzSk5OO4IeK8rQ6ZkiqqvePge5mXNJE8GWR6k/FAUJabRUBuyLDPAI43IhrYI X8/W4nwGkGTvcuVFH8EIfEVlUzBxDhC0eyoB81xPlfQcycgp+Okzq2/uVVmf8tUa2eyI QaisRsFE9qmHflH1/VzZMASsWEgy7UaWi5Z38tU1Hu8Dzh14UGZOO454h85cZtRJKWYP rqPw== 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=dUZGelSIJKf0TofGYaUHkWvWjab4oQFVFMAHanhJtNccZsOmgesFui1XvxYyJokPOA EBzUjhMZf4YTmA9Sxm1qu3t36NonuDlTJlIvCPD9JGoON7qqmK9FMF9E/uxnTYmxKXrd HJ7OmoV8y2WQx3QSLVEinIXdzzyNC8O22+5SmtupD/c8YgOzikyGnYw0a8/6mw+Dzo/e IY/9sjBmmRfaBXzX7K31qyDqJJQU9RGwdQ7bpksFfJ25s/kCLKp9bq11dk/ZsEKlBc8R LUTim4PJjXmxdt4z/d8bJkvUDW/uuib9ejZg5oDLhnInotYMm/QwE5l/j/uappp5DKlf ij+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 k9-v6si476344pgo.340.2018.05.15.11.21.17; Tue, 15 May 2018 11:21:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753202AbeEOSVP (ORCPT + 9 others); Tue, 15 May 2018 14:21:15 -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 X-Originating-IP: [10.202.227.234] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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(-) -- 2.7.4 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)