Use calloc() in favor of malloc + memset.

Reviewed by:	neel
This commit is contained in:
Xin LI 2014-04-22 18:55:21 +00:00
parent 6f05733a1f
commit 994f858a8b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264770
9 changed files with 12 additions and 24 deletions

View File

@ -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;

View File

@ -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++;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;