This is the first pass of mallocarray() in sys/dev. Please proofread.
Index: rd.c
===================================================================
RCS file: /cvs/src/sys/dev/rd.c,v
retrieving revision 1.7
diff -u -p -u -r1.7 rd.c
--- rd.c 12 Jul 2014 18:48:51 -0000 1.7
+++ rd.c 13 Jul 2014 15:49:17 -0000
@@ -88,7 +88,7 @@ rdattach(int num)
cf.cf_driver = &rd_cd;
rd_cd.cd_ndevs = num;
- rd_cd.cd_devs = malloc(num * sizeof(void *), M_DEVBUF, M_NOWAIT);
+ rd_cd.cd_devs = mallocarray(num, sizeof(void *), M_DEVBUF, M_NOWAIT);
if (rd_cd.cd_devs == NULL)
panic("rdattach: out of memory");
Index: softraid.c
===================================================================
RCS file: /cvs/src/sys/dev/softraid.c,v
retrieving revision 1.334
diff -u -p -u -r1.334 softraid.c
--- softraid.c 12 Jul 2014 18:48:51 -0000 1.334
+++ softraid.c 13 Jul 2014 15:48:56 -0000
@@ -252,7 +252,7 @@ sr_meta_attach(struct sr_discipline *sd,
/* we have a valid list now create an array index */
cl = &sd->sd_vol.sv_chunk_list;
- sd->sd_vol.sv_chunks = malloc(sizeof(struct sr_chunk *) * chunk_no,
+ sd->sd_vol.sv_chunks = mallocarray(chunk_no, sizeof(struct sr_chunk *),
M_DEVBUF, M_WAITOK | M_ZERO);
/* fill out chunk array */
@@ -1284,13 +1284,13 @@ sr_boot_assembly(struct sr_softc *sc)
}
/* Allocate memory for device and ondisk version arrays. */
- devs = malloc(BIOC_CRMAXLEN * sizeof(dev_t), M_DEVBUF,
+ devs = mallocarray(BIOC_CRMAXLEN, sizeof(dev_t), M_DEVBUF,
M_NOWAIT | M_CANFAIL);
if (devs == NULL) {
printf("%s: failed to allocate device array\n", DEVNAME(sc));
goto unwind;
}
- ondisk = malloc(BIOC_CRMAXLEN * sizeof(u_int64_t), M_DEVBUF,
+ ondisk = mallocarray(BIOC_CRMAXLEN, sizeof(u_int64_t), M_DEVBUF,
M_NOWAIT | M_CANFAIL);
if (ondisk == NULL) {
printf("%s: failed to allocate ondisk array\n", DEVNAME(sc));
@@ -1934,8 +1934,9 @@ sr_ccb_alloc(struct sr_discipline *sd)
if (sd->sd_ccb)
return (1);
- sd->sd_ccb = malloc(sizeof(struct sr_ccb) *
- sd->sd_max_wu * sd->sd_max_ccb_per_wu, M_DEVBUF, M_WAITOK | M_ZERO);
+ sd->sd_ccb = mallocarray(sd->sd_max_wu,
+ sd->sd_max_ccb_per_wu * sizeof(struct sr_ccb),
+ M_DEVBUF, M_WAITOK | M_ZERO);
TAILQ_INIT(&sd->sd_ccb_freeq);
for (i = 0; i < sd->sd_max_wu * sd->sd_max_ccb_per_wu; i++) {
ccb = &sd->sd_ccb[i];
Index: systrace.c
===================================================================
RCS file: /cvs/src/sys/dev/systrace.c,v
retrieving revision 1.70
diff -u -p -u -r1.70 systrace.c
--- systrace.c 12 Jul 2014 18:48:51 -0000 1.70
+++ systrace.c 13 Jul 2014 15:43:25 -0000
@@ -1639,7 +1639,7 @@ systrace_newpolicy(struct fsystrace *fst
DPRINTF(("%s: allocating %d -> %lu\n", __func__,
maxents, (u_long)maxents * sizeof(int)));
- pol->sysent = (u_char *)malloc(maxents * sizeof(u_char),
+ pol->sysent = mallocarray(maxents, sizeof(u_char),
M_XDATA, M_WAITOK);
pol->nsysent = maxents;
for (i = 0; i < maxents; i++)
Index: ic/ahci.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ahci.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 ahci.c
--- ic/ahci.c 12 Jul 2014 18:48:17 -0000 1.15
+++ ic/ahci.c 13 Jul 2014 16:25:21 -0000
@@ -527,8 +527,8 @@ ahci_port_alloc(struct ahci_softc *sc, u
}
/* Allocate a CCB for each command slot */
- ap->ap_ccbs = malloc(sizeof(struct ahci_ccb) * sc->sc_ncmds, M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ap->ap_ccbs = mallocarray(sc->sc_ncmds, sizeof(struct ahci_ccb),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ap->ap_ccbs == NULL) {
printf("%s: unable to allocate command list for port %d\n",
DEVNAME(sc), port);
Index: ic/aic79xx.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/aic79xx.c,v
retrieving revision 1.53
diff -u -p -u -r1.53 aic79xx.c
--- ic/aic79xx.c 12 Jul 2014 18:48:17 -0000 1.53
+++ ic/aic79xx.c 13 Jul 2014 16:25:06 -0000
@@ -6177,8 +6177,8 @@ ahd_init(struct ahd_softc *ahd)
AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
ahd->stack_size = ahd_probe_stack_size(ahd);
- ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t), M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ahd->saved_stack = mallocarray(ahd->stack_size, sizeof(uint16_t),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ahd->saved_stack == NULL)
return (ENOMEM);
Index: ic/aic7xxx.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/aic7xxx.c,v
retrieving revision 1.87
diff -u -p -u -r1.87 aic7xxx.c
--- ic/aic7xxx.c 12 Jul 2014 18:48:17 -0000 1.87
+++ ic/aic7xxx.c 13 Jul 2014 16:24:42 -0000
@@ -4235,7 +4235,7 @@ ahc_init_scbdata(struct ahc_softc *ahc)
SLIST_INIT(&scb_data->sg_maps);
/* Allocate SCB resources */
- scb_data->scbarray = malloc(sizeof(struct scb) * AHC_SCB_MAX_ALLOC,
+ scb_data->scbarray = mallocarray(AHC_SCB_MAX_ALLOC, sizeof(struct scb),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (scb_data->scbarray == NULL)
return (ENOMEM);
Index: ic/ami.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ami.c,v
retrieving revision 1.227
diff -u -p -u -r1.227 ami.c
--- ic/ami.c 12 Jul 2014 18:48:17 -0000 1.227
+++ ic/ami.c 13 Jul 2014 16:24:24 -0000
@@ -299,7 +299,7 @@ ami_alloc_ccbs(struct ami_softc *sc, int
struct ami_ccbmem *ccbmem, *mem;
int i, error;
- sc->sc_ccbs = malloc(sizeof(struct ami_ccb) * nccbs,
+ sc->sc_ccbs = mallocarray(nccbs, sizeof(struct ami_ccb),
M_DEVBUF, M_NOWAIT);
if (sc->sc_ccbs == NULL) {
printf(": unable to allocate ccbs\n");
@@ -566,7 +566,7 @@ ami_attach(struct ami_softc *sc)
#endif
#endif
- rsc = malloc(sizeof(struct ami_rawsoftc) * sc->sc_channels,
+ rsc = mallocarray(sc->sc_channels, sizeof(struct ami_rawsoftc),
M_DEVBUF, M_NOWAIT|M_ZERO);
if (!rsc) {
printf("%s: no memory for raw interface\n", DEVNAME(sc));
@@ -2408,7 +2408,7 @@ ami_create_sensors(struct ami_softc *sc)
if (ssc == NULL)
return (1);
- sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_nunits,
+ sc->sc_sensors = mallocarray(sc->sc_nunits, sizeof(struct ksensor),
M_DEVBUF, M_WAITOK|M_CANFAIL|M_ZERO);
if (sc->sc_sensors == NULL)
return (1);
Index: ic/ar5008.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ar5008.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 ar5008.c
--- ic/ar5008.c 12 Jul 2014 18:48:17 -0000 1.24
+++ ic/ar5008.c 13 Jul 2014 16:23:54 -0000
@@ -569,7 +569,7 @@ ar5008_rx_alloc(struct athn_softc *sc)
bus_size_t size;
int error, nsegs, i;
- rxq->bf = malloc(ATHN_NRXBUFS * sizeof(*bf), M_DEVBUF,
+ rxq->bf = mallocarray(ATHN_NRXBUFS, sizeof(*bf), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (rxq->bf == NULL)
return (ENOMEM);
Index: ic/ar5xxx.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ar5xxx.c,v
retrieving revision 1.57
diff -u -p -u -r1.57 ar5xxx.c
--- ic/ar5xxx.c 12 Jul 2014 18:48:17 -0000 1.57
+++ ic/ar5xxx.c 13 Jul 2014 16:21:47 -0000
@@ -388,7 +388,7 @@ ath_hal_init_channels(struct ath_hal *ha
u_int domain_5ghz, domain_2ghz;
HAL_CHANNEL *all_channels;
- if ((all_channels = malloc(sizeof(HAL_CHANNEL) * max_channels,
+ if ((all_channels = mallocarray(max_channels, sizeof(HAL_CHANNEL),
M_TEMP, M_NOWAIT | M_ZERO)) == NULL)
return (AH_FALSE);
Index: ic/ar9003.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ar9003.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 ar9003.c
--- ic/ar9003.c 12 Jul 2014 18:48:17 -0000 1.28
+++ ic/ar9003.c 13 Jul 2014 16:21:34 -0000
@@ -725,7 +725,8 @@ ar9003_rx_alloc(struct athn_softc *sc, i
struct ar_rx_status *ds;
int error, i;
- rxq->bf = malloc(count * sizeof(*bf), M_DEVBUF, M_NOWAIT | M_ZERO);
+ rxq->bf = mallocarray(count, sizeof(*bf), M_DEVBUF,
+ M_NOWAIT | M_ZERO);
if (rxq->bf == NULL)
return (ENOMEM);
Index: ic/cac.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/cac.c,v
retrieving revision 1.51
diff -u -p -u -r1.51 cac.c
--- ic/cac.c 12 Jul 2014 18:48:17 -0000 1.51
+++ ic/cac.c 13 Jul 2014 16:20:57 -0000
@@ -230,8 +230,8 @@ cac_init(struct cac_softc *sc, int start
}
sc->sc_nunits = cinfo.num_drvs;
- sc->sc_dinfos = malloc(cinfo.num_drvs * sizeof(struct cac_drive_info),
- M_DEVBUF, M_NOWAIT | M_ZERO);
+ sc->sc_dinfos = mallocarray(cinfo.num_drvs,
+ sizeof(struct cac_drive_info), M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_dinfos == NULL) {
printf("%s: cannot allocate memory for drive_info\n",
sc->sc_dv.dv_xname);
@@ -911,8 +911,8 @@ cac_create_sensors(struct cac_softc *sc)
if (ssc == NULL)
return (1);
- sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_nunits,
- M_DEVBUF, M_NOWAIT | M_ZERO);
+ sc->sc_sensors = mallocarray(sc->sc_nunits,
+ sizeof(struct ksensor), M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_sensors == NULL)
return (1);
Index: ic/ciss.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ciss.c,v
retrieving revision 1.69
diff -u -p -u -r1.69 ciss.c
--- ic/ciss.c 12 Jul 2014 18:48:17 -0000 1.69
+++ ic/ciss.c 13 Jul 2014 16:20:29 -0000
@@ -347,7 +347,7 @@ ciss_attach(struct ciss_softc *sc)
return -1;
}
- if (!(sc->sc_lds = malloc(sc->maxunits * sizeof(*sc->sc_lds),
+ if (!(sc->sc_lds = mallocarray(sc->maxunits, sizeof(*sc->sc_lds),
M_DEVBUF, M_NOWAIT | M_ZERO))) {
bus_dmamem_free(sc->dmat, sc->cmdseg, 1);
bus_dmamap_destroy(sc->dmat, sc->cmdmap);
@@ -385,7 +385,7 @@ ciss_attach(struct ciss_softc *sc)
sc->sc_flags |= CISS_BIO;
#ifndef SMALL_KERNEL
- sc->sensors = malloc(sizeof(struct ksensor) * sc->maxunits,
+ sc->sensors = mallocarray(sc->maxunits, sizeof(struct ksensor),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sensors) {
struct device *dev;
@@ -1311,7 +1311,7 @@ ciss_pdscan(struct ciss_softc *sc, int l
if (!k)
return NULL;
- ldp = malloc(sizeof(*ldp) + (k-1), M_DEVBUF, M_NOWAIT);
+ ldp = mallocarray(k-1, sizeof(*ldp), M_DEVBUF, M_NOWAIT);
if (!ldp)
return NULL;
Index: ic/lance.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/lance.c,v
retrieving revision 1.2
diff -u -p -u -r1.2 lance.c
--- ic/lance.c 26 Nov 2013 09:50:33 -0000 1.2
+++ ic/lance.c 13 Jul 2014 16:19:27 -0000
@@ -247,9 +247,9 @@ lance_config(struct lance_softc *sc)
if_attach(ifp);
ether_ifattach(ifp);
- sc->sc_rbufaddr = malloc(sc->sc_nrbuf * sizeof(int), M_DEVBUF,
+ sc->sc_rbufaddr = mallocarray(sc->sc_nrbuf, sizeof(int), M_DEVBUF,
M_WAITOK);
- sc->sc_tbufaddr = malloc(sc->sc_ntbuf * sizeof(int), M_DEVBUF,
+ sc->sc_tbufaddr = mallocarray(sc->sc_ntbuf, sizeof(int), M_DEVBUF,
M_WAITOK);
}
Index: ic/malo.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/malo.c,v
retrieving revision 1.99
diff -u -p -u -r1.99 malo.c
--- ic/malo.c 12 Jul 2014 18:48:17 -0000 1.99
+++ ic/malo.c 13 Jul 2014 16:19:17 -0000
@@ -575,8 +575,8 @@ malo_alloc_rx_ring(struct malo_softc *sc
ring->physaddr = ring->map->dm_segs->ds_addr;
- ring->data = malloc(count * sizeof (struct malo_rx_data), M_DEVBUF,
- M_NOWAIT);
+ ring->data = mallocarray(count, sizeof (struct malo_rx_data),
+ M_DEVBUF, M_NOWAIT);
if (ring->data == NULL) {
printf("%s: could not allocate soft data\n",
sc->sc_dev.dv_xname);
@@ -734,8 +734,8 @@ malo_alloc_tx_ring(struct malo_softc *sc
ring->physaddr = ring->map->dm_segs->ds_addr;
- ring->data = malloc(count * sizeof(struct malo_tx_data), M_DEVBUF,
- M_NOWAIT);
+ ring->data = mallocarray(count, sizeof(struct malo_tx_data),
+ M_DEVBUF, M_NOWAIT);
if (ring->data == NULL) {
printf("%s: could not allocate soft data\n",
sc->sc_dev.dv_xname);
Index: ic/mfi.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/mfi.c,v
retrieving revision 1.153
diff -u -p -u -r1.153 mfi.c
--- ic/mfi.c 12 Jul 2014 18:48:17 -0000 1.153
+++ ic/mfi.c 13 Jul 2014 16:18:47 -0000
@@ -246,7 +246,7 @@ mfi_init_ccb(struct mfi_softc *sc)
DNPRINTF(MFI_D_CCB, "%s: mfi_init_ccb\n", DEVNAME(sc));
- sc->sc_ccb = malloc(sizeof(struct mfi_ccb) * sc->sc_max_cmds,
+ sc->sc_ccb = mallocarray(sc->sc_max_cmds, sizeof(struct mfi_ccb),
M_DEVBUF, M_WAITOK|M_ZERO);
for (i = 0; i < sc->sc_max_cmds; i++) {
@@ -2127,7 +2127,7 @@ mfi_create_sensors(struct mfi_softc *sc)
sizeof(sc->sc_sensordev.xname));
if (ISSET(letoh32(sc->sc_info.mci_adapter_ops ), MFI_INFO_AOPS_BBU)) {
- sc->sc_bbu = malloc(sizeof(*sc->sc_bbu) * 4,
+ sc->sc_bbu = mallocarray(4, sizeof(*sc->sc_bbu),
M_DEVBUF, M_WAITOK | M_ZERO);
sc->sc_bbu[0].type = SENSOR_INDICATOR;
@@ -2162,7 +2162,7 @@ mfi_create_sensors(struct mfi_softc *sc)
}
}
- sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_ld_cnt,
+ sc->sc_sensors = mallocarray(sc->sc_ld_cnt, sizeof(struct ksensor),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_sensors == NULL)
return (1);
Index: ic/mpi.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/mpi.c,v
retrieving revision 1.192
diff -u -p -u -r1.192 mpi.c
--- ic/mpi.c 12 Jul 2014 18:48:17 -0000 1.192
+++ ic/mpi.c 13 Jul 2014 16:13:02 -0000
@@ -340,8 +340,8 @@ mpi_attach(struct mpi_softc *sc)
DEVNAME(sc));
}
- sc->sc_vol_page = malloc(sc->sc_cfg_hdr.page_length * 4,
- M_TEMP, M_WAITOK | M_CANFAIL);
+ sc->sc_vol_page =
mallocarray(sc->sc_cfg_hdr.page_length,
+ 4, M_TEMP, M_WAITOK | M_CANFAIL);
if (sc->sc_vol_page == NULL) {
panic("%s: can't get memory for IOC page 2, "
"bio disabled", DEVNAME(sc));
@@ -1050,7 +1050,7 @@ mpi_alloc_ccbs(struct mpi_softc *sc)
SLIST_INIT(&sc->sc_ccb_free);
mtx_init(&sc->sc_ccb_mtx, IPL_BIO);
- sc->sc_ccbs = malloc(sizeof(struct mpi_ccb) * sc->sc_maxcmds,
+ sc->sc_ccbs = mallocarray(sc->sc_maxcmds, sizeof(struct mpi_ccb),
M_DEVBUF, M_WAITOK | M_CANFAIL | M_ZERO);
if (sc->sc_ccbs == NULL) {
printf("%s: unable to allocate ccbs\n", DEVNAME(sc));
@@ -1156,7 +1156,7 @@ mpi_alloc_replies(struct mpi_softc *sc)
{
DNPRINTF(MPI_D_MISC, "%s: mpi_alloc_replies\n", DEVNAME(sc));
- sc->sc_rcbs = malloc(sc->sc_repq * sizeof(struct mpi_rcb), M_DEVBUF,
+ sc->sc_rcbs = mallocarray(sc->sc_repq, sizeof(struct mpi_rcb), M_DEVBUF,
M_WAITOK|M_CANFAIL);
if (sc->sc_rcbs == NULL)
return (1);
@@ -3430,7 +3430,7 @@ mpi_create_sensors(struct mpi_softc *sc)
if (vol == 0)
return (0);
- sc->sc_sensors = malloc(sizeof(struct ksensor) * vol,
+ sc->sc_sensors = mallocarray(vol, sizeof(struct ksensor),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_sensors == NULL)
return (1);
Index: ic/nvme.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/nvme.c,v
retrieving revision 1.5
diff -u -p -u -r1.5 nvme.c
--- ic/nvme.c 12 Jul 2014 18:48:17 -0000 1.5
+++ ic/nvme.c 13 Jul 2014 16:12:08 -0000
@@ -511,7 +511,7 @@ nvme_ccbs_alloc(struct nvme_softc *sc, u
struct nvme_ccb *ccb;
u_int i;
- sc->sc_ccbs = malloc(sizeof(*ccb) * nccbs, M_DEVBUF,
+ sc->sc_ccbs = mallocarray(nccbs, sizeof(*ccb), M_DEVBUF,
M_WAITOK | M_CANFAIL);
if (sc->sc_ccbs == NULL)
return (1);
Index: ic/oosiop.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/oosiop.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 oosiop.c
--- ic/oosiop.c 8 Jul 2014 17:19:25 -0000 1.21
+++ ic/oosiop.c 13 Jul 2014 16:11:57 -0000
@@ -292,7 +292,7 @@ oosiop_alloc_cb(struct oosiop_softc *sc,
/*
* Allocate oosiop_cb.
*/
- cb = malloc(sizeof(*cb) * ncb, M_DEVBUF, M_NOWAIT | M_ZERO);
+ cb = mallocarray(ncb, sizeof(*cb), M_DEVBUF, M_NOWAIT | M_ZERO);
if (cb == NULL) {
printf(": failed to allocate cb memory\n");
return (ENOMEM);
Index: ic/osiop.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/osiop.c,v
retrieving revision 1.48
diff -u -p -u -r1.48 osiop.c
--- ic/osiop.c 23 Jun 2011 16:31:16 -0000 1.48
+++ ic/osiop.c 13 Jul 2014 16:11:47 -0000
@@ -267,7 +267,7 @@ osiop_attach(sc)
/*
* Allocate (malloc) memory for acb's.
*/
- acb = malloc(sizeof(*acb) * OSIOP_NACB, M_DEVBUF, M_NOWAIT | M_ZERO);
+ acb = mallocarray(OSIOP_NACB, sizeof(*acb), M_DEVBUF, M_NOWAIT |
M_ZERO);
if (acb == NULL) {
printf(": can't allocate memory for acb\n");
return;
Index: ic/qla.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/qla.c,v
retrieving revision 1.42
diff -u -p -u -r1.42 qla.c
--- ic/qla.c 12 Jul 2014 18:48:17 -0000 1.42
+++ ic/qla.c 13 Jul 2014 16:02:02 -0000
@@ -2547,7 +2547,7 @@ qla_alloc_ccbs(struct qla_softc *sc)
mtx_init(&sc->sc_port_mtx, IPL_BIO);
mtx_init(&sc->sc_mbox_mtx, IPL_BIO);
- sc->sc_ccbs = malloc(sizeof(struct qla_ccb) * sc->sc_maxcmds,
+ sc->sc_ccbs = mallocarray(sizeof(struct qla_ccb), sc->sc_maxcmds,
M_DEVBUF, M_WAITOK | M_CANFAIL | M_ZERO);
if (sc->sc_ccbs == NULL) {
printf("%s: unable to allocate ccbs\n", DEVNAME(sc));
Index: ic/qlw.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/qlw.c,v
retrieving revision 1.23
diff -u -p -u -r1.23 qlw.c
--- ic/qlw.c 12 Jul 2014 18:48:17 -0000 1.23
+++ ic/qlw.c 13 Jul 2014 16:01:53 -0000
@@ -1699,7 +1699,7 @@ qlw_alloc_ccbs(struct qlw_softc *sc)
mtx_init(&sc->sc_ccb_mtx, IPL_BIO);
mtx_init(&sc->sc_queue_mtx, IPL_BIO);
- sc->sc_ccbs = malloc(sizeof(struct qlw_ccb) * sc->sc_maxccbs,
+ sc->sc_ccbs = mallocarray(sizeof(struct qlw_ccb), sc->sc_maxccbs,
M_DEVBUF, M_WAITOK | M_CANFAIL | M_ZERO);
if (sc->sc_ccbs == NULL) {
printf("%s: unable to allocate ccbs\n", DEVNAME(sc));
Index: ic/rt2560.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/rt2560.c,v
retrieving revision 1.64
diff -u -p -u -r1.64 rt2560.c
--- ic/rt2560.c 12 Jul 2014 18:48:17 -0000 1.64
+++ ic/rt2560.c 13 Jul 2014 16:01:43 -0000
@@ -388,8 +388,8 @@ rt2560_alloc_tx_ring(struct rt2560_softc
ring->physaddr = ring->map->dm_segs->ds_addr;
- ring->data = malloc(count * sizeof (struct rt2560_tx_data), M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ring->data = mallocarray(count, sizeof (struct rt2560_tx_data),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
printf("%s: could not allocate soft data\n",
sc->sc_dev.dv_xname);
@@ -532,8 +532,8 @@ rt2560_alloc_rx_ring(struct rt2560_softc
ring->physaddr = ring->map->dm_segs->ds_addr;
- ring->data = malloc(count * sizeof (struct rt2560_rx_data), M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ring->data = mallocarray(count, sizeof (struct rt2560_rx_data),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
printf("%s: could not allocate soft data\n",
sc->sc_dev.dv_xname);
Index: ic/rt2661.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/rt2661.c,v
retrieving revision 1.73
diff -u -p -u -r1.73 rt2661.c
--- ic/rt2661.c 12 Jul 2014 18:48:17 -0000 1.73
+++ ic/rt2661.c 13 Jul 2014 16:01:15 -0000
@@ -473,8 +473,8 @@ rt2661_alloc_tx_ring(struct rt2661_softc
ring->physaddr = ring->map->dm_segs->ds_addr;
- ring->data = malloc(count * sizeof (struct rt2661_tx_data), M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ring->data = mallocarray(count, sizeof (struct rt2661_tx_data),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
printf("%s: could not allocate soft data\n",
sc->sc_dev.dv_xname);
@@ -614,8 +614,8 @@ rt2661_alloc_rx_ring(struct rt2661_softc
ring->physaddr = ring->map->dm_segs->ds_addr;
- ring->data = malloc(count * sizeof (struct rt2661_rx_data), M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ring->data = mallocarray(count, sizeof (struct rt2661_rx_data),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
printf("%s: could not allocate soft data\n",
sc->sc_dev.dv_xname);
Index: ic/rtw.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/rtw.c,v
retrieving revision 1.86
diff -u -p -u -r1.86 rtw.c
--- ic/rtw.c 12 Jul 2014 18:48:17 -0000 1.86
+++ ic/rtw.c 13 Jul 2014 16:00:49 -0000
@@ -3614,7 +3614,7 @@ rtw_txsoft_blk_setup(struct rtw_txsoft_b
SIMPLEQ_INIT(&tsb->tsb_dirtyq);
SIMPLEQ_INIT(&tsb->tsb_freeq);
tsb->tsb_ndesc = qlen;
- tsb->tsb_desc = malloc(qlen * sizeof(*tsb->tsb_desc), M_DEVBUF,
+ tsb->tsb_desc = mallocarray(qlen, sizeof(*tsb->tsb_desc), M_DEVBUF,
M_NOWAIT);
if (tsb->tsb_desc == NULL)
return ENOMEM;
Index: ic/sili.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/sili.c,v
retrieving revision 1.52
diff -u -p -u -r1.52 sili.c
--- ic/sili.c 12 Jul 2014 18:48:17 -0000 1.52
+++ ic/sili.c 13 Jul 2014 16:00:36 -0000
@@ -748,7 +748,7 @@ sili_ports_alloc(struct sili_softc *sc)
struct sili_port *sp;
int i;
- sc->sc_ports = malloc(sizeof(struct sili_port) * sc->sc_nports,
+ sc->sc_ports = mallocarray(sc->sc_nports, sizeof(struct sili_port),
M_DEVBUF, M_WAITOK | M_ZERO);
for (i = 0; i < sc->sc_nports; i++) {
@@ -808,7 +808,7 @@ sili_ccb_alloc(struct sili_port *sp)
TAILQ_INIT(&sp->sp_active_ccbs);
TAILQ_INIT(&sp->sp_deferred_ccbs);
- sp->sp_ccbs = malloc(sizeof(struct sili_ccb) * SILI_MAX_CMDS,
+ sp->sp_ccbs = mallocarray(SILI_MAX_CMDS, sizeof(struct sili_ccb),
M_DEVBUF, M_WAITOK);
sp->sp_cmds = sili_dmamem_alloc(sc, SILI_CMD_LEN * SILI_MAX_CMDS,
SILI_PRB_ALIGN);
Index: ic/siop.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/siop.c,v
retrieving revision 1.67
diff -u -p -u -r1.67 siop.c
--- ic/siop.c 12 Jul 2014 18:48:17 -0000 1.67
+++ ic/siop.c 13 Jul 2014 16:00:11 -0000
@@ -1833,7 +1833,7 @@ siop_morecbd(sc)
}
/* allocate cmd list */
- newcbd->cmds = malloc(sizeof(struct siop_cmd) * SIOP_NCMDPB,
+ newcbd->cmds = mallocarray(sizeof(struct siop_cmd), SIOP_NCMDPB,
M_DEVBUF, M_NOWAIT | M_ZERO);
if (newcbd->cmds == NULL) {
printf("%s: can't allocate memory for command descriptors\n",
Index: ic/vga.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/vga.c,v
retrieving revision 1.62
diff -u -p -u -r1.62 vga.c
--- ic/vga.c 12 Jul 2014 18:48:17 -0000 1.62
+++ ic/vga.c 13 Jul 2014 15:59:48 -0000
@@ -663,9 +663,8 @@ vga_alloc_screen(void *v, const struct w
* XXX We could be more clever and use video RAM.
*/
scr = LIST_FIRST(&vc->screens);
- scr->pcs.mem =
- malloc(scr->pcs.type->ncols * scr->pcs.type->nrows * 2,
- M_DEVBUF, M_WAITOK);
+ scr->pcs.mem = mallocarray(scr->pcs.type->ncols,
+ scr->pcs.type->nrows * 2, M_DEVBUF, M_WAITOK);
}
scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
@@ -676,8 +675,8 @@ vga_alloc_screen(void *v, const struct w
vc->active = scr;
vc->currenttype = type;
} else {
- scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
- M_DEVBUF, M_WAITOK);
+ scr->pcs.mem = mallocarray(type->ncols,
+ type->nrows * 2, M_DEVBUF, M_WAITOK);
pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
}
Index: ic/z8530tty.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/z8530tty.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 z8530tty.c
--- ic/z8530tty.c 21 Apr 2013 14:44:16 -0000 1.24
+++ ic/z8530tty.c 13 Jul 2014 15:51:21 -0000
@@ -342,7 +342,7 @@ zstty_attach(struct device *parent, stru
tp->t_hwiflow = zshwiflow;
zst->zst_tty = tp;
- zst->zst_rbuf = malloc(zstty_rbuf_size << 1, M_DEVBUF, M_WAITOK);
+ zst->zst_rbuf = mallocarray(zstty_rbuf_size, 2, M_DEVBUF, M_WAITOK);
zst->zst_ebuf = zst->zst_rbuf + (zstty_rbuf_size << 1);
/* Disable the high water mark. */
zst->zst_r_hiwat = 0;
Index: pci/agp.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp.c,v
retrieving revision 1.44
diff -u -p -u -r1.44 agp.c
--- pci/agp.c 12 Jul 2014 18:48:51 -0000 1.44
+++ pci/agp.c 13 Jul 2014 17:27:38 -0000
@@ -398,7 +398,7 @@ agp_generic_bind_memory(struct agp_softc
*/
nseg = (mem->am_size + PAGE_SIZE - 1) / PAGE_SIZE;
- segs = malloc(nseg * sizeof *segs, M_AGP, M_WAITOK);
+ segs = mallocarray(nseg, sizeof *segs, M_AGP, M_WAITOK);
if ((error = bus_dmamem_alloc(sc->sc_dmat, mem->am_size, PAGE_SIZE, 0,
segs, nseg, &mem->am_nseg, BUS_DMA_ZERO | BUS_DMA_WAITOK)) != 0) {
free(segs, M_AGP, 0);
Index: pci/arc.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/arc.c,v
retrieving revision 1.102
diff -u -p -u -r1.102 arc.c
--- pci/arc.c 12 Jul 2014 18:48:51 -0000 1.102
+++ pci/arc.c 13 Jul 2014 17:27:21 -0000
@@ -2618,7 +2618,7 @@ arc_create_sensors(void *xsc, void *arg)
}
sc->sc_nsensors = bi.bi_novol;
- sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_nsensors,
+ sc->sc_sensors = mallocarray(sc->sc_nsensors, sizeof(struct ksensor),
M_DEVBUF, M_WAITOK | M_ZERO);
strlcpy(sc->sc_sensordev.xname, DEVNAME(sc),
Index: pci/azalia.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/azalia.c,v
retrieving revision 1.214
diff -u -p -u -r1.214 azalia.c
--- pci/azalia.c 12 Jul 2014 18:48:51 -0000 1.214
+++ pci/azalia.c 13 Jul 2014 17:26:40 -0000
@@ -829,7 +829,7 @@ azalia_get_ctrlr_caps(azalia_t *az)
printf("%s: no HD-Audio codecs\n", XNAME(az));
return -1;
}
- az->codecs = malloc(sizeof(codec_t) * az->ncodecs, M_DEVBUF,
+ az->codecs = mallocarray(az->ncodecs, sizeof(codec_t), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (az->codecs == NULL) {
printf("%s: can't allocate memory for codecs\n", XNAME(az));
@@ -1631,7 +1631,8 @@ azalia_codec_init(codec_t *this)
return -1;
}
this->wend = this->wstart + COP_NSUBNODES(result);
- this->w = malloc(sizeof(widget_t) * this->wend, M_DEVBUF, M_NOWAIT |
M_ZERO);
+ this->w = mallocarray(this->wend, sizeof(widget_t), M_DEVBUF,
+ M_NOWAIT | M_ZERO);
if (this->w == NULL) {
printf("%s: out of memory\n", XNAME(this->az));
return ENOMEM;
@@ -2054,7 +2055,7 @@ azalia_codec_sort_pins(codec_t *this)
}
}
- this->opins = malloc(nopins * sizeof(struct io_pin), M_DEVBUF,
+ this->opins = mallocarray(nopins, sizeof(struct io_pin), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (this->opins == NULL)
return(ENOMEM);
@@ -2072,7 +2073,7 @@ azalia_codec_sort_pins(codec_t *this)
break;
}
- this->opins_d = malloc(nopins_d * sizeof(struct io_pin), M_DEVBUF,
+ this->opins_d = mallocarray(nopins_d, sizeof(struct io_pin), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (this->opins_d == NULL)
return(ENOMEM);
@@ -2090,7 +2091,7 @@ azalia_codec_sort_pins(codec_t *this)
break;
}
- this->ipins = malloc(nipins * sizeof(struct io_pin), M_DEVBUF,
+ this->ipins = mallocarray(nipins, sizeof(struct io_pin), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (this->ipins == NULL)
return(ENOMEM);
@@ -2108,7 +2109,7 @@ azalia_codec_sort_pins(codec_t *this)
break;
}
- this->ipins_d = malloc(nipins_d * sizeof(struct io_pin), M_DEVBUF,
+ this->ipins_d = mallocarray(nipins_d, sizeof(struct io_pin), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (this->ipins_d == NULL)
return(ENOMEM);
@@ -2161,7 +2162,7 @@ azalia_codec_select_dacs(codec_t *this)
int nconv, conv;
int i, j, k, err;
- convs = malloc(this->na_dacs * sizeof(nid_t), M_DEVBUF,
+ convs = mallocarray(this->na_dacs, sizeof(nid_t), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (convs == NULL)
return(ENOMEM);
@@ -2724,7 +2725,7 @@ azalia_codec_construct_format(codec_t *t
if (this->formats != NULL)
free(this->formats, M_DEVBUF, 0);
this->nformats = 0;
- this->formats = malloc(sizeof(struct audio_format) * variation,
+ this->formats = mallocarray(variation, sizeof(struct audio_format),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (this->formats == NULL) {
printf("%s: out of memory in %s\n",
@@ -3411,7 +3412,7 @@ azalia_widget_init_connection(widget_t *
}
}
- this->connections = malloc(sizeof(nid_t) * nconn, M_DEVBUF, M_NOWAIT);
+ this->connections = mallocarray(nconn, sizeof(nid_t), M_DEVBUF,
M_NOWAIT);
if (this->connections == NULL) {
printf("%s: out of memory\n", XNAME(codec->az));
return ENOMEM;
@@ -4427,7 +4428,7 @@ azalia_create_encodings(codec_t *this)
if (this->encs != NULL)
free(this->encs, M_DEVBUF, 0);
this->nencs = 0;
- this->encs = malloc(sizeof(struct audio_encoding) * nencs,
+ this->encs = mallocarray(nencs, sizeof(struct audio_encoding),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (this->encs == NULL) {
printf("%s: out of memory in %s\n",
Index: pci/azalia_codec.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/azalia_codec.c,v
retrieving revision 1.162
diff -u -p -u -r1.162 azalia_codec.c
--- pci/azalia_codec.c 12 Jul 2014 18:48:51 -0000 1.162
+++ pci/azalia_codec.c 13 Jul 2014 17:23:13 -0000
@@ -658,7 +658,7 @@ azalia_mixer_init(codec_t *this)
this->maxmixers = 10;
this->nmixers = 0;
- this->mixers = malloc(sizeof(mixer_item_t) * this->maxmixers,
+ this->mixers = mallocarray(this->maxmixers, sizeof(mixer_item_t),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (this->mixers == NULL) {
printf("%s: out of memory in %s\n", XNAME(this), __func__);
@@ -1252,7 +1252,8 @@ azalia_mixer_ensure_capacity(codec_t *th
newmax = this->maxmixers + 10;
if (newmax < newsize)
newmax = newsize;
- newbuf = malloc(sizeof(mixer_item_t) * newmax, M_DEVBUF, M_NOWAIT |
M_ZERO);
+ newbuf = mallocarray(newmax, sizeof(mixer_item_t), M_DEVBUF,
+ M_NOWAIT | M_ZERO);
if (newbuf == NULL) {
printf("%s: out of memory in %s\n", XNAME(this), __func__);
return ENOMEM;
Index: pci/cz.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/cz.c,v
retrieving revision 1.19
diff -u -p -u -r1.19 cz.c
--- pci/cz.c 26 Mar 2012 16:23:22 -0000 1.19
+++ pci/cz.c 13 Jul 2014 17:22:42 -0000
@@ -388,8 +388,8 @@ cz_attach(parent, self, aux)
return;
}
- cz->cz_ports = malloc(sizeof(struct cztty_softc) * cz->cz_nchannels,
- M_DEVBUF, M_WAITOK | M_ZERO);
+ cz->cz_ports = mallocarray(cz->cz_nchannels,
+ sizeof(struct cztty_softc), M_DEVBUF, M_WAITOK | M_ZERO);
cztty_attached_ttys += cz->cz_nchannels;
for (i = 0; i < cz->cz_nchannels; i++) {
Index: pci/emuxki.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/emuxki.c,v
retrieving revision 1.45
diff -u -p -u -r1.45 emuxki.c
--- pci/emuxki.c 12 Jul 2014 18:48:51 -0000 1.45
+++ pci/emuxki.c 13 Jul 2014 17:22:20 -0000
@@ -293,7 +293,7 @@ emuxki_dmamem_alloc(bus_dma_tag_t dmat,
mem->nsegs = nsegs;
mem->bound = 0;
- mem->segs = malloc(mem->nsegs * sizeof(*(mem->segs)), type, flags);
+ mem->segs = mallocarray(mem->nsegs, sizeof(*(mem->segs)), type, flags);
if (mem->segs == NULL) {
free(mem, type, 0);
return (NULL);
Index: pci/hifn7751.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/hifn7751.c,v
retrieving revision 1.168
diff -u -p -u -r1.168 hifn7751.c
--- pci/hifn7751.c 12 Jul 2014 18:48:51 -0000 1.168
+++ pci/hifn7751.c 13 Jul 2014 17:21:58 -0000
@@ -1847,8 +1847,8 @@ hifn_newsession(u_int32_t *sidp, struct
if (ses == NULL) {
sesn = sc->sc_nsessions;
- ses = (struct hifn_session *)malloc((sesn + 1) *
- sizeof(*ses), M_DEVBUF, M_NOWAIT);
+ ses = mallocarray((sesn + 1), sizeof(*ses),
+ M_DEVBUF, M_NOWAIT);
if (ses == NULL)
return (ENOMEM);
bcopy(sc->sc_sessions, ses, sesn * sizeof(*ses));
Index: pci/if_em.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_em.c,v
retrieving revision 1.286
diff -u -p -u -r1.286 if_em.c
--- pci/if_em.c 12 Jul 2014 18:48:51 -0000 1.286
+++ pci/if_em.c 13 Jul 2014 17:19:37 -0000
@@ -2119,8 +2119,8 @@ em_dma_free(struct em_softc *sc, struct
int
em_allocate_transmit_structures(struct em_softc *sc)
{
- if (!(sc->tx_buffer_area = malloc(sizeof(struct em_buffer) *
- sc->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->tx_buffer_area = mallocarray(sc->num_tx_desc,
+ sizeof(struct em_buffer), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate tx_buffer memory\n",
sc->sc_dv.dv_xname);
return (ENOMEM);
@@ -2553,8 +2553,8 @@ em_allocate_receive_structures(struct em
int i, error;
struct em_buffer *rx_buffer;
- if (!(sc->rx_buffer_area = malloc(sizeof(struct em_buffer) *
- sc->num_rx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->rx_buffer_area = mallocarray(sc->num_rx_desc,
+ sizeof(struct em_buffer), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate rx_buffer memory\n",
sc->sc_dv.dv_xname);
return (ENOMEM);
Index: pci/if_ix.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.95
diff -u -p -u -r1.95 if_ix.c
--- pci/if_ix.c 12 Jul 2014 18:48:51 -0000 1.95
+++ pci/if_ix.c 13 Jul 2014 17:18:38 -0000
@@ -1703,25 +1703,22 @@ ixgbe_allocate_queues(struct ix_softc *s
int txconf = 0, rxconf = 0, i;
/* First allocate the top level queue structs */
- if (!(sc->queues =
- (struct ix_queue *) malloc(sizeof(struct ix_queue) *
- sc->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->queues = mallocarray(sc->num_queues,
+ sizeof(struct ix_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate queue memory\n", ifp->if_xname);
goto fail;
}
/* Then allocate the TX ring struct memory */
- if (!(sc->tx_rings =
- (struct tx_ring *) malloc(sizeof(struct tx_ring) *
- sc->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->tx_rings = mallocarray(sc->num_queues,
+ sizeof(struct tx_ring), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate TX ring memory\n",
ifp->if_xname);
goto fail;
}
/* Next allocate the RX */
- if (!(sc->rx_rings =
- (struct rx_ring *) malloc(sizeof(struct rx_ring) *
- sc->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->rx_rings = mallocarray(sc->num_queues,
+ sizeof(struct rx_ring), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate RX ring memory\n",
ifp->if_xname);
goto rx_fail;
}
@@ -1814,9 +1811,8 @@ ixgbe_allocate_transmit_buffers(struct t
struct ixgbe_tx_buf *txbuf;
int error, i;
- if (!(txr->tx_buffers =
- (struct ixgbe_tx_buf *) malloc(sizeof(struct ixgbe_tx_buf) *
- sc->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(txr->tx_buffers = mallocarray(sc->num_tx_desc,
+ sizeof(struct ixgbe_tx_buf), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate tx_buffer memory\n",
ifp->if_xname);
error = ENOMEM;
Index: pci/if_ixgb.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_ixgb.c,v
retrieving revision 1.61
diff -u -p -u -r1.61 if_ixgb.c
--- pci/if_ixgb.c 12 Jul 2014 18:48:51 -0000 1.61
+++ pci/if_ixgb.c 13 Jul 2014 17:17:15 -0000
@@ -1135,8 +1135,8 @@ ixgb_dma_free(struct ixgb_softc *sc, str
int
ixgb_allocate_transmit_structures(struct ixgb_softc *sc)
{
- if (!(sc->tx_buffer_area = malloc(sizeof(struct ixgb_buffer) *
- sc->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->tx_buffer_area = mallocarray(sc->num_tx_desc,
+ sizeof(struct ixgb_buffer), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate tx_buffer memory\n",
sc->sc_dv.dv_xname);
return (ENOMEM);
@@ -1501,8 +1501,8 @@ ixgb_allocate_receive_structures(struct
int i, error;
struct ixgb_buffer *rx_buffer;
- if (!(sc->rx_buffer_area = malloc(sizeof(struct ixgb_buffer) *
- sc->num_rx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+ if (!(sc->rx_buffer_area = mallocarray(sc->num_rx_desc,
+ sizeof(struct ixgb_buffer), M_DEVBUF, M_NOWAIT | M_ZERO))) {
printf("%s: Unable to allocate rx_buffer memory\n",
sc->sc_dv.dv_xname);
return (ENOMEM);
Index: pci/if_nxe.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_nxe.c,v
retrieving revision 1.65
diff -u -p -u -r1.65 if_nxe.c
--- pci/if_nxe.c 12 Jul 2014 18:48:51 -0000 1.65
+++ pci/if_nxe.c 13 Jul 2014 17:16:40 -0000
@@ -1926,7 +1926,7 @@ nxe_pkt_alloc(struct nxe_softc *sc, u_in
int i;
npl = malloc(sizeof(*npl), M_DEVBUF, M_WAITOK | M_ZERO);
- pkt = malloc(sizeof(*pkt) * npkts, M_DEVBUF, M_WAITOK | M_ZERO);
+ pkt = mallocarray(npkts, sizeof(*pkt), M_DEVBUF, M_WAITOK | M_ZERO);
npl->npl_pkts = pkt;
TAILQ_INIT(&npl->npl_free);
Index: pci/if_tht.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_tht.c,v
retrieving revision 1.127
diff -u -p -u -r1.127 if_tht.c
--- pci/if_tht.c 12 Jul 2014 18:48:52 -0000 1.127
+++ pci/if_tht.c 13 Jul 2014 17:14:41 -0000
@@ -1879,8 +1879,8 @@ tht_pkt_alloc(struct tht_softc *sc, stru
struct tht_pkt *pkt;
int i;
- tpl->tpl_pkts = malloc(sizeof(struct tht_pkt) * npkts, M_DEVBUF,
- M_WAITOK | M_ZERO);
+ tpl->tpl_pkts = mallocarray(npkts, sizeof(struct tht_pkt),
+ M_DEVBUF, M_WAITOK | M_ZERO);
TAILQ_INIT(&tpl->tpl_free);
TAILQ_INIT(&tpl->tpl_used);
Index: pci/if_txp.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_txp.c,v
retrieving revision 1.109
diff -u -p -u -r1.109 if_txp.c
--- pci/if_txp.c 12 Jul 2014 18:48:52 -0000 1.109
+++ pci/if_txp.c 13 Jul 2014 17:15:50 -0000
@@ -1585,9 +1585,8 @@ txp_response(struct txp_softc *sc, u_int
rsp = (struct txp_rsp_desc *)(((u_int8_t *)sc->sc_rspring.base)
+ ridx);
if (id == letoh16(rsp->rsp_id) && letoh16(rsp->rsp_seq) == seq)
{
- *rspp = (struct txp_rsp_desc *)malloc(
- sizeof(struct txp_rsp_desc) * (rsp->rsp_numdesc +
1),
- M_DEVBUF, M_NOWAIT);
+ *rspp = mallocarray(rsp->rsp_numdesc + 1,
+ sizeof(struct txp_rsp_desc), M_DEVBUF, M_NOWAIT);
if ((*rspp) == NULL)
return (-1);
txp_rsp_fixup(sc, rsp, *rspp);
Index: pci/if_vic.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_vic.c,v
retrieving revision 1.80
diff -u -p -u -r1.80 if_vic.c
--- pci/if_vic.c 12 Jul 2014 18:48:52 -0000 1.80
+++ pci/if_vic.c 13 Jul 2014 17:13:57 -0000
@@ -567,15 +567,15 @@ vic_alloc_data(struct vic_softc *sc)
sc->sc_rxq[1].pktlen = 4096;
for (q = 0; q < VIC_NRXRINGS; q++) {
- sc->sc_rxq[q].bufs = malloc(sizeof(struct vic_rxbuf) *
- sc->sc_nrxbuf, M_DEVBUF, M_NOWAIT | M_ZERO);
+ sc->sc_rxq[q].bufs = mallocarray(sc->sc_nrxbuf,
+ sizeof(struct vic_rxbuf), M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_rxq[q].bufs == NULL) {
printf(": unable to allocate rxbuf for ring %d\n", q);
goto freerx;
}
}
- sc->sc_txbuf = malloc(sizeof(struct vic_txbuf) * sc->sc_ntxbuf,
+ sc->sc_txbuf = mallocarray(sc->sc_ntxbuf, sizeof(struct vic_txbuf),
M_DEVBUF, M_NOWAIT);
if (sc->sc_txbuf == NULL) {
printf(": unable to allocate txbuf\n");
Index: pci/ips.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/ips.c,v
retrieving revision 1.109
diff -u -p -u -r1.109 ips.c
--- pci/ips.c 12 Jul 2014 18:48:52 -0000 1.109
+++ pci/ips.c 13 Jul 2014 17:12:16 -0000
@@ -796,7 +796,7 @@ ips_attach(struct device *parent, struct
#ifndef SMALL_KERNEL
/* Add sensors */
- if ((sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_nunits,
+ if ((sc->sc_sensors = mallocarray(sc->sc_nunits, sizeof(struct ksensor),
M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
printf(": can't alloc sensors\n");
return;
@@ -1981,7 +1981,7 @@ ips_ccb_alloc(struct ips_softc *sc, int
struct ips_ccb *ccb;
int i;
- if ((ccb = malloc(n * sizeof(*ccb), M_DEVBUF,
+ if ((ccb = mallocarray(n, sizeof(*ccb), M_DEVBUF,
M_NOWAIT | M_ZERO)) == NULL)
return (NULL);
Index: pci/isp_pci.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/isp_pci.c,v
retrieving revision 1.60
diff -u -p -u -r1.60 isp_pci.c
--- pci/isp_pci.c 12 Jul 2014 18:48:52 -0000 1.60
+++ pci/isp_pci.c 13 Jul 2014 17:11:58 -0000
@@ -560,7 +560,7 @@ isp_pci_attach(struct device *parent, st
if (pa->pa_id == PCI_QLOGIC_ISP1240) {
isp->isp_mdvec = &mdvec_1080;
isp->isp_type = ISP_HA_SCSI_1240;
- isp->isp_param = malloc(2 * sizeof(sdparam), M_DEVBUF,
+ isp->isp_param = mallocarray(2, sizeof(sdparam), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (isp->isp_param == NULL) {
printf(nomem);
@@ -572,7 +572,7 @@ isp_pci_attach(struct device *parent, st
if (pa->pa_id == PCI_QLOGIC_ISP1280) {
isp->isp_mdvec = &mdvec_1080;
isp->isp_type = ISP_HA_SCSI_1280;
- isp->isp_param = malloc(2 * sizeof(sdparam),
+ isp->isp_param = mallocarray(2, sizeof(sdparam),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (isp->isp_param == NULL) {
printf(nomem);
@@ -596,7 +596,7 @@ isp_pci_attach(struct device *parent, st
if (pa->pa_id == PCI_QLOGIC_ISP12160) {
isp->isp_mdvec = &mdvec_12160;
isp->isp_type = ISP_HA_SCSI_12160;
- isp->isp_param = malloc(2 * sizeof(sdparam),
+ isp->isp_param = mallocarray(2, sizeof(sdparam),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (isp->isp_param == NULL) {
printf(nomem);
Index: pci/mfii.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/mfii.c,v
retrieving revision 1.16
diff -u -p -u -r1.16 mfii.c
--- pci/mfii.c 12 Jul 2014 18:48:52 -0000 1.16
+++ pci/mfii.c 13 Jul 2014 17:14:54 -0000
@@ -1382,7 +1382,7 @@ mfii_init_ccb(struct mfii_softc *sc)
u_int i;
int error;
- sc->sc_ccb = malloc(sizeof(struct mfii_ccb) * sc->sc_max_cmds,
+ sc->sc_ccb = mallocarray(sc->sc_max_cmds, sizeof(struct mfii_ccb),
M_DEVBUF, M_WAITOK|M_ZERO);
for (i = 0; i < sc->sc_max_cmds; i++) {
Index: pci/mpii.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/mpii.c,v
retrieving revision 1.95
diff -u -p -u -r1.95 mpii.c
--- pci/mpii.c 12 Jul 2014 18:48:52 -0000 1.95
+++ pci/mpii.c 13 Jul 2014 17:11:02 -0000
@@ -553,7 +553,7 @@ mpii_attach(struct device *parent, struc
}
}
- sc->sc_devs = malloc(sc->sc_max_devices *
+ sc->sc_devs = mallocarray(sc->sc_max_devices,
sizeof(struct mpii_device *), M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_devs == NULL) {
printf("%s: unable to allocate memory for mpii_device\n",
@@ -2366,7 +2366,7 @@ mpii_alloc_ccbs(struct mpii_softc *sc)
scsi_ioh_set(&sc->sc_ccb_tmo_handler, &sc->sc_iopool,
mpii_scsi_cmd_tmo_handler, sc);
- sc->sc_ccbs = malloc(sizeof(*ccb) * (sc->sc_max_cmds-1),
+ sc->sc_ccbs = mallocarray((sc->sc_max_cmds-1), sizeof(*ccb),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_ccbs == NULL) {
printf("%s: unable to allocate ccbs\n", DEVNAME(sc));
@@ -2471,8 +2471,8 @@ mpii_alloc_replies(struct mpii_softc *sc
{
DNPRINTF(MPII_D_MISC, "%s: mpii_alloc_replies\n", DEVNAME(sc));
- sc->sc_rcbs = malloc(sc->sc_num_reply_frames * sizeof(struct mpii_rcb),
- M_DEVBUF, M_NOWAIT);
+ sc->sc_rcbs = mallocarray(sc->sc_num_reply_frames,
+ sizeof(struct mpii_rcb), M_DEVBUF, M_NOWAIT);
if (sc->sc_rcbs == NULL)
return (1);
@@ -3530,7 +3530,7 @@ mpii_create_sensors(struct mpii_softc *s
struct scsi_link *link;
int i;
- sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_vd_count,
+ sc->sc_sensors = mallocarray(sc->sc_vd_count, sizeof(struct ksensor),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_sensors == NULL)
return (1);
Index: pci/musycc.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/musycc.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 musycc.c
--- pci/musycc.c 19 May 2010 15:27:35 -0000 1.21
+++ pci/musycc.c 13 Jul 2014 17:10:25 -0000
@@ -115,8 +115,8 @@ musycc_attach_common(struct musycc_softc
MUSYCC_CONF_BLAPSE_SET(3) | MUSYCC_CONF_INTB;
/* initialize group descriptors */
- sc->mc_groups = malloc(sc->mc_ngroups * sizeof(struct musycc_group),
- M_DEVBUF, M_NOWAIT | M_ZERO);
+ sc->mc_groups = mallocarray(sc->mc_ngroups,
+ sizeof(struct musycc_group), M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->mc_groups == NULL) {
printf(": couldn't alloc group descriptors\n");
musycc_free_groupdesc(sc);
Index: pci/qle.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/qle.c,v
retrieving revision 1.30
diff -u -p -u -r1.30 qle.c
--- pci/qle.c 12 Jul 2014 18:48:52 -0000 1.30
+++ pci/qle.c 13 Jul 2014 17:09:53 -0000
@@ -2844,7 +2844,7 @@ qle_alloc_ccbs(struct qle_softc *sc)
mtx_init(&sc->sc_port_mtx, IPL_BIO);
mtx_init(&sc->sc_mbox_mtx, IPL_BIO);
- sc->sc_ccbs = malloc(sizeof(struct qle_ccb) * sc->sc_maxcmds,
+ sc->sc_ccbs = mallocarray(sc->sc_maxcmds, sizeof(struct qle_ccb),
M_DEVBUF, M_WAITOK | M_CANFAIL | M_ZERO);
if (sc->sc_ccbs == NULL) {
printf("%s: unable to allocate ccbs\n", DEVNAME(sc));
Index: pci/safe.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/safe.c,v
retrieving revision 1.36
diff -u -p -u -r1.36 safe.c
--- pci/safe.c 12 Jul 2014 18:48:52 -0000 1.36
+++ pci/safe.c 13 Jul 2014 17:09:39 -0000
@@ -1344,7 +1344,7 @@ safe_newsession(u_int32_t *sidp, struct
if (ses == NULL) {
sesn = sc->sc_nsessions;
- ses = (struct safe_session *)malloc((sesn + 1) *
+ ses = mallocarray((sesn + 1),
sizeof(struct safe_session), M_DEVBUF, M_NOWAIT);
if (ses == NULL)
return (ENOMEM);
Index: pci/sdhc_pci.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/sdhc_pci.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 sdhc_pci.c
--- pci/sdhc_pci.c 4 Jan 2013 23:19:40 -0000 1.14
+++ pci/sdhc_pci.c 13 Jul 2014 17:08:15 -0000
@@ -158,8 +158,8 @@ sdhc_pci_attach(struct device *parent, s
nslots = SDHC_PCI_NUM_SLOTS(slotinfo);
/* Allocate an array big enough to hold all the possible hosts */
- sc->sc.sc_host = malloc(sizeof(struct sdhc_host *) * nslots, M_DEVBUF,
- M_WAITOK);
+ sc->sc.sc_host = mallocarray(nslots, sizeof(struct sdhc_host *),
+ M_DEVBUF, M_WAITOK);
/* XXX: handle 64-bit BARs */
for (reg = SDHC_PCI_BAR_START + SDHC_PCI_FIRST_BAR(slotinfo) *
Index: pci/ubsec.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/ubsec.c,v
retrieving revision 1.158
diff -u -p -u -r1.158 ubsec.c
--- pci/ubsec.c 12 Jul 2014 18:48:52 -0000 1.158
+++ pci/ubsec.c 13 Jul 2014 16:44:28 -0000
@@ -693,7 +693,7 @@ ubsec_newsession(u_int32_t *sidp, struct
if (ses == NULL) {
sesn = sc->sc_nsessions;
- ses = (struct ubsec_session *)malloc((sesn + 1) *
+ ses = mallocarray((sesn + 1),
sizeof(struct ubsec_session), M_DEVBUF, M_NOWAIT);
if (ses == NULL)
return (ENOMEM);
Index: pci/virtio.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/virtio.c,v
retrieving revision 1.8
diff -u -p -u -r1.8 virtio.c
--- pci/virtio.c 12 Jul 2014 18:48:52 -0000 1.8
+++ pci/virtio.c 13 Jul 2014 16:43:39 -0000
@@ -379,8 +379,8 @@ virtio_alloc_vq(struct virtio_softc *sc,
vq->vq_maxnsegs = maxnsegs;
/* free slot management */
- vq->vq_entries = malloc(sizeof(struct vq_entry)*vq_size,
- M_DEVBUF, M_NOWAIT | M_ZERO);
+ vq->vq_entries = mallocarray(vq_size, sizeof(struct vq_entry),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (vq->vq_entries == NULL) {
r = ENOMEM;
goto err;
Index: pci/vmwpvs.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/vmwpvs.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 vmwpvs.c
--- pci/vmwpvs.c 12 Jul 2014 18:48:52 -0000 1.9
+++ pci/vmwpvs.c 13 Jul 2014 16:43:25 -0000
@@ -507,7 +507,8 @@ vmwpvs_attach(struct device *parent, str
goto free_sgl;
}
- sc->sc_ccbs = malloc(sizeof(struct vmwpvs_ccb) * r, M_DEVBUF, M_WAITOK);
+ sc->sc_ccbs = mallocarray(r, sizeof(struct vmwpvs_ccb),
+ M_DEVBUF, M_WAITOK);
/* cant fail */
sgls = VMWPVS_DMA_KVA(sc->sc_sgls);