Commit 77296bf6 authored by Yunsheng Lin's avatar Yunsheng Lin Committed by David S. Miller

net: hns3: use devm_kcalloc when allocating desc_cb

This patch uses devm_kcalloc instead of kcalloc when allocating
ring->desc_cb, because devm_kcalloc not only ensure to free the
memory when the dev is deallocted, but also allocate the memory
from it's device memory node.
Signed-off-by: default avatarYunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 845e0d1d
...@@ -3478,8 +3478,8 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring) ...@@ -3478,8 +3478,8 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
if (ring->desc_num <= 0 || ring->buf_size <= 0) if (ring->desc_num <= 0 || ring->buf_size <= 0)
return -EINVAL; return -EINVAL;
ring->desc_cb = kcalloc(ring->desc_num, sizeof(ring->desc_cb[0]), ring->desc_cb = devm_kcalloc(ring_to_dev(ring), ring->desc_num,
GFP_KERNEL); sizeof(ring->desc_cb[0]), GFP_KERNEL);
if (!ring->desc_cb) { if (!ring->desc_cb) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -3500,7 +3500,7 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring) ...@@ -3500,7 +3500,7 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
out_with_desc: out_with_desc:
hns3_free_desc(ring); hns3_free_desc(ring);
out_with_desc_cb: out_with_desc_cb:
kfree(ring->desc_cb); devm_kfree(ring_to_dev(ring), ring->desc_cb);
ring->desc_cb = NULL; ring->desc_cb = NULL;
out: out:
return ret; return ret;
...@@ -3509,7 +3509,7 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring) ...@@ -3509,7 +3509,7 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
static void hns3_fini_ring(struct hns3_enet_ring *ring) static void hns3_fini_ring(struct hns3_enet_ring *ring)
{ {
hns3_free_desc(ring); hns3_free_desc(ring);
kfree(ring->desc_cb); devm_kfree(ring_to_dev(ring), ring->desc_cb);
ring->desc_cb = NULL; ring->desc_cb = NULL;
ring->next_to_clean = 0; ring->next_to_clean = 0;
ring->next_to_use = 0; ring->next_to_use = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment