lkml.org 
[lkml]   [2019]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 4.14 106/150] net: hns3: bugfix for buffer not free problem during resetting
    Date
    From: Huazhong Tan <tanhuazhong@huawei.com>

    [ 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 <tanhuazhong@huawei.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    .../hisilicon/hns3/hns3pf/hns3_enet.c | 24 ++++++++++++++++---
    1 file changed, 21 insertions(+), 3 deletions(-)

    diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
    index 69726908e72c4..3faf5d46b8a21 100644
    --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
    +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
    @@ -2302,7 +2302,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;
    @@ -2326,7 +2326,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;
    @@ -2338,6 +2338,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,
    @@ -2532,8 +2542,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;
    }
    @@ -2558,6 +2570,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
    \
     
     \ /
      Last update: 2019-11-16 17:09    [W:4.256 / U:0.108 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site