Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1872062yba; Thu, 25 Apr 2019 07:06:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZOCSYivDbfMVIYrp+sWC9xVJcpxoCPeBOAQA5ewiBSMyswxiUpgNmYkJxZ9WnZ8dfutpo X-Received: by 2002:a17:902:26b:: with SMTP id 98mr9231928plc.30.1556201172380; Thu, 25 Apr 2019 07:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556201172; cv=none; d=google.com; s=arc-20160816; b=oE9ebGFoiCT9r/KBAyUNQ14HTZID+rPBC2uh1ziS6yK4dgSbpM6nwkwDII35gwZa3Q y06WgqF+CxPRegVXx/qDtbI+GmLX2RT8dimZMuad7CYUBPWhQtpUM/x5p0mAtuQs9Vqi nOKRYNiLgb5r3imouZifh+jergT3v6IDmWCeMeks54fs0dc1jFvdCZ3gQX64ZOpAcFz2 s+C0slsUD7V8XO+s/js9wAhFzuGGPD1gF2zPh5uduigq/Yrsehz4RfxbRKswCWo57oqT hL5e7smIwhr47+fHWv0dXtmChyKneFFPvlZw+98hQcfd6LETCAoMU/elzd+krU00Ar5h HGMA== 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; bh=Wxfm6KuMxX3vrxvzXke1TTpyJWA1YQYW4JAOj1HdOuk=; b=PQOng+ytrO6mrZ8eBjShLH/3zWt0A6P338VJAATbRZBn89jwEPWGXP1rJfaqGa2mOs PbXBu2CJziPd+27cK7kkPiFgGPHBEDzWI4osJw+7YGkuhlMwuM1pF54UcPgbr2ogPrks 7JbpXovBiuULXs8+aef6iEqy6xPLNfqrtdSWXqtVV5a+llgaqpypK5Q6qwsqBzVlbST+ dSyhfnwHZavE+z6fhoYDad5gwC3D2HsJYApa4828KMD16lZoAmK0x3AeUHQYToJ/y9xd K8OuQFrpa20UfdxNxkqSclQ2neEp129Zu2NifcpU6Zc5+wmt6ndqSSveEMjylB793hEp q3JA== 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 m6si5401951pll.96.2019.04.25.07.05.55; Thu, 25 Apr 2019 07:06:12 -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 S2387890AbfDYMo1 (ORCPT + 99 others); Thu, 25 Apr 2019 08:44:27 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6693 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731399AbfDYMoR (ORCPT ); Thu, 25 Apr 2019 08:44:17 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3AC70B4E357C1B479CB3; Thu, 25 Apr 2019 20:44:14 +0800 (CST) Received: from localhost.localdomain (10.67.212.132) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Thu, 25 Apr 2019 20:44:06 +0800 From: Huazhong Tan To: CC: , , , , , , Huazhong Tan , Peng Li Subject: [PATCH V3 net-next 10/11] net: hns3: prevent double free in hns3_put_ring_config() Date: Thu, 25 Apr 2019 20:42:54 +0800 Message-ID: <1556196175-65389-11-git-send-email-tanhuazhong@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556196175-65389-1-git-send-email-tanhuazhong@huawei.com> References: <1556196175-65389-1-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.132] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds a check for the hns3_put_ring_config() to prevent double free, and for more readable, move the NULL assignment of priv->ring_data into the hns3_put_ring_config(). Signed-off-by: Huazhong Tan Signed-off-by: Peng Li --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 7dc281c..b0f31eb 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -3487,6 +3487,7 @@ static int hns3_get_ring_config(struct hns3_nic_priv *priv) } devm_kfree(&pdev->dev, priv->ring_data); + priv->ring_data = NULL; return ret; } @@ -3495,12 +3496,16 @@ static void hns3_put_ring_config(struct hns3_nic_priv *priv) struct hnae3_handle *h = priv->ae_handle; int i; + if (!priv->ring_data) + return; + for (i = 0; i < h->kinfo.num_tqps; i++) { devm_kfree(priv->dev, priv->ring_data[i].ring); devm_kfree(priv->dev, priv->ring_data[i + h->kinfo.num_tqps].ring); } devm_kfree(priv->dev, priv->ring_data); + priv->ring_data = NULL; } static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring) @@ -3920,8 +3925,6 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset) hns3_dbg_uninit(handle); - priv->ring_data = NULL; - out_netdev_free: free_netdev(netdev); } @@ -4268,12 +4271,10 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle) hns3_uninit_all_ring(priv); err_uninit_vector: hns3_nic_uninit_vector_data(priv); - priv->ring_data = NULL; err_dealloc_vector: hns3_nic_dealloc_vector_data(priv); err_put_ring: hns3_put_ring_config(priv); - priv->ring_data = NULL; return ret; } @@ -4335,7 +4336,6 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle) netdev_err(netdev, "uninit ring error\n"); hns3_put_ring_config(priv); - priv->ring_data = NULL; return ret; } -- 2.7.4