-/* $OpenBSD: tc_dma_3000_500.c,v 1.5 2009/02/01 14:34:02 miod Exp $ */
+/* $OpenBSD: tc_dma_3000_500.c,v 1.6 2014/12/13 21:05:32 doug Exp $ */
/* $NetBSD: tc_dma_3000_500.c,v 1.13 2001/07/19 06:40:03 thorpej Exp $ */
/*-
int nslots;
{
extern struct alpha_bus_dma_tag tc_dmat_direct;
- size_t sisize;
int i;
/* Allocate per-slot DMA info. */
- sisize = nslots * sizeof(struct tc_dma_slot_info);
- tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_NOWAIT | M_ZERO);
+ tc_dma_slot_info = mallocarray(nslots, sizeof(struct tc_dma_slot_info),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (tc_dma_slot_info == NULL)
panic("tc_dma_init: can't allocate per-slot DMA info");
-/* $OpenBSD: ampintc.c,v 1.4 2014/10/08 14:53:36 rapha Exp $ */
+/* $OpenBSD: ampintc.c,v 1.5 2014/12/13 21:05:32 doug Exp $ */
/*
* Copyright (c) 2007,2009,2011 Dale Rahn <drahn@openbsd.org>
*
/* XXX - check power saving bit */
- sc->sc_ampintc_handler = malloc(
- (sizeof (*sc->sc_ampintc_handler) * nintr),
- M_DEVBUF, M_ZERO | M_NOWAIT);
+ sc->sc_ampintc_handler = mallocarray(nintr,
+ sizeof(*sc->sc_ampintc_handler), M_DEVBUF, M_ZERO | M_NOWAIT);
for (i = 0; i < nintr; i++) {
TAILQ_INIT(&sc->sc_ampintc_handler[i].iq_list);
}
-/* $OpenBSD: impact.c,v 1.6 2014/07/12 18:44:42 tedu Exp $ */
+/* $OpenBSD: impact.c,v 1.7 2014/12/13 21:05:32 doug Exp $ */
/*
* Copyright (c) 2010, 2012 Miodrag Vallat.
impact_init_screen(struct impact_screen *scr)
{
struct rasops_info *ri = &scr->ri;
- size_t bssize;
int i;
uint32_t c, r, g, b;
* be able to fulfill scrolling requests.
*/
if (scr->bs == NULL) {
- bssize = ri->ri_rows * ri->ri_cols *
- sizeof(struct wsdisplay_charcell);
- scr->bs = malloc(bssize, M_DEVBUF, M_NOWAIT | M_ZERO);
+ scr->bs = mallocarray(ri->ri_rows,
+ ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
+ M_NOWAIT | M_ZERO);
if (scr->bs == NULL)
return ENOMEM;
}
-/* $OpenBSD: aic79xx.c,v 1.54 2014/07/13 23:10:23 deraadt Exp $ */
+/* $OpenBSD: aic79xx.c,v 1.55 2014/12/13 21:05:33 doug Exp $ */
/*
* Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom
ahd->num_critical_sections = cs_count;
if (cs_count != 0) {
-
- cs_count *= sizeof(struct cs);
- ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
+ ahd->critical_sections = mallocarray(cs_count,
+ sizeof(struct cs), M_DEVBUF, M_NOWAIT);
if (ahd->critical_sections == NULL)
panic("ahd_loadseq: Could not malloc");
+ cs_count *= sizeof(struct cs);
+
memcpy(ahd->critical_sections, cs_table, cs_count);
}
ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
-/* $OpenBSD: aic7xxx.c,v 1.88 2014/07/13 23:10:23 deraadt Exp $ */
+/* $OpenBSD: aic7xxx.c,v 1.89 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: aic7xxx.c,v 1.108 2003/11/02 11:07:44 wiz Exp $ */
/*
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
- * $Id: aic7xxx.c,v 1.88 2014/07/13 23:10:23 deraadt Exp $
+ * $Id: aic7xxx.c,v 1.89 2014/12/13 21:05:33 doug Exp $
*/
/*
* Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
ahc->num_critical_sections = cs_count;
if (cs_count != 0) {
-
- cs_count *= sizeof(struct cs);
- ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
+ ahc->critical_sections = mallocarray(cs_count,
+ sizeof(struct cs), M_DEVBUF, M_NOWAIT);
if (ahc->critical_sections == NULL)
panic("ahc_loadseq: Could not malloc");
+ cs_count *= sizeof(struct cs);
+
memcpy(ahc->critical_sections, cs_table, cs_count);
}
ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
-/* $OpenBSD: if_ix.c,v 1.111 2014/11/27 15:49:13 brad Exp $ */
+/* $OpenBSD: if_ix.c,v 1.112 2014/12/13 21:05:33 doug Exp $ */
/******************************************************************************
u_int n = 0;
if (sc->num_queues > 1) {
- if ((ifr = malloc(sc->num_queues * sizeof(*ifr), M_DEVBUF,
+ if ((ifr = mallocarray(sc->num_queues, sizeof(*ifr), M_DEVBUF,
M_WAITOK | M_ZERO)) == NULL)
return (ENOMEM);
} else
-/* $OpenBSD: if_oce.c,v 1.79 2014/08/30 09:48:23 dlg Exp $ */
+/* $OpenBSD: if_oce.c,v 1.80 2014/12/13 21:05:33 doug Exp $ */
/*
* Copyright (c) 2012 Mike Belopuhov
u_int n = 0;
if (sc->sc_nrq > 1) {
- if ((ifr = malloc(sc->sc_nrq * sizeof(*ifr), M_DEVBUF,
+ if ((ifr = mallocarray(sc->sc_nrq, sizeof(*ifr), M_DEVBUF,
M_WAITOK | M_ZERO)) == NULL)
return (ENOMEM);
} else
-/* $OpenBSD: if_vio.c,v 1.20 2014/12/06 10:09:10 sf Exp $ */
+/* $OpenBSD: if_vio.c,v 1.21 2014/12/13 21:05:33 doug Exp $ */
/*
* Copyright (c) 2012 Stefan Fritsch, Alexander Fiveg.
sc->sc_ctrl_mac_tbl_mc = (void*)(kva + offset);
}
- allocsize = (rxqsize + txqsize) *
- (2 * sizeof(bus_dmamap_t) + sizeof(struct mbuf *));
- sc->sc_arrays = malloc(allocsize, M_DEVBUF, M_WAITOK|M_CANFAIL|M_ZERO);
+ sc->sc_arrays = mallocarray(rxqsize + txqsize,
+ 2 * sizeof(bus_dmamap_t) + sizeof(struct mbuf *), M_DEVBUF,
+ M_WAITOK | M_CANFAIL | M_ZERO);
if (sc->sc_arrays == NULL) {
printf("unable to allocate mem for dmamaps\n");
goto err_hdr;
}
+ allocsize = (rxqsize + txqsize) *
+ (2 * sizeof(bus_dmamap_t) + sizeof(struct mbuf *));
sc->sc_tx_dmamaps = sc->sc_arrays + rxqsize;
sc->sc_rx_mbufs = (void*) (sc->sc_tx_dmamaps + txqsize);
-/* $OpenBSD: isp_pci.c,v 1.61 2014/07/13 23:10:23 deraadt Exp $ */
+/* $OpenBSD: isp_pci.c,v 1.62 2014/12/13 21:05:33 doug Exp $ */
/* $FreeBSD: src/sys/dev/isp/isp_pci.c,v 1.148 2007/06/26 23:08:57 mjacob Exp $*/
/*-
* Copyright (c) 1997-2006 by Matthew Jacob
if (isp->isp_rquest_dma) /* been here before? */
return (0);
- len = isp->isp_maxcmds * sizeof (XS_T *);
- isp->isp_xflist = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
+ isp->isp_xflist = mallocarray(isp->isp_maxcmds, sizeof(XS_T *),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (isp->isp_xflist == NULL) {
isp_prt(isp, ISP_LOGERR, "cannot malloc xflist array");
return (1);
}
- len = isp->isp_maxcmds * sizeof (bus_dmamap_t);
- pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_NOWAIT);
+ len = isp->isp_maxcmds * sizeof(XS_T *);
+
+ pcs->pci_xfer_dmap = mallocarray(isp->isp_maxcmds, sizeof(bus_dmamap_t),
+ M_DEVBUF, M_NOWAIT);
if (pcs->pci_xfer_dmap == NULL) {
free(isp->isp_xflist, M_DEVBUF, 0);
isp->isp_xflist = NULL;
isp_prt(isp, ISP_LOGERR, "cannot malloc dma map array");
return (1);
}
+ len = isp->isp_maxcmds * sizeof(bus_dmamap_t);
for (i = 0; i < isp->isp_maxcmds; i++) {
if (bus_dmamap_create(dmat, MAXPHYS, (MAXPHYS / NBPG) + 1,
-/* $OpenBSD: cfxga.c,v 1.28 2014/07/12 18:48:52 tedu Exp $ */
+/* $OpenBSD: cfxga.c,v 1.29 2014/12/13 21:05:33 doug Exp $ */
/*
* Copyright (c) 2005, 2006, Matthieu Herrb and Miodrag Vallat
* Allocate backing store to remember non-visible screen contents in
* emulation mode.
*/
- scrsize = ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell);
- scr->scr_mem = malloc(scrsize, M_DEVBUF,
+ scr->scr_mem = mallocarray(ri->ri_rows,
+ ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
(cold ? M_NOWAIT : M_WAITOK) | M_ZERO);
if (scr->scr_mem == NULL) {
free(scr, M_DEVBUF, 0);
return (ENOMEM);
}
+ scrsize = ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell);
ri->ri_ops.copycols = cfxga_copycols;
ri->ri_ops.copyrows = cfxga_copyrows;
-/* $OpenBSD: rasops.c,v 1.34 2014/11/20 10:37:21 landry Exp $ */
+/* $OpenBSD: rasops.c,v 1.35 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: rasops.c,v 1.35 2001/02/02 06:01:01 marcus Exp $ */
/*-
if (scr == NULL)
return (ENOMEM);
- size = ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell);
- scr->rs_bs = malloc(size, M_DEVBUF, M_NOWAIT);
+ scr->rs_bs = mallocarray(ri->ri_rows,
+ ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
+ M_NOWAIT);
if (scr->rs_bs == NULL) {
free(scr, M_DEVBUF, 0);
return (ENOMEM);
}
+ size = ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell);
*cookiep = scr;
*curxp = 0;
-/* $OpenBSD: uaudio.c,v 1.107 2014/12/09 07:05:06 doug Exp $ */
+/* $OpenBSD: uaudio.c,v 1.108 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: uaudio.c,v 1.90 2004/10/29 17:12:53 kent Exp $ */
/*
} else {
DPRINTF(("%s: adding %s\n", __func__, mc->ctlname));
}
- len = sizeof(*mc) * (sc->sc_nctls + 1);
- nmc = malloc(len, M_USBDEV, M_NOWAIT);
+
+ nmc = mallocarray(sc->sc_nctls + 1, sizeof(*mc), M_USBDEV, M_NOWAIT);
if (nmc == NULL) {
printf("uaudio_mixer_add_ctl: no memory\n");
return;
}
+ len = sizeof(*mc) * (sc->sc_nctls + 1);
+
/* Copy old data, if there was any */
if (sc->sc_nctls != 0) {
bcopy(sc->sc_ctls, nmc, sizeof(*mc) * (sc->sc_nctls));
size_t len;
struct as_info *nai;
- len = sizeof(*ai) * (sc->sc_nalts + 1);
- nai = malloc(len, M_USBDEV, M_NOWAIT);
+ nai = mallocarray(sc->sc_nalts + 1, sizeof(*ai), M_USBDEV, M_NOWAIT);
if (nai == NULL) {
printf("uaudio_add_alt: no memory\n");
return;
}
+ len = sizeof(*ai) * (sc->sc_nalts + 1);
+
/* Copy old data, if there was any */
if (sc->sc_nalts != 0) {
bcopy(sc->sc_alts, nai, sizeof(*ai) * (sc->sc_nalts));
-/* $OpenBSD: uhidev.c,v 1.65 2014/12/11 18:39:27 mpi Exp $ */
+/* $OpenBSD: uhidev.c,v 1.66 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: uhidev.c,v 1.14 2003/03/11 16:44:00 augustss Exp $ */
/*
printf(", %d report id%s", nrepid, nrepid > 1 ? "s" : "");
printf("\n");
nrepid++;
- sc->sc_subdevs = malloc(nrepid * sizeof(struct uhidev *),
+ sc->sc_subdevs = mallocarray(nrepid, sizeof(struct uhidev *),
M_USBDEV, M_NOWAIT | M_ZERO);
if (sc->sc_subdevs == NULL) {
printf("%s: no memory\n", DEVNAME(sc));
-/* $OpenBSD: usb_subr.c,v 1.114 2014/12/09 07:05:06 doug Exp $ */
+/* $OpenBSD: usb_subr.c,v 1.115 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
}
nifaces = dev->cdesc->bNumInterface;
uaa.configno = dev->cdesc->bConfigurationValue;
- ifaces = malloc(nifaces * sizeof(*ifaces), M_USB, M_NOWAIT);
+ ifaces = mallocarray(nifaces, sizeof(*ifaces), M_USB, M_NOWAIT);
if (ifaces == NULL) {
err = USBD_NOMEM;
goto fail;
uaa.nifaces = nifaces;
/* add 1 for possible ugen and 1 for NULL terminator */
- len = (nifaces + 2) * sizeof dv;
- dev->subdevs = malloc(len, M_USB, M_NOWAIT | M_ZERO);
+ dev->subdevs = mallocarray(nifaces + 2, sizeof(dv), M_USB,
+ M_NOWAIT | M_ZERO);
if (dev->subdevs == NULL) {
free(ifaces, M_USB, 0);
err = USBD_NOMEM;
goto fail;
}
+ len = (nifaces + 2) * sizeof(dv);
for (i = 0; i < nifaces; i++) {
if (usbd_iface_claimed(dev, i))
-/* $OpenBSD: vnd.c,v 1.154 2014/10/17 02:05:06 tedu Exp $ */
+/* $OpenBSD: vnd.c,v 1.155 2014/12/13 21:05:32 doug Exp $ */
/* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */
/*
vndattach(int num)
{
char *mem;
- u_long size;
int i;
if (num <= 0)
return;
- size = num * sizeof(struct vnd_softc);
- mem = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
+ mem = mallocarray(num, sizeof(struct vnd_softc), M_DEVBUF,
+ M_NOWAIT | M_ZERO);
if (mem == NULL) {
printf("WARNING: no memory for vnode disks\n");
return;
-/* $OpenBSD: wskbd.c,v 1.80 2014/07/12 18:48:53 tedu Exp $ */
+/* $OpenBSD: wskbd.c,v 1.81 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: wskbd.c,v 1.80 2005/05/04 01:52:16 augustss Exp $ */
/*
if (umdp->maplen > WSKBDIO_MAXMAPLEN)
return (EINVAL);
+ buf = mallocarray(umdp->maplen, sizeof(struct wscons_keymap),
+ M_TEMP, M_WAITOK);
len = umdp->maplen * sizeof(struct wscons_keymap);
- buf = malloc(len, M_TEMP, M_WAITOK);
+
error = copyin(umdp->map, buf, len);
if (error == 0) {
wskbd_init_keymap(umdp->maplen,
-/* $OpenBSD: wsfont.c,v 1.37 2014/12/07 13:07:18 miod Exp $ */
+/* $OpenBSD: wsfont.c,v 1.38 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: wsfont.c,v 1.17 2001/02/07 13:59:24 ad Exp $ */
/*-
/* Allocate a buffer big enough for the rotated font. */
newstride = (font->fontheight + 7) / 8;
- newbits = malloc(newstride * font->fontwidth * font->numchars,
+ newbits = mallocarray(font->numchars, newstride * font->fontwidth,
M_DEVBUF, M_WAITOK | M_ZERO);
/* Rotate the font a bit at a time. */
-/* $OpenBSD: sched_bsd.c,v 1.39 2014/11/12 22:27:45 tedu Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.40 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
return;
if (!idleticks)
- if (!(idleticks = malloc(sizeof(*idleticks) * ncpusfound,
+ if (!(idleticks = mallocarray(ncpusfound, sizeof(*idleticks),
M_DEVBUF, M_NOWAIT | M_ZERO)))
return;
if (!totalticks)
- if (!(totalticks = malloc(sizeof(*totalticks) * ncpusfound,
+ if (!(totalticks = mallocarray(ncpusfound, sizeof(*totalticks),
M_DEVBUF, M_NOWAIT | M_ZERO))) {
free(idleticks, M_DEVBUF,
sizeof(*idleticks) * ncpusfound);
-/* $OpenBSD: subr_log.c,v 1.24 2014/12/10 02:44:47 tedu Exp $ */
+/* $OpenBSD: subr_log.c,v 1.25 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
auio.uio_resid = aiov.iov_len;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO)) {
+ ktriov = mallocarray(auio.uio_iovcnt, sizeof(struct iovec),
+ M_TEMP, M_WAITOK);
iovlen = auio.uio_iovcnt * sizeof (struct iovec);
- ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
memcpy(ktriov, auio.uio_iov, iovlen);
}
#endif
-/* $OpenBSD: uipc_syscalls.c,v 1.96 2014/12/11 19:21:57 tedu Exp $ */
+/* $OpenBSD: uipc_syscalls.c,v 1.97 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
control = 0;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO)) {
+ ktriov = mallocarray(auio.uio_iovcnt, sizeof(struct iovec),
+ M_TEMP, M_WAITOK);
iovlen = auio.uio_iovcnt * sizeof (struct iovec);
- ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
memcpy(ktriov, auio.uio_iov, iovlen);
}
#endif
}
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO)) {
+ ktriov = mallocarray(auio.uio_iovcnt, sizeof(struct iovec),
+ M_TEMP, M_WAITOK);
iovlen = auio.uio_iovcnt * sizeof (struct iovec);
- ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
memcpy(ktriov, auio.uio_iov, iovlen);
}
#endif
-/* $OpenBSD: if_enc.c,v 1.58 2014/12/08 10:46:14 mpi Exp $ */
+/* $OpenBSD: if_enc.c,v 1.59 2014/12/13 21:05:33 doug Exp $ */
/*
* Copyright (c) 2010 Reyk Floeter <reyk@vantronix.net>
}
if (unit == 0 || unit > enc_max_unit) {
+ if ((new = mallocarray(unit + 1, sizeof(struct ifnet *),
+ M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
+ return (ENOBUFS);
newlen = sizeof(struct ifnet *) * (unit + 1);
- if ((new = malloc(newlen, M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOBUFS);
if (enc_allifps != NULL) {
memcpy(new, enc_allifps,
sizeof(struct ifnet *) * (enc_max_unit + 1));
return (EINVAL);
if (id == 0 || id > enc_max_id) {
+ if ((new = mallocarray(id + 1, sizeof(struct ifnet *),
+ M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
+ return (ENOBUFS);
newlen = sizeof(struct ifnet *) * (id + 1);
- if ((new = malloc(newlen, M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
- return (ENOBUFS);
if (enc_ifps != NULL) {
memcpy(new, enc_ifps,
sizeof(struct ifnet *) * (enc_max_id + 1));
-/* $OpenBSD: if_ppp.c,v 1.78 2014/12/05 15:50:04 mpi Exp $ */
+/* $OpenBSD: if_ppp.c,v 1.79 2014/12/13 21:05:33 doug Exp $ */
/* $NetBSD: if_ppp.c,v 1.39 1997/05/17 21:11:59 christos Exp $ */
/*
if ((unsigned) nbp->bf_len > BPF_MAXINSNS)
return EINVAL;
newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
- if (newcodelen != 0) {
- newcode = malloc(newcodelen, M_DEVBUF, M_WAITOK);
+ if (nbp->bf_len != 0) {
+ newcode = mallocarray(nbp->bf_len, sizeof(struct bpf_insn),
+ M_DEVBUF, M_WAITOK);
if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
newcodelen)) != 0) {
free(newcode, M_DEVBUF, 0);