diff options
author | Peter Malone <peter.malone@gmail.com> | 2017-02-16 15:42:26 -0500 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2018-02-01 09:26:46 -0500 |
commit | 03ee47ae8a7c608975be7e45287bff0482e295d6 (patch) | |
tree | 05ea298938a19379f4a49963c23c175f47327957 | |
parent | 0063e8bbd2b62d13645d416625478c2199fdee0f (diff) |
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>
-rw-r--r-- | tools/virtio/ringtest/ring.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/tools/virtio/ringtest/ring.c b/tools/virtio/ringtest/ring.c index 2b9859beea65..5a41404aaef5 100644 --- a/tools/virtio/ringtest/ring.c +++ b/tools/virtio/ringtest/ring.c | |||
@@ -84,12 +84,11 @@ void alloc_ring(void) | |||
84 | perror("Unable to allocate ring buffer.\n"); | 84 | perror("Unable to allocate ring buffer.\n"); |
85 | exit(3); | 85 | exit(3); |
86 | } | 86 | } |
87 | event = malloc(sizeof *event); | 87 | event = calloc(1, sizeof(*event)); |
88 | if (!event) { | 88 | if (!event) { |
89 | perror("Unable to allocate event buffer.\n"); | 89 | perror("Unable to allocate event buffer.\n"); |
90 | exit(3); | 90 | exit(3); |
91 | } | 91 | } |
92 | memset(event, 0, sizeof *event); | ||
93 | guest.avail_idx = 0; | 92 | guest.avail_idx = 0; |
94 | guest.kicked_avail_idx = -1; | 93 | guest.kicked_avail_idx = -1; |
95 | guest.last_used_idx = 0; | 94 | guest.last_used_idx = 0; |
@@ -102,12 +101,11 @@ void alloc_ring(void) | |||
102 | ring[i] = desc; | 101 | ring[i] = desc; |
103 | } | 102 | } |
104 | guest.num_free = ring_size; | 103 | guest.num_free = ring_size; |
105 | data = malloc(ring_size * sizeof *data); | 104 | data = calloc(ring_size, sizeof(*data)); |
106 | if (!data) { | 105 | if (!data) { |
107 | perror("Unable to allocate data buffer.\n"); | 106 | perror("Unable to allocate data buffer.\n"); |
108 | exit(3); | 107 | exit(3); |
109 | } | 108 | } |
110 | memset(data, 0, ring_size * sizeof *data); | ||
111 | } | 109 | } |
112 | 110 | ||
113 | /* guest side */ | 111 | /* guest side */ |