summaryrefslogtreecommitdiff
path: root/sys/dev/usb
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/usb')
-rw-r--r--sys/dev/usb/uaudio.c13
-rw-r--r--sys/dev/usb/uhidev.c4
-rw-r--r--sys/dev/usb/usb_subr.c9
3 files changed, 15 insertions, 11 deletions
diff --git a/sys/dev/usb/uaudio.c b/sys/dev/usb/uaudio.c
index 893190dd1ae..3a81988f685 100644
--- a/sys/dev/usb/uaudio.c
+++ b/sys/dev/usb/uaudio.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -649,12 +649,14 @@ uaudio_mixer_add_ctl(struct uaudio_softc *sc, struct mixerctl *mc)
} 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));
@@ -1524,12 +1526,13 @@ uaudio_add_alt(struct uaudio_softc *sc, const struct as_info *ai)
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));
diff --git a/sys/dev/usb/uhidev.c b/sys/dev/usb/uhidev.c
index c4ef58db6cd..7144b5f7094 100644
--- a/sys/dev/usb/uhidev.c
+++ b/sys/dev/usb/uhidev.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -215,7 +215,7 @@ uhidev_attach(struct device *parent, struct device *self, void *aux)
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));
diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c
index c9f48b13ccb..606e795c6ce 100644
--- a/sys/dev/usb/usb_subr.c
+++ b/sys/dev/usb/usb_subr.c
@@ -1,4 +1,4 @@
-/* $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 $ */
@@ -894,7 +894,7 @@ usbd_probe_and_attach(struct device *parent, struct usbd_device *dev, int port,
}
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;
@@ -905,13 +905,14 @@ usbd_probe_and_attach(struct device *parent, struct usbd_device *dev, int port,
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))