Skip to content

Commit b11460f

Browse files
yechun1jren1
authored andcommitted
replace malloc and memset with calloc
malloc: allocate a block of memory, the contents of the block are undefined. calloc: allocate a block of memory for an array of num elements and initializes all its bits to zero. Signed-off-by: yechunliang <yechunliangcn@163.com>
1 parent 92d8638 commit b11460f

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

hypervisor/arch/x86/vtd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ static int register_hrhd_units(void)
208208
}
209209

210210
for (i = 0; i < info->drhd_count; i++) {
211-
drhd_rt = malloc(sizeof(struct dmar_drhd_rt));
211+
drhd_rt = calloc(1, sizeof(struct dmar_drhd_rt));
212212
ASSERT(drhd_rt != NULL, "");
213-
memset(drhd_rt, 0, sizeof(struct dmar_drhd_rt));
214213
drhd_rt->drhd = &info->drhd_units[i];
215214
dmar_register_hrhd(drhd_rt);
216215
}

hypervisor/debug/sbuf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size)
8383
if (!sbuf_allocate_size)
8484
return NULL;
8585

86-
sbuf = malloc(sbuf_allocate_size);
86+
sbuf = calloc(1, sbuf_allocate_size);
8787
if (sbuf == NULL) {
8888
pr_err("%s no memory!", __func__);
8989
return NULL;
9090
}
9191

92-
memset(sbuf, 0, SBUF_HEAD_SIZE);
9392
sbuf->ele_num = ele_num;
9493
sbuf->ele_size = ele_size;
9594
sbuf->size = ele_num * ele_size;

0 commit comments

Comments
 (0)