32 lines
1.4 KiB
Diff
32 lines
1.4 KiB
Diff
|
|
From 2abbc6020498b1c464775623de8b2db76e684d55 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Junxian Huang <huangjunxian6@hisilicon.com>
|
||
|
|
Date: Tue, 24 Oct 2023 11:16:49 +0800
|
||
|
|
Subject: hikptool/roce: Use calloc to alloc memory for array instead of malloc
|
||
|
|
|
||
|
|
calloc is more situable for memory allocation for array than malloc,
|
||
|
|
since the allocated memory will be set to 0.
|
||
|
|
|
||
|
|
Fixes: 8b3b68347165 ("hikptool/roce: Add a common frame for hikptool roce register query")
|
||
|
|
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
|
||
|
|
---
|
||
|
|
net/roce/roce_ext_common/hikp_roce_ext_common.c | 4 ++--
|
||
|
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.c b/net/roce/roce_ext_common/hikp_roce_ext_common.c
|
||
|
|
index d0fae69..d5ae64a 100644
|
||
|
|
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
|
||
|
|
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
|
||
|
|
@@ -115,8 +115,8 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
|
||
|
|
max_size = res_head->total_block_num * sizeof(uint32_t);
|
||
|
|
|
||
|
|
if (block_id == 0) {
|
||
|
|
- reg->offset = (uint32_t *)malloc(max_size);
|
||
|
|
- reg->data = (uint32_t *)malloc(max_size);
|
||
|
|
+ reg->offset = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
|
||
|
|
+ reg->data = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
|
||
|
|
if ((reg->offset == NULL) || (reg->data == NULL)) {
|
||
|
|
printf("hikptool roce_%s alloc log memmory 0x%x failed!\n",
|
||
|
|
cmd_name, max_size);
|
||
|
|
--
|
||
|
|
2.30.0
|