mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-23 09:47:44 +00:00
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>
This commit is contained in:
@@ -83,13 +83,12 @@ struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size)
|
||||
if (!sbuf_allocate_size)
|
||||
return NULL;
|
||||
|
||||
sbuf = malloc(sbuf_allocate_size);
|
||||
sbuf = calloc(1, sbuf_allocate_size);
|
||||
if (sbuf == NULL) {
|
||||
pr_err("%s no memory!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(sbuf, 0, SBUF_HEAD_SIZE);
|
||||
sbuf->ele_num = ele_num;
|
||||
sbuf->ele_size = ele_size;
|
||||
sbuf->size = ele_num * ele_size;
|
||||
|
Reference in New Issue
Block a user