mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ringtest: ring.c malloc & memset to calloc
@ 2017-02-16 20:42 Peter Malone
  0 siblings, 0 replies; only message in thread
From: Peter Malone @ 2017-02-16 20:42 UTC (permalink / raw)
  To: mst, jasowang, linux-kernel; +Cc: Peter Malone

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

Signed-off-by: Peter Malone <peter.malone@gmail.com>
---
 tools/virtio/ringtest/ring.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/virtio/ringtest/ring.c b/tools/virtio/ringtest/ring.c
index 747c5dd..fa92638 100644
--- a/tools/virtio/ringtest/ring.c
+++ b/tools/virtio/ringtest/ring.c
@@ -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 */
-- 
1.7.10.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-02-16 20:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16 20:42 [PATCH] ringtest: ring.c malloc & memset to calloc Peter Malone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome