Author: delphij
Date: Tue Apr 22 18:55:21 2014
New Revision: 264770
URL: http://svnweb.freebsd.org/changeset/base/264770

Log:
  Use calloc() in favor of malloc + memset.
  
  Reviewed by:  neel

Modified:
  head/usr.sbin/bhyve/block_if.c
  head/usr.sbin/bhyve/mevent.c
  head/usr.sbin/bhyve/pci_ahci.c
  head/usr.sbin/bhyve/pci_emul.c
  head/usr.sbin/bhyve/pci_passthru.c
  head/usr.sbin/bhyve/pci_virtio_block.c
  head/usr.sbin/bhyve/pci_virtio_net.c
  head/usr.sbin/bhyve/pci_virtio_rnd.c
  head/usr.sbin/bhyve/uart_emul.c

Modified: head/usr.sbin/bhyve/block_if.c
==============================================================================
--- head/usr.sbin/bhyve/block_if.c      Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/block_if.c      Tue Apr 22 18:55:21 2014        
(r264770)
@@ -270,13 +270,12 @@ blockif_open(const char *optstr, const c
                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;

Modified: head/usr.sbin/bhyve/mevent.c
==============================================================================
--- head/usr.sbin/bhyve/mevent.c        Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/mevent.c        Tue Apr 22 18:55:21 2014        
(r264770)
@@ -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++;

Modified: head/usr.sbin/bhyve/pci_ahci.c
==============================================================================
--- head/usr.sbin/bhyve/pci_ahci.c      Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/pci_ahci.c      Tue Apr 22 18:55:21 2014        
(r264770)
@@ -1756,8 +1756,7 @@ pci_ahci_init(struct vmctx *ctx, struct 
        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;

Modified: head/usr.sbin/bhyve/pci_emul.c
==============================================================================
--- head/usr.sbin/bhyve/pci_emul.c      Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/pci_emul.c      Tue Apr 22 18:55:21 2014        
(r264770)
@@ -688,8 +688,7 @@ pci_emul_init(struct vmctx *ctx, struct 
        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 *
        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
        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;
 

Modified: head/usr.sbin/bhyve/pci_passthru.c
==============================================================================
--- head/usr.sbin/bhyve/pci_passthru.c  Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/pci_passthru.c  Tue Apr 22 18:55:21 2014        
(r264770)
@@ -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 
        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;

Modified: head/usr.sbin/bhyve/pci_virtio_block.c
==============================================================================
--- head/usr.sbin/bhyve/pci_virtio_block.c      Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/pci_virtio_block.c      Tue Apr 22 18:55:21 2014        
(r264770)
@@ -299,8 +299,7 @@ pci_vtblk_init(struct vmctx *ctx, struct
                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;

Modified: head/usr.sbin/bhyve/pci_virtio_net.c
==============================================================================
--- head/usr.sbin/bhyve/pci_virtio_net.c        Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/pci_virtio_net.c        Tue Apr 22 18:55:21 2014        
(r264770)
@@ -513,8 +513,7 @@ pci_vtnet_init(struct vmctx *ctx, struct
        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);
 

Modified: head/usr.sbin/bhyve/pci_virtio_rnd.c
==============================================================================
--- head/usr.sbin/bhyve/pci_virtio_rnd.c        Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/pci_virtio_rnd.c        Tue Apr 22 18:55:21 2014        
(r264770)
@@ -155,8 +155,7 @@ pci_vtrnd_init(struct vmctx *ctx, struct
                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;

Modified: head/usr.sbin/bhyve/uart_emul.c
==============================================================================
--- head/usr.sbin/bhyve/uart_emul.c     Tue Apr 22 18:08:34 2014        
(r264769)
+++ head/usr.sbin/bhyve/uart_emul.c     Tue Apr 22 18:55:21 2014        
(r264770)
@@ -563,8 +563,7 @@ uart_init(uart_intr_func_t intr_assert, 
 {
        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;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to