Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6016099ybc; Wed, 27 Nov 2019 13:27:17 -0800 (PST) X-Google-Smtp-Source: APXvYqzWu+t13CLFEz/4DF7eKdLid/priFUr+yLnAVVbm1S2D1U1Ui4oRRoH29DTdK2M7PNzTOWm X-Received: by 2002:a17:906:1296:: with SMTP id k22mr26674450ejb.237.1574890037388; Wed, 27 Nov 2019 13:27:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890037; cv=none; d=google.com; s=arc-20160816; b=zMH2jqJsBGfjktwC7Jv9IyXd6K80p0ujJMsu+izEg3Kt2lRfWljp1BX3bRf2fD37gz L2LFHWxmpS7Wh7zkaLsRPTnBCxX79UUM1MHBnHsNxZ8/kPyXO1kQhM7blMmVXMiqB/Yk aEi15sSqIvYjweOv+oy6E+gsMyotmdaG1V1fzSIjSLjukp3R3T3rZZY9Aa1/cZAU0dvH xk29Du/htTw5UCta24bG4jdbQoLJlrzz9gGwTHQIXXYLqkhbc+tq88uKDWsQ0APk/ZS6 jsej3s5Xj31UDdPYDu4n8lXluj4ht2BwZmbs52KSyIQUH+zChbJ9rrPSrVREBnQ5VWYZ XwBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bsqaWTkc1BbEaXQlP/3H2QDpoaJ4SIOVWMqAJTRseak=; b=JlE3hbUnnDRJGEtvMNBfyDOxVnHNSU5ym2/ho1Qo3A6XtanfBayClhAZ/fChvKv5yA Yob39OkPc87ZHKlePsjqxEyI0iKxeQM/h1R74uwrsccJz0fyF24ckHA3IHtUvTEz7NUd V/YkIe5wC+k2fqvu7/hGcgg94BnD7jSQY7F2MkhU4n3cvn2zz60gN65JqxdHVpddyPMr 3EGJsWjgy1UPhpZm7DtdeqYGHhKOlG0fXBY2CGXspshdUpjRMQFt/KIGX01Wd2CtpMFW gl2N6H6T4TfbTfj4geE67ybpqYsZRFWt9nmxka2uOVHmSKDRN3Z0Ro1wgwp5HAZrEr1g mg8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yogMqxOp; 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 g6si13119868edk.210.2019.11.27.13.26.53; Wed, 27 Nov 2019 13:27:17 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=yogMqxOp; 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 S1731351AbfK0VC6 (ORCPT + 99 others); Wed, 27 Nov 2019 16:02:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:55902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731965AbfK0VCz (ORCPT ); Wed, 27 Nov 2019 16:02:55 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 30766215F1; Wed, 27 Nov 2019 21:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888574; bh=u4cMk57GJBtPgUj1fNsMhqxtKdBQxEFX5HaDeTIiLZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yogMqxOpMb9ikIaCe4VJwwzLao76teY/to9TGdCvbfJJBwvOgcsUrmZzPuUPU9f3T 7lOCDichO+gPLIqWpVvTdYr8cG6hO7MLQedKXl80fIXqE/mPfJq/s1zAQNMYZ5J416 Dhr8Z1kjHl5DQXh/+1PcI1xKWyJx46ZyEiegzbZg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Huazhong Tan , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 185/306] net: hns3: bugfix for buffer not free problem during resetting Date: Wed, 27 Nov 2019 21:30:35 +0100 Message-Id: <20191127203128.798931840@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huazhong Tan [ Upstream commit 73b907a083b8a8c1c62cb494bc9fbe6ae086c460 ] When hns3_get_ring_config()/hns3_queue_to_ring()/ hns3_get_vector_ring_chain() failed during resetting, the allocated memory has not been freed before these three functions return. So this patch adds error handler in these functions to fix it. Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC") Signed-off-by: Huazhong Tan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index e11a7de20b8f4..3708f149d0a6a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -2547,7 +2547,7 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); if (!chain) - return -ENOMEM; + goto err_free_chain; cur_chain->next = chain; chain->tqp_index = tx_ring->tqp->tqp_index; @@ -2577,7 +2577,7 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, while (rx_ring) { chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); if (!chain) - return -ENOMEM; + goto err_free_chain; cur_chain->next = chain; chain->tqp_index = rx_ring->tqp->tqp_index; @@ -2592,6 +2592,16 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, } return 0; + +err_free_chain: + cur_chain = head->next; + while (cur_chain) { + chain = cur_chain->next; + devm_kfree(&pdev->dev, chain); + cur_chain = chain; + } + + return -ENOMEM; } static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, @@ -2836,8 +2846,10 @@ static int hns3_queue_to_ring(struct hnae3_queue *tqp, return ret; ret = hns3_ring_get_cfg(tqp, priv, HNAE3_RING_TYPE_RX); - if (ret) + if (ret) { + devm_kfree(priv->dev, priv->ring_data[tqp->tqp_index].ring); return ret; + } return 0; } @@ -2864,6 +2876,12 @@ static int hns3_get_ring_config(struct hns3_nic_priv *priv) return 0; err: + while (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(&pdev->dev, priv->ring_data); return ret; } -- 2.20.1