Hello!

On 10/29/2018 4:54 PM, Huazhong Tan wrote:

When hns3_get_ring_config()/hns3_queue_to_ring() failed during resetting,
the allocated memory has not been freed before hns3_get_ring_config() and
hns3_queue_to_ring() return. So this patch fixes the buffer not freeing
problem during resetting.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan <tanhuazh...@huawei.com>
---
  drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index d9066c5..6f0fd62 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
[...]
@@ -3047,7 +3049,7 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
  {
        struct hnae3_handle *h = priv->ae_handle;
        struct pci_dev *pdev = h->pdev;
-       int i, ret;
+       int i, j, ret;
priv->ring_data = devm_kzalloc(&pdev->dev,
                                        array3_size(h->kinfo.num_tqps,
@@ -3065,6 +3067,12 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
return 0;
  err:
+       for (j = i - 1; j >= 0; j--) {

   As is with the other patch, you don't need 'j' here.

+               devm_kfree(priv->dev, priv->ring_data[j].ring);
+               devm_kfree(priv->dev,
+                          priv->ring_data[j + h->kinfo.num_tqps].ring);
+       }
+
        devm_kfree(&pdev->dev, priv->ring_data);
        return ret;
  }

MBR, Sergei

Reply via email to