diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c index ffa343c0dd5e..b29bc7856e86 100644 --- a/usr.sbin/bhyve/block_if.c +++ b/usr.sbin/bhyve/block_if.c @@ -270,13 +270,12 @@ blockif_open(const char *optstr, const char *ident) assert(sectsz != 0); } - bc = malloc(sizeof(struct blockif_ctxt)); + bc = calloc(1, sizeof(struct blockif_ctxt)); if (bc == NULL) { close(fd); return (NULL); } - memset(bc, 0, sizeof(*bc)); bc->bc_magic = BLOCKIF_SIG; bc->bc_fd = fd; bc->bc_size = size; diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c index 82faab2d245b..b83ec6904d63 100644 --- a/usr.sbin/bhyve/mevent.c +++ b/usr.sbin/bhyve/mevent.c @@ -268,12 +268,11 @@ mevent_add(int tfd, enum ev_type type, /* * Allocate an entry, populate it, and add it to the change list. */ - mevp = malloc(sizeof(struct mevent)); + mevp = calloc(1, sizeof(struct mevent)); if (mevp == NULL) { goto exit; } - memset(mevp, 0, sizeof(struct mevent)); if (type == EVF_TIMER) { mevp->me_msecs = tfd; mevp->me_timid = mevent_timid++; diff --git a/usr.sbin/bhyve/pci_ahci.c b/usr.sbin/bhyve/pci_ahci.c index fb32bade1f71..3f9fc7f1c33c 100644 --- a/usr.sbin/bhyve/pci_ahci.c +++ b/usr.sbin/bhyve/pci_ahci.c @@ -1756,8 +1756,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts, int atapi) dbg = fopen("/tmp/log", "w+"); #endif - sc = malloc(sizeof(struct pci_ahci_softc)); - memset(sc, 0, sizeof(struct pci_ahci_softc)); + sc = calloc(1, sizeof(struct pci_ahci_softc)); pi->pi_arg = sc; sc->asc_pi = pi; sc->ports = MAX_PORTS; diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index 3c3188a9d4c1..c403233208cb 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -688,8 +688,7 @@ pci_emul_init(struct vmctx *ctx, struct pci_devemu *pde, int bus, int slot, struct pci_devinst *pdi; int err; - pdi = malloc(sizeof(struct pci_devinst)); - bzero(pdi, sizeof(*pdi)); + pdi = calloc(1, sizeof(struct pci_devinst)); pdi->pi_vmctx = ctx; pdi->pi_bus = bus; @@ -781,8 +780,7 @@ pci_msix_table_init(struct pci_devinst *pi, int table_entries) assert(table_entries <= MAX_MSIX_TABLE_ENTRIES); table_size = table_entries * MSIX_TABLE_ENTRY_SIZE; - pi->pi_msix.table = malloc(table_size); - bzero(pi->pi_msix.table, table_size); + pi->pi_msix.table = calloc(1, table_size); /* set mask bit of vector control register */ for (i = 0; i < table_entries; i++) @@ -1781,8 +1779,7 @@ pci_emul_dinit(struct vmctx *ctx, struct pci_devinst *pi, char *opts) int error; struct pci_emul_dsoftc *sc; - sc = malloc(sizeof(struct pci_emul_dsoftc)); - memset(sc, 0, sizeof(struct pci_emul_dsoftc)); + sc = calloc(1, sizeof(struct pci_emul_dsoftc)); pi->pi_arg = sc; diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 562d53267099..04d68c4c15ce 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -232,8 +232,7 @@ cfginitmsi(struct passthru_softc *sc) /* Allocate the emulated MSI-X table array */ table_size = pi->pi_msix.table_count * MSIX_TABLE_ENTRY_SIZE; - pi->pi_msix.table = malloc(table_size); - bzero(pi->pi_msix.table, table_size); + pi->pi_msix.table = calloc(1, table_size); /* Mask all table entries */ for (i = 0; i < pi->pi_msix.table_count; i++) { @@ -574,8 +573,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) if (vm_assign_pptdev(ctx, bus, slot, func) != 0) goto done; - sc = malloc(sizeof(struct passthru_softc)); - memset(sc, 0, sizeof(struct passthru_softc)); + sc = calloc(1, sizeof(struct passthru_softc)); pi->pi_arg = sc; sc->psc_pi = pi; diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 2f37804fe444..3474fd7fb88d 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -299,8 +299,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) assert(sectsz != 0); } - sc = malloc(sizeof(struct pci_vtblk_softc)); - memset(sc, 0, sizeof(struct pci_vtblk_softc)); + sc = calloc(1, sizeof(struct pci_vtblk_softc)); /* record fd of storage device/file */ sc->vbsc_fd = fd; diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c index e7b54bca4049..c3b8690bb6e0 100644 --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -513,8 +513,7 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) char *vtopts; int mac_provided; - sc = malloc(sizeof(struct pci_vtnet_softc)); - memset(sc, 0, sizeof(struct pci_vtnet_softc)); + sc = calloc(1, sizeof(struct pci_vtnet_softc)); pthread_mutex_init(&sc->vsc_mtx, NULL); diff --git a/usr.sbin/bhyve/pci_virtio_rnd.c b/usr.sbin/bhyve/pci_virtio_rnd.c index 38459d216c7b..4d531834cbe2 100644 --- a/usr.sbin/bhyve/pci_virtio_rnd.c +++ b/usr.sbin/bhyve/pci_virtio_rnd.c @@ -155,8 +155,7 @@ pci_vtrnd_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) return (1); } - sc = malloc(sizeof(struct pci_vtrnd_softc)); - memset(sc, 0, sizeof(struct pci_vtrnd_softc)); + sc = calloc(1, sizeof(struct pci_vtrnd_softc)); vi_softc_linkup(&sc->vrsc_vs, &vtrnd_vi_consts, sc, pi, &sc->vrsc_vq); sc->vrsc_vs.vs_mtx = &sc->vrsc_mtx; diff --git a/usr.sbin/bhyve/uart_emul.c b/usr.sbin/bhyve/uart_emul.c index dd1c22039dd4..38e14a95ab03 100644 --- a/usr.sbin/bhyve/uart_emul.c +++ b/usr.sbin/bhyve/uart_emul.c @@ -563,8 +563,7 @@ uart_init(uart_intr_func_t intr_assert, uart_intr_func_t intr_deassert, { struct uart_softc *sc; - sc = malloc(sizeof(struct uart_softc)); - bzero(sc, sizeof(struct uart_softc)); + sc = calloc(1, sizeof(struct uart_softc)); sc->arg = arg; sc->intr_assert = intr_assert;