Errors will result in nice clean panic messages so we know what's wrong.
Reviewed by dhill visa natano jsg.
-/* $OpenBSD: ihidev.c,v 1.12 2016/04/23 09:40:28 kettenis Exp $ */
+/* $OpenBSD: ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */
/*
* HID-over-i2c driver
*
}
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_DEVBUF, 0);
+ free(sc->sc_ibuf, M_DEVBUF, sc->sc_isize);
sc->sc_ibuf = NULL;
}
-/* $OpenBSD: aac.c,v 1.67 2016/03/27 11:06:19 mpi Exp $ */
+/* $OpenBSD: aac.c,v 1.68 2017/04/08 02:57:24 deraadt Exp $ */
/*-
* Copyright (c) 2000 Michael Smith
exit_map:
bus_dmamem_free(sc->aac_dmat, &fm->aac_seg, fm->aac_nsegs);
exit_alloc:
- free(fm, M_DEVBUF, 0);
+ free(fm, M_DEVBUF, sizeof *fm);
exit:
AAC_LOCK_RELEASE(&sc->aac_io_lock);
return (error);
bus_dmamem_unmap(sc->aac_dmat, (caddr_t)fm->aac_fibs,
AAC_FIBMAP_SIZE);
bus_dmamem_free(sc->aac_dmat, &fm->aac_seg, fm->aac_nsegs);
- free(fm, M_DEVBUF, 0);
+ free(fm, M_DEVBUF, sizeof *fm);
}
}
-/* $OpenBSD: ami.c,v 1.232 2016/08/14 04:08:03 dlg Exp $ */
+/* $OpenBSD: ami.c,v 1.233 2017/04/08 02:57:24 deraadt Exp $ */
/*
* Copyright (c) 2001 Michael Shalayeff
done:
error = 0;
bail:
- free(p, M_DEVBUF, 0);
+ free(p, M_DEVBUF, sizeof *p);
dma_free(vpdbuf, sizeof(*vpdbuf));
dma_free(inqbuf, sizeof(*inqbuf));
-/* $OpenBSD: i82365.c,v 1.34 2015/08/15 19:29:00 miod Exp $ */
+/* $OpenBSD: i82365.c,v 1.35 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: i82365.c,v 1.10 1998/06/09 07:36:55 thorpej Exp $ */
/*
break;
if (pe2->pe_type == PCIC_EVENT_INSERTION) {
SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
- free(pe1, M_TEMP, 0);
+ free(pe1, M_TEMP, sizeof *pe1);
SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
- free(pe2, M_TEMP, 0);
+ free(pe2, M_TEMP, sizeof *pe2);
}
}
splx(s);
break;
if (pe2->pe_type == PCIC_EVENT_REMOVAL) {
SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
- free(pe1, M_TEMP, 0);
+ free(pe1, M_TEMP, sizeof *pe1);
SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
- free(pe2, M_TEMP, 0);
+ free(pe2, M_TEMP, sizeof *pe1);
}
}
splx(s);
default:
panic("pcic_event_thread: unknown event %d", pe->pe_type);
}
- free(pe, M_TEMP, 0);
+ free(pe, M_TEMP, sizeof *pe);
}
void
-/* $OpenBSD: nvme.c,v 1.53 2016/11/15 12:17:42 mpi Exp $ */
+/* $OpenBSD: nvme.c,v 1.54 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
free_sq:
nvme_dmamem_free(sc, q->q_sq_dmamem);
free:
- free(q, M_DEVBUF, 0);
+ free(q, M_DEVBUF, sizeof *q);
return (NULL);
}
nvme_dmamem_sync(sc, q->q_sq_dmamem, BUS_DMASYNC_POSTWRITE);
nvme_dmamem_free(sc, q->q_cq_dmamem);
nvme_dmamem_free(sc, q->q_sq_dmamem);
- free(q, M_DEVBUF, 0);
+ free(q, M_DEVBUF, sizeof *q);
}
int
destroy:
bus_dmamap_destroy(sc->sc_dmat, ndm->ndm_map);
ndmfree:
- free(ndm, M_DEVBUF, 0);
+ free(ndm, M_DEVBUF, sizeof *ndm);
return (NULL);
}
bus_dmamem_unmap(sc->sc_dmat, ndm->ndm_kva, ndm->ndm_size);
bus_dmamem_free(sc->sc_dmat, &ndm->ndm_seg, 1);
bus_dmamap_destroy(sc->sc_dmat, ndm->ndm_map);
- free(ndm, M_DEVBUF, 0);
+ free(ndm, M_DEVBUF, sizeof *ndm);
}
-/* $OpenBSD: rtw.c,v 1.97 2017/01/22 10:17:38 dlg Exp $ */
+/* $OpenBSD: rtw.c,v 1.98 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: rtw.c,v 1.29 2004/12/27 19:49:16 dyoung Exp $ */
/*-
fail8:
sr = &sc->sc_srom;
- sr->sr_size = 0;
if (sr->sr_content != NULL) {
- free(sr->sr_content, M_DEVBUF, 0);
+ free(sr->sr_content, M_DEVBUF, sr->sr_size);
sr->sr_content = NULL;
}
+ sr->sr_size = 0;
fail7:
rtw_rxdesc_dmamaps_destroy(sc->sc_dmat, &sc->sc_rxsoft[0],
-/* $OpenBSD: if_nxe.c,v 1.74 2017/01/22 10:17:38 dlg Exp $ */
+/* $OpenBSD: if_nxe.c,v 1.75 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
bus_dmamap_destroy(sc->sc_dmat, pkt->pkt_dmap);
free(npl->npl_pkts, M_DEVBUF, 0);
- free(npl, M_DEVBUF, 0);
+ free(npl, M_DEVBUF, sizeof *npl);
}
struct nxe_pkt *
destroy:
bus_dmamap_destroy(sc->sc_dmat, ndm->ndm_map);
ndmfree:
- free(ndm, M_DEVBUF, 0);
+ free(ndm, M_DEVBUF, sizeof *ndm);
return (NULL);
}
bus_dmamem_unmap(sc->sc_dmat, ndm->ndm_kva, ndm->ndm_size);
bus_dmamem_free(sc->sc_dmat, &ndm->ndm_seg, 1);
bus_dmamap_destroy(sc->sc_dmat, ndm->ndm_map);
- free(ndm, M_DEVBUF, 0);
+ free(ndm, M_DEVBUF, sizeof *ndm);
}
u_int32_t
-/* $OpenBSD: if_wpi.c,v 1.139 2017/03/08 12:02:41 mpi Exp $ */
+/* $OpenBSD: if_wpi.c,v 1.140 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2006-2008
{
struct wpi_fw_info *fw = &sc->fw;
const struct wpi_firmware_hdr *hdr;
- size_t size;
int error;
/* Read firmware image from filesystem. */
- if ((error = loadfirmware("wpi-3945abg", &fw->data, &size)) != 0) {
+ if ((error = loadfirmware("wpi-3945abg", &fw->data, &fw->datalen)) != 0) {
printf("%s: error, %d, could not read firmware %s\n",
sc->sc_dev.dv_xname, error, "wpi-3945abg");
return error;
}
- if (size < sizeof (*hdr)) {
+ if (fw->datalen < sizeof (*hdr)) {
printf("%s: truncated firmware header: %zu bytes\n",
- sc->sc_dev.dv_xname, size);
- free(fw->data, M_DEVBUF, size);
+ sc->sc_dev.dv_xname, fw->datalen);
+ free(fw->data, M_DEVBUF, fw->datalen);
return EINVAL;
}
/* Extract firmware header information. */
fw->boot.textsz > WPI_FW_BOOT_TEXT_MAXSZ ||
(fw->boot.textsz & 3) != 0) {
printf("%s: invalid firmware header\n", sc->sc_dev.dv_xname);
- free(fw->data, M_DEVBUF, size);
+ free(fw->data, M_DEVBUF, fw->datalen);
return EINVAL;
}
/* Check that all firmware sections fit. */
- if (size < sizeof (*hdr) + fw->main.textsz + fw->main.datasz +
+ if (fw->datalen < sizeof (*hdr) + fw->main.textsz + fw->main.datasz +
fw->init.textsz + fw->init.datasz + fw->boot.textsz) {
printf("%s: firmware file too short: %zu bytes\n",
- sc->sc_dev.dv_xname, size);
- free(fw->data, M_DEVBUF, size);
+ sc->sc_dev.dv_xname, fw->datalen);
+ free(fw->data, M_DEVBUF, fw->datalen);
return EINVAL;
}
/* Initialize hardware and upload firmware. */
error = wpi_hw_init(sc);
- free(sc->fw.data, M_DEVBUF, 0);
+ free(sc->fw.data, M_DEVBUF, sc->fw.datalen);
if (error != 0) {
printf("%s: could not initialize hardware\n",
sc->sc_dev.dv_xname);
-/* $OpenBSD: if_wpivar.h,v 1.26 2016/09/05 08:18:40 tedu Exp $ */
+/* $OpenBSD: if_wpivar.h,v 1.27 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2006-2008
struct wpi_fw_info {
u_char *data;
+ size_t datalen;
struct wpi_fw_part init;
struct wpi_fw_part main;
struct wpi_fw_part boot;
-/* $OpenBSD: mfii.c,v 1.42 2017/02/11 04:12:28 dlg Exp $ */
+/* $OpenBSD: mfii.c,v 1.43 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2012 David Gwynne <dlg@openbsd.org>
return (0);
free_pdsc:
- free(sc->sc_pd, M_DEVBUF, 0);
+ free(sc->sc_pd, M_DEVBUF, sizeof(*sc->sc_pd));
return (1);
}
destroy:
bus_dmamap_destroy(sc->sc_dmat, m->mdm_map);
mdmfree:
- free(m, M_DEVBUF, 0);
+ free(m, M_DEVBUF, sizeof *m);
return (NULL);
}
bus_dmamem_unmap(sc->sc_dmat, m->mdm_kva, m->mdm_size);
bus_dmamem_free(sc->sc_dmat, &m->mdm_seg, 1);
bus_dmamap_destroy(sc->sc_dmat, m->mdm_map);
- free(m, M_DEVBUF, 0);
+ free(m, M_DEVBUF, sizeof *m);
}
void
-/* $OpenBSD: mpii.c,v 1.110 2017/01/16 18:18:16 mikeb Exp $ */
+/* $OpenBSD: mpii.c,v 1.111 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2010, 2012 Mike Belopuhov
* Copyright (c) 2009 James Giannoules
dev->slot = sc->sc_vd_id_low;
dev->dev_handle = lemtoh16(&ce->vol_dev_handle);
if (mpii_insert_dev(sc, dev)) {
- free(dev, M_DEVBUF, 0);
+ free(dev, M_DEVBUF, sizeof *dev);
break;
}
sc->sc_vd_count++;
dev->expander = lemtoh16(&tcl->expander_handle);
if (mpii_insert_dev(sc, dev)) {
- free(dev, M_DEVBUF, 0);
+ free(dev, M_DEVBUF, sizeof *dev);
break;
}
DETACH_FORCE);
}
- free(dev, M_DEVBUF, 0);
+ free(dev, M_DEVBUF, sizeof *dev);
break;
}
}
destroy:
bus_dmamap_destroy(sc->sc_dmat, mdm->mdm_map);
mdmfree:
- free(mdm, M_DEVBUF, 0);
+ free(mdm, M_DEVBUF, sizeof *mdm);
return (NULL);
}
bus_dmamem_unmap(sc->sc_dmat, mdm->mdm_kva, mdm->mdm_size);
bus_dmamem_free(sc->sc_dmat, &mdm->mdm_seg, 1);
bus_dmamap_destroy(sc->sc_dmat, mdm->mdm_map);
- free(mdm, M_DEVBUF, 0);
+ free(mdm, M_DEVBUF, sizeof *mdm);
}
int
mpii_dmamem_free(sc, sc->sc_requests);
free_ccbs:
- free(sc->sc_ccbs, M_DEVBUF, 0);
+ free(sc->sc_ccbs, M_DEVBUF, (sc->sc_max_cmds-1) * sizeof(*ccb));
return (1);
}
sc->sc_replies = mpii_dmamem_alloc(sc, sc->sc_reply_size *
sc->sc_num_reply_frames);
if (sc->sc_replies == NULL) {
- free(sc->sc_rcbs, M_DEVBUF, 0);
+ free(sc->sc_rcbs, M_DEVBUF,
+ sc->sc_num_reply_frames * sizeof(struct mpii_rcb));
return (1);
}
scsi_io_put(&sc->sc_iopool, ccb);
done:
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (rv);
}
&hdr, 1, vpg, pagelen) != 0) {
printf("%s: unable to fetch raid volume page 0\n",
DEVNAME(sc));
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (EINVAL);
}
}
if ((rv = mpii_bio_hs(sc, NULL, 0, vpg->hot_spare_pool, &hcnt)) != 0) {
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (rv);
}
strlcpy(bv->bv_dev, scdev->dv_xname, sizeof(bv->bv_dev));
}
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (0);
}
&hdr, 1, vpg, pagelen) != 0) {
printf("%s: unable to fetch raid volume page 0\n",
DEVNAME(sc));
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (EINVAL);
}
int nvdsk = vpg->num_phys_disks;
int hsmap = vpg->hot_spare_pool;
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (mpii_bio_hs(sc, bd, nvdsk, hsmap, NULL));
}
bd->bd_diskid;
dn = pd->phys_disk_num;
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (mpii_bio_disk(sc, bd, dn));
}
MPII_PG_EXTENDED, &ehdr, 1, cpg, pagelen) != 0) {
printf("%s: unable to fetch raid config page 0\n",
DEVNAME(sc));
- free(cpg, M_TEMP, 0);
+ free(cpg, M_TEMP, pagelen);
return (EINVAL);
}
if (bd != NULL && bd->bd_diskid == nhs + nvdsk) {
u_int8_t dn = el->phys_disk_num;
- free(cpg, M_TEMP, 0);
+ free(cpg, M_TEMP, pagelen);
return (mpii_bio_disk(sc, bd, dn));
}
nhs++;
if (hscnt)
*hscnt = nhs;
- free(cpg, M_TEMP, 0);
+ free(cpg, M_TEMP, pagelen);
return (0);
}
&hdr, 1, ppg, sizeof(*ppg)) != 0) {
printf("%s: unable to fetch raid drive page 0\n",
DEVNAME(sc));
- free(ppg, M_TEMP, 0);
+ free(ppg, M_TEMP, sizeof(*ppg));
return (EINVAL);
}
if ((dev = mpii_find_dev(sc, lemtoh16(&ppg->dev_handle))) == NULL) {
bd->bd_status = BIOC_SDINVALID;
- free(ppg, M_TEMP, 0);
+ free(ppg, M_TEMP, sizeof(*ppg));
return (0);
}
sizeof(ppg->product_id));
scsi_strvis(bd->bd_serial, ppg->serial, sizeof(ppg->serial));
- free(ppg, M_TEMP, 0);
+ free(ppg, M_TEMP, sizeof(*ppg));
return (0);
}
MPII_PG_POLL, &hdr, 1, vpg, pagelen) != 0) {
DNPRINTF(MPII_D_MISC, "%s: unable to fetch raid volume "
"page 0\n", DEVNAME(sc));
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (EINVAL);
}
break;
}
- free(vpg, M_TEMP, 0);
+ free(vpg, M_TEMP, pagelen);
return (0);
}
-/* $OpenBSD: ehci.c,v 1.198 2017/03/30 14:44:36 deraadt Exp $ */
+/* $OpenBSD: ehci.c,v 1.199 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: ehci.c,v 1.66 2004/06/30 03:11:56 mycroft Exp $ */
/*
ehci_free_sqh(sc, sc->sc_async_head);
#endif
bad1:
- free(sc->sc_softitds, M_USB, 0);
+ free(sc->sc_softitds, M_USB,
+ sc->sc_flsize * sizeof(struct ehci_soft_itd *));
usb_freemem(&sc->sc_bus, &sc->sc_fldma);
return (err);
}
usb_delay_ms(&sc->sc_bus, 300); /* XXX let stray task complete */
- free(sc->sc_softitds, M_USB, 0);
+ free(sc->sc_softitds, M_USB,
+ sc->sc_flsize * sizeof(struct ehci_soft_itd *));
usb_freemem(&sc->sc_bus, &sc->sc_fldma);
/* XXX free other data structures XXX */
-/* $OpenBSD: if_athn_usb.c,v 1.46 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: if_athn_usb.c,v 1.47 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2011 Damien Bergamini <damien.bergamini@free.fr>
usc->usb_dev.dv_xname);
goto fail;
}
+ usc->ibuflen = isize;
error = usbd_open_pipe_intr(usc->sc_iface, AR_PIPE_RX_INTR,
USBD_SHORT_XFER_OK, &usc->rx_intr_pipe, usc, usc->ibuf, isize,
athn_usb_intr, USBD_DEFAULT_INTERVAL);
usc->rx_intr_pipe = NULL;
}
if (usc->ibuf != NULL) {
- free(usc->ibuf, M_USBDEV, 0);
+ free(usc->ibuf, M_USBDEV, usc->ibuflen);
usc->ibuf = NULL;
}
}
-/* $OpenBSD: if_athn_usb.h,v 1.7 2017/01/12 16:32:28 stsp Exp $ */
+/* $OpenBSD: if_athn_usb.h,v 1.8 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2011 Damien Bergamini <damien.bergamini@free.fr>
struct usbd_pipe *rx_intr_pipe;
struct usbd_pipe *tx_intr_pipe;
uint8_t *ibuf;
+ size_t ibuflen;
struct ar_wmi_cmd_reg_write wbuf[AR_MAX_WRITE_COUNT];
int wcount;
-/* $OpenBSD: if_kue.c,v 1.87 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: if_kue.c,v 1.88 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: if_kue.c,v 1.50 2002/07/16 22:00:31 augustss Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
sc->kue_dev.dv_xname);
return;
}
+ sc->kue_mcfilterslen = KUE_MCFILTCNT(sc);
s = splnet();
s = splusb(); /* XXX why? */
if (sc->kue_mcfilters != NULL) {
- free(sc->kue_mcfilters, M_USBDEV, 0);
+ free(sc->kue_mcfilters, M_USBDEV, sc->kue_mcfilterslen);
sc->kue_mcfilters = NULL;
}
-/* $OpenBSD: if_kuereg.h,v 1.11 2013/11/11 12:38:39 pirofti Exp $ */
+/* $OpenBSD: if_kuereg.h,v 1.12 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: if_kuereg.h,v 1.11 2001/01/21 02:35:31 augustss Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
int kue_if_flags;
u_int16_t kue_rxfilt;
u_int8_t *kue_mcfilters;
+ size_t kue_mcfilterslen;
struct kue_cdata kue_cdata;
char kue_attached;
-/* $OpenBSD: if_otus.c,v 1.56 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: if_otus.c,v 1.57 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
sc->sc_dev.dv_xname);
goto fail;
}
+ sc->ibuflen = isize;
error = usbd_open_pipe_intr(sc->sc_iface, AR_EPT_INTR_RX_NO,
USBD_SHORT_XFER_OK, &sc->cmd_rx_pipe, sc, sc->ibuf, isize,
otus_intr, USBD_DEFAULT_INTERVAL);
usbd_close_pipe(sc->cmd_rx_pipe);
}
if (sc->ibuf != NULL)
- free(sc->ibuf, M_USBDEV, 0);
+ free(sc->ibuf, M_USBDEV, sc->ibuflen);
if (sc->data_tx_pipe != NULL)
usbd_close_pipe(sc->data_tx_pipe);
if (sc->cmd_tx_pipe != NULL)
-/* $OpenBSD: if_otusreg.h,v 1.9 2013/11/26 20:33:18 deraadt Exp $ */
+/* $OpenBSD: if_otusreg.h,v 1.10 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
struct usbd_pipe *cmd_tx_pipe;
struct usbd_pipe *cmd_rx_pipe;
uint8_t *ibuf;
+ size_t ibuflen;
int sc_if_flags;
int sc_tx_timer;
-/* $OpenBSD: if_urndis.c,v 1.64 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: if_urndis.c,v 1.65 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2010 Jonathan Armani <armani@openbsd.org>
rval = RNDIS_STATUS_FAILURE;
}
- free(hdr, M_TEMP, 0);
+ free(hdr, M_TEMP, RNDIS_RESPONSE_LEN);
return rval;
}
if (bufsz == ETHER_ADDR_LEN) {
memcpy(eaddr, buf, ETHER_ADDR_LEN);
printf(", address %s\n", ether_sprintf(eaddr));
- free(buf, M_TEMP, 0);
+ free(buf, M_TEMP, bufsz);
} else {
printf(", invalid address\n");
- free(buf, M_TEMP, 0);
+ free(buf, M_TEMP, bufsz);
splx(s);
return;
}
-/* $OpenBSD: if_zyd.c,v 1.117 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: if_zyd.c,v 1.118 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
struct zyd_softc *sc = (struct zyd_softc *)self;
const char *fwname;
u_char *fw;
- size_t size;
+ size_t fwsize;
int error;
fwname = (sc->mac_rev == ZYD_ZD1211) ? "zd1211" : "zd1211b";
- if ((error = loadfirmware(fwname, &fw, &size)) != 0) {
+ if ((error = loadfirmware(fwname, &fw, &fwsize)) != 0) {
printf("%s: error %d, could not read firmware file %s\n",
sc->sc_dev.dv_xname, error, fwname);
return;
}
- error = zyd_loadfirmware(sc, fw, size);
- free(fw, M_DEVBUF, size);
+ error = zyd_loadfirmware(sc, fw, fwsize);
+ free(fw, M_DEVBUF, fwsize);
if (error != 0) {
printf("%s: could not load firmware (error=%d)\n",
sc->sc_dev.dv_xname, error);
sc->ibuf = malloc(isize, M_USBDEV, M_NOWAIT);
if (sc->ibuf == NULL)
return ENOMEM;
-
+ sc->ibuflen = isize;
error = usbd_open_pipe_intr(sc->sc_iface, 0x83, USBD_SHORT_XFER_OK,
&sc->zyd_ep[ZYD_ENDPT_IIN], sc, sc->ibuf, isize, zyd_intr,
USBD_DEFAULT_INTERVAL);
}
}
if (sc->ibuf != NULL) {
- free(sc->ibuf, M_USBDEV, 0);
+ free(sc->ibuf, M_USBDEV, sc->ibuflen);
sc->ibuf = NULL;
}
}
-/* $OpenBSD: if_zydreg.h,v 1.28 2014/07/12 15:26:54 stsp Exp $ */
+/* $OpenBSD: if_zydreg.h,v 1.29 2017/04/08 02:57:25 deraadt Exp $ */
/*-
* Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
#define ZYD_ENDPT_CNT 4
struct usbd_pipe *zyd_ep[ZYD_ENDPT_CNT];
uint8_t *ibuf;
+ size_t ibuflen;
struct zyd_rx_data rx_data[ZYD_RX_LIST_CNT];
struct zyd_tx_data tx_data[ZYD_TX_LIST_CNT];
-/* $OpenBSD: uaudio.c,v 1.125 2017/04/05 22:45:21 deraadt Exp $ */
+/* $OpenBSD: uaudio.c,v 1.126 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uaudio.c,v 1.90 2004/10/29 17:12:53 kent Exp $ */
/*
/* Copy old data, if there was any */
if (sc->sc_nctls != 0) {
memcpy(nmc, sc->sc_ctls, sizeof(*mc) * (sc->sc_nctls));
- free(sc->sc_ctls, M_USBDEV, 0);
+ free(sc->sc_ctls, M_USBDEV, sc->sc_nctls * sizeof(*mc));
}
sc->sc_ctls = nmc;
/* Copy old data, if there was any */
if (sc->sc_nalts != 0) {
memcpy(nai, sc->sc_alts, sizeof(*ai) * (sc->sc_nalts));
- free(sc->sc_alts, M_USBDEV, 0);
+ free(sc->sc_alts, M_USBDEV, sc->sc_nalts * sizeof(*ai));
}
sc->sc_alts = nai;
DPRINTFN(2,("%s: adding alt=%d, enc=%d\n",
free(iot[i].output, M_TEMP, 0);
iot[i].d.desc = NULL;
}
- free(iot, M_TEMP, 0);
+ free(iot, M_TEMP, 256 * sizeof(struct io_terminal));
return (USBD_NORMAL_COMPLETION);
}
-/* $OpenBSD: ubcmtp.c,v 1.14 2017/03/17 09:26:28 mpi Exp $ */
+/* $OpenBSD: ubcmtp.c,v 1.15 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2013-2014, joshua stein <jcs@openbsd.org>
}
if (sc->tp_pkt != NULL) {
- free(sc->tp_pkt, M_USBDEV, 0);
+ free(sc->tp_pkt, M_USBDEV, sc->tp_maxlen);
sc->tp_pkt = NULL;
}
if (sc->bt_pkt != NULL) {
- free(sc->bt_pkt, M_USBDEV, 0);
+ free(sc->bt_pkt, M_USBDEV, sc->bt_maxlen);
sc->bt_pkt = NULL;
}
}
usbd_close_pipe(sc->sc_tp_pipe);
}
if (sc->tp_pkt != NULL)
- free(sc->tp_pkt, M_USBDEV, 0);
+ free(sc->tp_pkt, M_USBDEV, sc->tp_maxlen);
fail1:
if (sc->sc_bt_pipe != NULL) {
usbd_abort_pipe(sc->sc_bt_pipe);
usbd_close_pipe(sc->sc_bt_pipe);
}
if (sc->bt_pkt != NULL)
- free(sc->bt_pkt, M_USBDEV, 0);
+ free(sc->bt_pkt, M_USBDEV, sc->bt_maxlen);
return (1);
}
-/* $OpenBSD: ubsa.c,v 1.64 2015/03/14 03:38:49 jsg Exp $ */
+/* $OpenBSD: ubsa.c,v 1.65 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: ubsa.c,v 1.5 2002/11/25 00:51:33 fvdl Exp $ */
/*-
* Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
if (sc->sc_intr_pipe != NULL) {
usbd_abort_pipe(sc->sc_intr_pipe);
usbd_close_pipe(sc->sc_intr_pipe);
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname,
usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}
-/* $OpenBSD: uchcom.c,v 1.26 2017/04/06 04:48:54 deraadt Exp $ */
+/* $OpenBSD: uchcom.c,v 1.27 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uchcom.c,v 1.1 2007/09/03 17:57:37 tshiozak Exp $ */
/*
struct usbd_interface *sc_iface;
/* */
int sc_intr_endpoint;
- int sc_intr_size;
struct usbd_pipe *sc_intr_pipe;
u_char *sc_intr_buf;
+ int sc_isize;
/* */
uint8_t sc_version;
int sc_dtr;
goto failed;
sc->sc_intr_endpoint = endpoints.ep_intr;
- sc->sc_intr_size = endpoints.ep_intr_size;
+ sc->sc_isize = endpoints.ep_intr_size;
/* setup ucom layer */
uca.portno = UCOM_UNK_PORTNO;
usbd_status err;
if (sc->sc_intr_endpoint != -1 && sc->sc_intr_pipe == NULL) {
- sc->sc_intr_buf = malloc(sc->sc_intr_size, M_USBDEV, M_WAITOK);
+ sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
err = usbd_open_pipe_intr(sc->sc_iface,
sc->sc_intr_endpoint,
USBD_SHORT_XFER_OK,
&sc->sc_intr_pipe, sc,
sc->sc_intr_buf,
- sc->sc_intr_size,
+ sc->sc_isize,
uchcom_intr, USBD_DEFAULT_INTERVAL);
if (err) {
printf("%s: cannot open interrupt pipe: %s\n",
if (err)
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname, usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}
-/* $OpenBSD: ucycom.c,v 1.35 2017/04/06 04:48:54 deraadt Exp $ */
+/* $OpenBSD: ucycom.c,v 1.36 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: ucycom.c,v 1.3 2005/08/05 07:27:47 skrll Exp $ */
/*
s = splusb();
if (sc->sc_obuf != NULL) {
- free(sc->sc_obuf, M_USBDEV, 0);
+ free(sc->sc_obuf, M_USBDEV, sc->sc_olen);
sc->sc_obuf = NULL;
}
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_ilen);
sc->sc_ibuf = NULL;
}
splx(s);
-/* $OpenBSD: udl.c,v 1.86 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: udl.c,v 1.87 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2009 Marcus Glocker <mglocker@openbsd.org>
DN(sc));
return (ENOMEM);
}
+ sc->sc_cbslen = sc->sc_ri.ri_rows * sc->sc_ri.ri_cols *
+ sizeof(*sc->sc_cbs);
sc->sc_nscreens++;
/* free character backing store */
if (sc->sc_cbs != NULL)
- free(sc->sc_cbs, M_DEVBUF, 0);
+ free(sc->sc_cbs, M_DEVBUF, sc->sc_cbslen);
sc->sc_nscreens--;
}
struct udl_cmd_buf *cb = &sc->sc_cmd_buf;
if (cb->buf != NULL) {
- free(cb->buf, M_DEVBUF, 0);
+ free(cb->buf, M_DEVBUF, UDL_CMD_MAX_XFER_SIZE);
cb->buf = NULL;
}
cb->off = 0;
-/* $OpenBSD: udl.h,v 1.22 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: udl.h,v 1.23 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2009 Marcus Glocker <mglocker@openbsd.org>
#define DLUNK 0x00ff /* unknown */
uint8_t sc_cur_mode;
u_int *sc_cbs; /* character backing store */
+ size_t sc_cbslen;
/*
* We use function pointers to the framebuffer manipulation
-/* $OpenBSD: ugen.c,v 1.94 2016/05/24 05:35:01 mpi Exp $ */
+/* $OpenBSD: ugen.c,v 1.95 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: ugen.c,v 1.63 2002/11/26 18:49:48 christos Exp $ */
/* $FreeBSD: src/sys/dev/usb/ugen.c,v 1.26 1999/11/17 22:33:41 n_hibma Exp $ */
struct clist q;
struct selinfo rsel;
u_char *ibuf; /* start of buffer (circular for isoc) */
+ size_t ibuflen;
u_char *fill; /* location for input (isoc) */
u_char *limit; /* end of circular buffer (isoc) */
u_char *cur; /* current read location (isoc) */
isize = UGETW(edesc->wMaxPacketSize);
if (isize == 0) /* shouldn't happen */
return (EINVAL);
- sce->ibuf = malloc(isize, M_USBDEV, M_WAITOK);
+ sce->ibuflen = isize;
+ sce->ibuf = malloc(sce->ibuflen, M_USBDEV, M_WAITOK);
DPRINTFN(5, ("ugenopen: intr endpt=%d,isize=%d\n",
endpt, isize));
clalloc(&sce->q, UGEN_IBSIZE, 0);
sce->ibuf, isize, ugenintr,
USBD_DEFAULT_INTERVAL);
if (err) {
- free(sce->ibuf, M_USBDEV, 0);
+ free(sce->ibuf, M_USBDEV, sce->ibuflen);
clfree(&sce->q);
return (EIO);
}
isize = UGETW(edesc->wMaxPacketSize);
if (isize == 0) /* shouldn't happen */
return (EINVAL);
+ sce->ibuflen = isize * UGEN_NISOFRAMES;
sce->ibuf = mallocarray(isize, UGEN_NISOFRAMES,
M_USBDEV, M_WAITOK);
sce->cur = sce->fill = sce->ibuf;
err = usbd_open_pipe(sce->iface,
edesc->bEndpointAddress, 0, &sce->pipeh);
if (err) {
- free(sce->ibuf, M_USBDEV, 0);
+ free(sce->ibuf, M_USBDEV, sce->ibuflen);
return (EIO);
}
for(i = 0; i < UGEN_NISOREQS; ++i) {
}
if (sce->ibuf != NULL) {
- free(sce->ibuf, M_USBDEV, 0);
+ free(sce->ibuf, M_USBDEV, sce->ibuflen);
sce->ibuf = NULL;
}
}
case USB_DO_REQUEST:
{
struct usb_ctl_request *ur = (void *)addr;
- size_t len = UGETW(ur->ucr_request.wLength);
+ size_t len = UGETW(ur->ucr_request.wLength), mlen;
struct iovec iov;
struct uio uio;
- void *ptr = 0;
+ void *ptr = NULL;
int error = 0;
if (!(flag & FWRITE))
goto ret;
}
/* Only if USBD_SHORT_XFER_OK is set. */
- if (len > ur->ucr_actlen)
- len = ur->ucr_actlen;
- if (len != 0) {
+ mlen = len;
+ if (mlen > ur->ucr_actlen)
+ mlen = ur->ucr_actlen;
+ if (mlen != 0) {
if (uio.uio_rw == UIO_READ) {
- error = uiomove(ptr, len, &uio);
+ error = uiomove(ptr, mlen, &uio);
if (error)
goto ret;
}
}
ret:
if (ptr)
- free(ptr, M_TEMP, 0);
+ free(ptr, M_TEMP, len);
return (error);
}
case USB_GET_DEVICEINFO:
-/* $OpenBSD: uhid.c,v 1.66 2016/05/24 05:35:01 mpi Exp $ */
+/* $OpenBSD: uhid.c,v 1.67 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uhid.c,v 1.57 2003/03/11 16:44:00 augustss Exp $ */
/*
DPRINTF(("uhidclose: sc=%p\n", sc));
clfree(&sc->sc_q);
- free(sc->sc_obuf, M_USBDEV, 0);
+ free(sc->sc_obuf, M_USBDEV, sc->sc_hdev.sc_osize);
sc->sc_async = NULL;
uhidev_close(&sc->sc_hdev);
-/* $OpenBSD: uhidev.c,v 1.74 2016/06/13 10:15:03 mpi Exp $ */
+/* $OpenBSD: uhidev.c,v 1.75 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uhidev.c,v 1.14 2003/03/11 16:44:00 augustss Exp $ */
/*
if (usbd_get_report_descriptor(sc->sc_udev, sc->sc_ifaceno,
desc, size)) {
printf("%s: no report descriptor\n", DEVNAME(sc));
- free(desc, M_USBDEV, 0);
+ free(desc, M_USBDEV, size);
return;
}
}
}
if (sc->sc_repdesc != NULL)
- free(sc->sc_repdesc, M_USBDEV, 0);
+ free(sc->sc_repdesc, M_USBDEV, sc->sc_repdesc_size);
/*
* XXX Check if we have only one children claiming all the Report
usbd_close_pipe(sc->sc_ipipe);
out1:
DPRINTF(("uhidev_open: failed in someway"));
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_isize);
scd->sc_state &= ~UHIDEV_OPEN;
sc->sc_refcnt = 0;
sc->sc_ipipe = NULL;
}
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_isize);
sc->sc_ibuf = NULL;
}
}
-/* $OpenBSD: uhub.c,v 1.89 2016/09/02 09:14:59 mpi Exp $ */
+/* $OpenBSD: uhub.c,v 1.90 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uhub.c,v 1.64 2003/02/08 03:32:51 ichiro Exp $ */
/* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */
hub->ports = mallocarray(nports, sizeof(struct usbd_port),
M_USBDEV, M_NOWAIT);
if (hub->ports == NULL) {
- free(hub, M_USBDEV, 0);
+ free(hub, M_USBDEV, sizeof *hub);
return;
}
dev->hub = hub;
bad:
if (sc->sc_statusbuf)
- free(sc->sc_statusbuf, M_USBDEV, 0);
+ free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen);
if (hub) {
if (hub->ports)
free(hub->ports, M_USBDEV, 0);
- free(hub, M_USBDEV, 0);
+ free(hub, M_USBDEV, sizeof *hub);
}
dev->hub = NULL;
}
if (hub->ports[0].tt)
free(hub->ports[0].tt, M_USBDEV, 0);
if (sc->sc_statusbuf)
- free(sc->sc_statusbuf, M_USBDEV, 0);
+ free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen);
if (hub->ports)
free(hub->ports, M_USBDEV, 0);
- free(hub, M_USBDEV, 0);
+ free(hub, M_USBDEV, sizeof *hub);
sc->sc_hub->hub = NULL;
return (0);
-/* $OpenBSD: umct.c,v 1.45 2016/09/02 09:14:59 mpi Exp $ */
+/* $OpenBSD: umct.c,v 1.46 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: umct.c,v 1.10 2003/02/23 04:20:07 simonb Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
if (sc->sc_intr_pipe != NULL) {
usbd_abort_pipe(sc->sc_intr_pipe);
usbd_close_pipe(sc->sc_intr_pipe);
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
if (err)
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname, usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}
-/* $OpenBSD: umidi.c,v 1.44 2017/02/10 08:07:21 ratchov Exp $ */
+/* $OpenBSD: umidi.c,v 1.45 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: umidi.c,v 1.16 2002/07/11 21:14:32 augustss Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
static void
free_all_jacks(struct umidi_softc *sc)
{
- int s;
+ int s, jacks = sc->sc_in_num_jacks + sc->sc_out_num_jacks;
s = splusb();
if (sc->sc_out_jacks) {
- free(sc->sc_jacks, M_USBDEV, 0);
+ free(sc->sc_jacks, M_USBDEV, jacks * sizeof(*sc->sc_out_jacks));
sc->sc_jacks = sc->sc_in_jacks = sc->sc_out_jacks = NULL;
}
splx(s);
static void
free_all_mididevs(struct umidi_softc *sc)
{
- sc->sc_num_mididevs = 0;
if (sc->sc_mididevs)
- free(sc->sc_mididevs, M_USBDEV, 0);
+ free(sc->sc_mididevs, M_USBDEV,
+ sc->sc_num_mididevs * sizeof(*sc->sc_mididevs));
+ sc->sc_mididevs = NULL;
+ sc->sc_num_mididevs = 0;
}
static usbd_status
-/* $OpenBSD: umsm.c,v 1.108 2016/12/12 04:26:29 jsg Exp $ */
+/* $OpenBSD: umsm.c,v 1.109 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2008 Yojiro UO <yuo@nui.org>
if (sc->sc_intr_pipe != NULL) {
usbd_abort_pipe(sc->sc_intr_pipe);
usbd_close_pipe(sc->sc_intr_pipe);
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname,
usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}
-/* $OpenBSD: uoaklux.c,v 1.12 2016/01/09 04:14:42 jcs Exp $ */
+/* $OpenBSD: uoaklux.c,v 1.13 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2012 Yojiro UO <yuo@nui.org>
uhidev_close(&sc->sc_hdev);
if (scc->sc_ibuf != NULL) {
- free(scc->sc_ibuf, M_USBDEV, 0);
+ free(scc->sc_ibuf, M_USBDEV, scc->sc_ilen);
scc->sc_ibuf = NULL;
}
-/* $OpenBSD: uoakrh.c,v 1.14 2016/03/11 18:41:33 mmcc Exp $ */
+/* $OpenBSD: uoakrh.c,v 1.15 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2012 Yojiro UO <yuo@nui.org>
uhidev_close(&sc->sc_hdev);
if (scc->sc_ibuf != NULL) {
- free(scc->sc_ibuf, M_USBDEV, 0);
+ free(scc->sc_ibuf, M_USBDEV, scc->sc_ilen);
scc->sc_ibuf = NULL;
}
-/* $OpenBSD: uoakv.c,v 1.12 2016/01/09 04:14:42 jcs Exp $ */
+/* $OpenBSD: uoakv.c,v 1.13 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2012 Yojiro UO <yuo@nui.org>
uhidev_close(&sc->sc_hdev);
if (scc->sc_ibuf != NULL) {
- free(scc->sc_ibuf, M_USBDEV, 0);
+ free(scc->sc_ibuf, M_USBDEV, scc->sc_ilen);
scc->sc_ibuf = NULL;
}
-/* $OpenBSD: upd.c,v 1.25 2016/01/09 04:14:42 jcs Exp $ */
+/* $OpenBSD: upd.c,v 1.26 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2015 David Higgs <higgsd@gmail.com>
sc->sc_hdev.sc_intr = upd_intr;
sc->sc_hdev.sc_parent = uha->parent;
- sc->sc_reports = NULL;
- sc->sc_sensors = NULL;
SLIST_INIT(&sc->sc_root_sensors);
strlcpy(sc->sc_sensordev.xname, DEVNAME(sc),
sensor_detach(&sc->sc_sensordev, &sensor->ksensor);
}
- free(sc->sc_reports, M_USBDEV, 0);
- free(sc->sc_sensors, M_USBDEV, 0);
+ free(sc->sc_reports, M_USBDEV, sc->sc_max_repid * sizeof(struct upd_report));
+ free(sc->sc_sensors, M_USBDEV, UPD_MAX_SENSORS * sizeof(struct upd_sensor));
return (0);
}
-/* $OpenBSD: uplcom.c,v 1.68 2016/09/02 09:14:59 mpi Exp $ */
+/* $OpenBSD: uplcom.c,v 1.69 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uplcom.c,v 1.29 2002/09/23 05:51:23 simonb Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
int i;
struct ucom_attach_args uca;
- sc->sc_udev = dev;
+ sc->sc_udev = dev;
DPRINTF(("\n\nuplcom attach: sc=%p\n", sc));
* USB-RSAQ1 has two interface
*
* USB-RSAQ1 | USB-RSAQ2
- * -----------------+-----------------
+ * -----------------+-----------------
* Interface 0 |Interface 0
* Interrupt(0x81) | Interrupt(0x81)
* -----------------+ BulkIN(0x02)
DPRINTF(("uplcom_detach: sc=%p flags=%d\n", sc, flags));
- if (sc->sc_intr_pipe != NULL) {
- usbd_abort_pipe(sc->sc_intr_pipe);
- usbd_close_pipe(sc->sc_intr_pipe);
- free(sc->sc_intr_buf, M_USBDEV, 0);
- sc->sc_intr_pipe = NULL;
- }
+ if (sc->sc_intr_pipe != NULL) {
+ usbd_abort_pipe(sc->sc_intr_pipe);
+ usbd_close_pipe(sc->sc_intr_pipe);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
+ sc->sc_intr_pipe = NULL;
+ }
if (sc->sc_subdev != NULL) {
rv = config_detach(sc->sc_subdev, flags);
usbd_status
uplcom_reset(struct uplcom_softc *sc)
{
- usb_device_request_t req;
+ usb_device_request_t req;
usbd_status err;
- req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
- req.bRequest = UPLCOM_SET_REQUEST;
- USETW(req.wValue, 0);
- USETW(req.wIndex, sc->sc_iface_number);
- USETW(req.wLength, 0);
+ req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+ req.bRequest = UPLCOM_SET_REQUEST;
+ USETW(req.wValue, 0);
+ USETW(req.wIndex, sc->sc_iface_number);
+ USETW(req.wLength, 0);
- err = usbd_do_request(sc->sc_udev, &req, 0);
+ err = usbd_do_request(sc->sc_udev, &req, 0);
if (err)
return (EIO);
if (err)
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname, usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}
-/* $OpenBSD: usb.c,v 1.111 2016/05/18 18:28:58 patrick Exp $ */
+/* $OpenBSD: usb.c,v 1.112 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $ */
/*
case USB_REQUEST:
{
struct usb_ctl_request *ur = (void *)data;
- size_t len = UGETW(ur->ucr_request.wLength);
+ size_t len = UGETW(ur->ucr_request.wLength), mlen;
struct iovec iov;
struct uio uio;
- void *ptr = 0;
+ void *ptr = NULL;
int addr = ur->ucr_addr;
usbd_status err;
int error = 0;
goto ret;
}
/* Only if USBD_SHORT_XFER_OK is set. */
- if (len > ur->ucr_actlen)
- len = ur->ucr_actlen;
- if (len != 0) {
+ mlen = len;
+ if (mlen > ur->ucr_actlen)
+ mlen = ur->ucr_actlen;
+ if (mlen != 0) {
if (uio.uio_rw == UIO_READ) {
- error = uiomove(ptr, len, &uio);
+ error = uiomove(ptr, mlen, &uio);
if (error)
goto ret;
}
}
ret:
if (ptr)
- free(ptr, M_TEMP, 0);
+ free(ptr, M_TEMP, len);
return (error);
}
-/* $OpenBSD: usb_mem.c,v 1.28 2016/11/30 10:19:18 mpi Exp $ */
+/* $OpenBSD: usb_mem.c,v 1.29 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: usb_mem.c,v 1.26 2003/02/01 06:23:40 thorpej Exp $ */
/*
free1:
bus_dmamem_free(tag, p->segs, p->nsegs);
free0:
- free(p, M_USB, 0);
+ free(p, M_USB, sizeof *p);
return (USBD_NOMEM);
}
bus_dmamap_destroy(p->tag, p->map);
bus_dmamem_unmap(p->tag, p->kaddr, p->size);
bus_dmamem_free(p->tag, p->segs, p->nsegs);
- free(p, M_USB, 0);
+ free(p, M_USB, sizeof *p);
}
#endif
-/* $OpenBSD: usb_subr.c,v 1.133 2017/04/05 22:45:21 deraadt Exp $ */
+/* $OpenBSD: usb_subr.c,v 1.134 2017/04/08 02:57:25 deraadt 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 $ */
usb_status_t ds;
usb_config_descriptor_t cd, *cdp;
usbd_status err;
- int i, ifcidx, nifc, len, selfpowered, power;
+ int i, ifcidx, nifc, cdplen, selfpowered, power;
DPRINTFN(5,("usbd_set_config_index: dev=%p index=%d\n", dev, index));
return (err);
if (cd.bDescriptorType != UDESC_CONFIG)
return (USBD_INVAL);
- len = UGETW(cd.wTotalLength);
- cdp = malloc(len, M_USB, M_NOWAIT);
+ cdplen = UGETW(cd.wTotalLength);
+ cdp = malloc(cdplen, M_USB, M_NOWAIT);
if (cdp == NULL)
return (USBD_NOMEM);
/* Get the full descriptor. */
for (i = 0; i < 3; i++) {
- err = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdp);
+ err = usbd_get_desc(dev, UDESC_CONFIG, index, cdplen, cdp);
if (!err)
break;
usbd_delay_ms(dev, 200);
return (USBD_NORMAL_COMPLETION);
bad:
- free(cdp, M_USB, 0);
+ free(cdp, M_USB, cdplen);
return (err);
}
p = malloc(dev->bus->pipe_size, M_USB, M_NOWAIT|M_ZERO);
if (p == NULL)
return (USBD_NOMEM);
+ p->pipe_size = dev->bus->pipe_size;
p->device = dev;
p->iface = iface;
p->endpoint = ep;
if (err) {
DPRINTF(("%s: endpoint=0x%x failed, error=%s\n", __func__,
ep->edesc->bEndpointAddress, usbd_errstr(err)));
- free(p, M_USB, 0);
+ free(p, M_USB, dev->bus->pipe_size);
return (err);
}
*pipe = p;
dev->subdevs = mallocarray(nifaces + 2, sizeof(dv), M_USB,
M_NOWAIT | M_ZERO);
if (dev->subdevs == NULL) {
- free(ifaces, M_USB, 0);
+ free(ifaces, M_USB, nifaces * sizeof(*ifaces));
err = USBD_NOMEM;
goto fail;
}
usbd_claim_iface(dev, i);
}
}
- free(ifaces, M_USB, 0);
+ free(ifaces, M_USB, nifaces * sizeof(*ifaces));
if (dev->ndevs > 0) {
for (i = 0; i < nifaces; i++) {
goto fail;
}
- free(dev->subdevs, M_USB, 0);
+ free(dev->subdevs, M_USB, (nifaces + 2) * sizeof(dv));
dev->subdevs = NULL;
}
/* No interfaces were attached in any of the configurations. */
DPRINTFN(15, ("usbd_print dev=%p\n", uaa->device));
if (pnp) {
if (!uaa->usegeneric) {
- free(devinfop, M_TEMP, 0);
+ free(devinfop, M_TEMP, DEVINFOSIZE);
return (QUIET);
}
printf("%s at %s", devinfop, pnp);
if (!pnp)
printf(" %s\n", devinfop);
- free(devinfop, M_TEMP, 0);
+ free(devinfop, M_TEMP, DEVINFOSIZE);
return (UNCONF);
}
-/* $OpenBSD: usbdi.c,v 1.90 2017/03/17 09:25:59 mpi Exp $ */
+/* $OpenBSD: usbdi.c,v 1.91 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: usbdi.c,v 1.103 2002/09/27 15:37:38 provos Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */
pipe->methods->close(pipe);
if (pipe->intrxfer != NULL)
usbd_free_xfer(pipe->intrxfer);
- free(pipe, M_USB, 0);
+ free(pipe, M_USB, pipe->pipe_size);
return (USBD_NORMAL_COMPLETION);
}
USETW2(p->bString[i], 0, s[i]);
return (2 * i + 2);
}
-
-/* $OpenBSD: usbdivar.h,v 1.71 2016/05/23 11:31:12 mpi Exp $ */
+/* $OpenBSD: usbdivar.h,v 1.72 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: usbdivar.h,v 1.70 2002/07/11 21:14:36 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.11 1999/11/17 22:33:51 n_hibma Exp $ */
struct usbd_interface *iface;
struct usbd_device *device;
struct usbd_endpoint *endpoint;
+ size_t pipe_size;
char running;
char aborting;
SIMPLEQ_HEAD(, usbd_xfer) queue;
-/* $OpenBSD: uslhcom.c,v 1.5 2017/04/06 04:48:54 deraadt Exp $ */
+/* $OpenBSD: uslhcom.c,v 1.6 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2015 SASANO Takayoshi <uaa@openbsd.org>
if (usbd_is_dying(sc->sc_udev))
return EIO;
- sc->sc_ibuf = malloc(sc->sc_hdev.sc_osize + sizeof(u_char),
- M_USBDEV, M_WAITOK);
+ sc->sc_ibuf = malloc(sc->sc_hdev.sc_isize, M_USBDEV, M_WAITOK);
uslhcom_set_baud_rate(&config, 9600);
config.parity = UART_CONFIG_PARITY_NONE;
s = splusb();
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_hdev.sc_isize);
sc->sc_ibuf = NULL;
}
splx(s);
-/* $OpenBSD: usps.c,v 1.8 2016/11/06 12:58:01 mpi Exp $ */
+/* $OpenBSD: usps.c,v 1.9 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2011 Yojiro UO <yuo@nui.org>
usbd_close_pipe(sc->sc_ipipe);
if (sc->sc_xfer != NULL)
usbd_free_xfer(sc->sc_xfer);
- if (sc->sc_intrbuf != NULL)
- free(sc->sc_intrbuf, M_USBDEV, 0);
+ if (sc->sc_intrbuf != NULL)
+ free(sc->sc_intrbuf, M_USBDEV, sc->sc_isize);
}
int
usbd_abort_pipe(sc->sc_ipipe);
usbd_close_pipe(sc->sc_ipipe);
if (sc->sc_intrbuf != NULL)
- free(sc->sc_intrbuf, M_USBDEV, 0);
+ free(sc->sc_intrbuf, M_USBDEV, sc->sc_isize);
sc->sc_ipipe = NULL;
}
if (sc->sc_xfer != NULL)
-/* $OpenBSD: uticom.c,v 1.31 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: uticom.c,v 1.32 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2005 Dmitry Komissaroff <dxi@mail.ru>.
*
if (sc->sc_intr_pipe != NULL) {
usbd_abort_pipe(sc->sc_intr_pipe);
usbd_close_pipe(sc->sc_intr_pipe);
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
if (err)
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname, usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}
-/* $OpenBSD: utrh.c,v 1.20 2016/03/19 11:41:56 mpi Exp $ */
+/* $OpenBSD: utrh.c,v 1.21 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2009 Yojiro UO <yuo@nui.org>
uhidev_close(&sc->sc_hdev);
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_ilen);
sc->sc_ibuf = NULL;
}
-/* $OpenBSD: uts.c,v 1.39 2016/09/02 09:14:59 mpi Exp $ */
+/* $OpenBSD: uts.c,v 1.40 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2007 Robert Nagy <robert@openbsd.org>
USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc, sc->sc_ibuf,
sc->sc_isize, uts_intr, USBD_DEFAULT_INTERVAL);
if (err) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
return (EIO);
}
}
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_isize);
sc->sc_ibuf = NULL;
}
-/* $OpenBSD: utwitch.c,v 1.16 2016/01/09 04:14:42 jcs Exp $ */
+/* $OpenBSD: utwitch.c,v 1.17 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2010 Yojiro UO <yuo@nui.org>
uhidev_close(&sc->sc_hdev);
if (sc->sc_ibuf != NULL) {
- free(sc->sc_ibuf, M_USBDEV, 0);
+ free(sc->sc_ibuf, M_USBDEV, sc->sc_ilen);
sc->sc_ibuf = NULL;
}
-/* $OpenBSD: uvideo.c,v 1.193 2017/03/26 15:31:15 deraadt Exp $ */
+/* $OpenBSD: uvideo.c,v 1.194 2017/04/08 02:57:25 deraadt Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
struct uvideo_frame_buffer *fb = &sc->sc_frame_buffer;
if (fb->buf != NULL) {
- free(fb->buf, M_DEVBUF, 0);
+ free(fb->buf, M_DEVBUF, fb->buf_size);
fb->buf = NULL;
}
qctrl->flags = 0;
out:
- free(ctrl_data, M_USBDEV, 0);
+ free(ctrl_data, M_USBDEV, ctrl_len);
return (ret);
}
}
out:
- free(ctrl_data, M_USBDEV, 0);
+ free(ctrl_data, M_USBDEV, ctrl_len);
return (0);
}
if (error != USBD_NORMAL_COMPLETION)
ret = EINVAL;
- free(ctrl_data, M_USBDEV, 0);
+ free(ctrl_data, M_USBDEV, ctrl_len);
return (ret);
}
-/* $OpenBSD: uvscom.c,v 1.34 2016/09/02 09:14:59 mpi Exp $ */
+/* $OpenBSD: uvscom.c,v 1.35 2017/04/08 02:57:25 deraadt Exp $ */
/* $NetBSD: uvscom.c,v 1.9 2003/02/12 15:36:20 ichiro Exp $ */
/*-
* Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
if (sc->sc_intr_pipe != NULL) {
usbd_abort_pipe(sc->sc_intr_pipe);
usbd_close_pipe(sc->sc_intr_pipe);
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
printf("%s: close interrupt pipe failed: %s\n",
sc->sc_dev.dv_xname,
usbd_errstr(err));
- free(sc->sc_intr_buf, M_USBDEV, 0);
+ free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
sc->sc_intr_pipe = NULL;
}
}