1
0
Fork 0

ringtest: ring.c malloc & memset to calloc

Code cleanup change - moving from malloc & memset to calloc.

Signed-off-by: Peter Malone <peter.malone@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hifive-unleashed-5.1
Peter Malone 2017-02-16 15:42:26 -05:00 committed by Michael S. Tsirkin
parent 0063e8bbd2
commit 03ee47ae8a
1 changed files with 2 additions and 4 deletions

View File

@ -84,12 +84,11 @@ void alloc_ring(void)
perror("Unable to allocate ring buffer.\n"); perror("Unable to allocate ring buffer.\n");
exit(3); exit(3);
} }
event = malloc(sizeof *event); event = calloc(1, sizeof(*event));
if (!event) { if (!event) {
perror("Unable to allocate event buffer.\n"); perror("Unable to allocate event buffer.\n");
exit(3); exit(3);
} }
memset(event, 0, sizeof *event);
guest.avail_idx = 0; guest.avail_idx = 0;
guest.kicked_avail_idx = -1; guest.kicked_avail_idx = -1;
guest.last_used_idx = 0; guest.last_used_idx = 0;
@ -102,12 +101,11 @@ void alloc_ring(void)
ring[i] = desc; ring[i] = desc;
} }
guest.num_free = ring_size; guest.num_free = ring_size;
data = malloc(ring_size * sizeof *data); data = calloc(ring_size, sizeof(*data));
if (!data) { if (!data) {
perror("Unable to allocate data buffer.\n"); perror("Unable to allocate data buffer.\n");
exit(3); exit(3);
} }
memset(data, 0, ring_size * sizeof *data);
} }
/* guest side */ /* guest side */