aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuazhong Tan <tanhuazhong@huawei.com>2018-10-30 09:50:44 -0400
committerDavid S. Miller <davem@davemloft.net>2018-10-31 15:42:38 -0400
commit73b907a083b8a8c1c62cb494bc9fbe6ae086c460 (patch)
tree83e7f678a3e27987ed47d82b58d27a479653d614
parentece4bf46e98c9f3775a488f3932a531508d3b1a2 (diff)
net: hns3: bugfix for buffer not free problem during resetting
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 <tanhuazhong@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3_enet.c24
1 files 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 0b4323b1f930..b767ff96b537 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2727,7 +2727,7 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2727 chain = devm_kzalloc(&pdev->dev, sizeof(*chain), 2727 chain = devm_kzalloc(&pdev->dev, sizeof(*chain),
2728 GFP_KERNEL); 2728 GFP_KERNEL);
2729 if (!chain) 2729 if (!chain)
2730 return -ENOMEM; 2730 goto err_free_chain;
2731 2731
2732 cur_chain->next = chain; 2732 cur_chain->next = chain;
2733 chain->tqp_index = tx_ring->tqp->tqp_index; 2733 chain->tqp_index = tx_ring->tqp->tqp_index;
@@ -2757,7 +2757,7 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2757 while (rx_ring) { 2757 while (rx_ring) {
2758 chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); 2758 chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL);
2759 if (!chain) 2759 if (!chain)
2760 return -ENOMEM; 2760 goto err_free_chain;
2761 2761
2762 cur_chain->next = chain; 2762 cur_chain->next = chain;
2763 chain->tqp_index = rx_ring->tqp->tqp_index; 2763 chain->tqp_index = rx_ring->tqp->tqp_index;
@@ -2772,6 +2772,16 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2772 } 2772 }
2773 2773
2774 return 0; 2774 return 0;
2775
2776err_free_chain:
2777 cur_chain = head->next;
2778 while (cur_chain) {
2779 chain = cur_chain->next;
2780 devm_kfree(&pdev->dev, chain);
2781 cur_chain = chain;
2782 }
2783
2784 return -ENOMEM;
2775} 2785}
2776 2786
2777static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, 2787static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
@@ -3037,8 +3047,10 @@ static int hns3_queue_to_ring(struct hnae3_queue *tqp,
3037 return ret; 3047 return ret;
3038 3048
3039 ret = hns3_ring_get_cfg(tqp, priv, HNAE3_RING_TYPE_RX); 3049 ret = hns3_ring_get_cfg(tqp, priv, HNAE3_RING_TYPE_RX);
3040 if (ret) 3050 if (ret) {
3051 devm_kfree(priv->dev, priv->ring_data[tqp->tqp_index].ring);
3041 return ret; 3052 return ret;
3053 }
3042 3054
3043 return 0; 3055 return 0;
3044} 3056}
@@ -3065,6 +3077,12 @@ static int hns3_get_ring_config(struct hns3_nic_priv *priv)
3065 3077
3066 return 0; 3078 return 0;
3067err: 3079err:
3080 while (i--) {
3081 devm_kfree(priv->dev, priv->ring_data[i].ring);
3082 devm_kfree(priv->dev,
3083 priv->ring_data[i + h->kinfo.num_tqps].ring);
3084 }
3085
3068 devm_kfree(&pdev->dev, priv->ring_data); 3086 devm_kfree(&pdev->dev, priv->ring_data);
3069 return ret; 3087 return ret;
3070} 3088}