-/* $OpenBSD: virtio.c,v 1.15 2016/07/09 09:06:22 stefan Exp $ */
+/* $OpenBSD: virtio.c,v 1.16 2016/07/19 09:52:34 natano Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
q_gpa = viornd.vq[viornd.cfg.queue_notify].qa;
q_gpa = q_gpa * VIRTIO_PAGE_SIZE;
- buf = malloc(vr_sz);
+ buf = calloc(1, vr_sz);
if (buf == NULL) {
- log_warn("malloc error getting viornd ring");
+ log_warn("calloc error getting viornd ring");
return (0);
}
- memset(buf, 0, vr_sz);
-
if (read_mem(q_gpa, buf, vr_sz)) {
free(buf);
return (0);
q_gpa = dev->vq[dev->cfg.queue_notify].qa;
q_gpa = q_gpa * VIRTIO_PAGE_SIZE;
- vr = malloc(vr_sz);
+ vr = calloc(1, vr_sz);
if (vr == NULL) {
- log_warn("malloc error getting vioblk ring");
+ log_warn("calloc error getting vioblk ring");
return (0);
}
- memset(vr, 0, vr_sz);
-
if (read_mem(q_gpa, vr, vr_sz)) {
log_warnx("error reading gpa 0x%llx", q_gpa);
free(vr);
q_gpa = dev->vq[0].qa;
q_gpa = q_gpa * VIRTIO_PAGE_SIZE;
- vr = malloc(vr_sz);
+ vr = calloc(1, vr_sz);
if (vr == NULL) {
- log_warn("rx enq: malloc error getting vionet ring");
+ log_warn("rx enq: calloc error getting vionet ring");
return (0);
}
- memset(vr, 0, vr_sz);
-
if (read_mem(q_gpa, vr, vr_sz)) {
log_warnx("rx enq: error reading gpa 0x%llx", q_gpa);
free(vr);
q_gpa = dev->vq[dev->cfg.queue_notify].qa;
q_gpa = q_gpa * VIRTIO_PAGE_SIZE;
- vr = malloc(vr_sz);
+ vr = calloc(1, vr_sz);
if (vr == NULL) {
- log_warn("malloc error getting vionet ring");
+ log_warn("calloc error getting vionet ring");
goto out;
}
- memset(vr, 0, vr_sz);
-
if (read_mem(q_gpa, vr, vr_sz)) {
log_warnx("error reading gpa 0x%llx", q_gpa);
goto out;
+ sizeof(uint16_t) * (2 + VIORND_QUEUE_SIZE));
if (vcp->vcp_ndisks > 0) {
- vioblk = malloc(sizeof(struct vioblk_dev) * vcp->vcp_ndisks);
+ vioblk = calloc(vcp->vcp_ndisks, sizeof(struct vioblk_dev));
if (vioblk == NULL) {
- log_warn("%s: malloc failure allocating vioblks",
+ log_warn("%s: calloc failure allocating vioblks",
__progname);
return;
}
- memset(vioblk, 0, sizeof(struct vioblk_dev) * vcp->vcp_ndisks);
-
/* One virtio block device for each disk defined in vcp */
for (i = 0; i < vcp->vcp_ndisks; i++) {
if ((sz = lseek(child_disks[i], 0, SEEK_END)) == -1)
}
if (vcp->vcp_nnics > 0) {
- vionet = malloc(sizeof(struct vionet_dev) * vcp->vcp_nnics);
+ vionet = calloc(vcp->vcp_nnics, sizeof(struct vionet_dev));
if (vionet == NULL) {
- log_warn("%s: malloc failure allocating vionets",
+ log_warn("%s: calloc failure allocating vionets",
__progname);
return;
}
- memset(vionet, 0, sizeof(struct vionet_dev) * vcp->vcp_nnics);
-
nr_vionet = vcp->vcp_nnics;
/* Virtio network */
for (i = 0; i < vcp->vcp_nnics; i++) {
-/* $OpenBSD: vmm.c,v 1.32 2016/07/09 09:06:22 stefan Exp $ */
+/* $OpenBSD: vmm.c,v 1.33 2016/07/19 09:52:34 natano Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
ret = 0;
- tid = malloc(sizeof(pthread_t) * vcp->vcp_ncpus);
- vrp = malloc(sizeof(struct vm_run_params *) * vcp->vcp_ncpus);
+ tid = calloc(vcp->vcp_ncpus, sizeof(pthread_t));
+ vrp = calloc(vcp->vcp_ncpus, sizeof(struct vm_run_params *));
if (tid == NULL || vrp == NULL) {
log_warn("%s: memory allocation error - exiting.",
__progname);