5 Star 0 Fork 4

src-openEuler/hikptool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0048-hikptool-roce-Use-calloc-to-alloc-memory-for-array-i.patch 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/hikptool.git
git@gitee.com:src-openeuler/hikptool.git
src-openeuler
hikptool
hikptool
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385