]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ringtest: ring.c malloc & memset to calloc
authorPeter Malone <peter.malone@gmail.com>
Thu, 16 Feb 2017 20:42:26 +0000 (15:42 -0500)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 1 Feb 2018 14:26:46 +0000 (16:26 +0200)
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>
tools/virtio/ringtest/ring.c

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