summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroga <oga@openbsd.org>2011-06-23 22:02:26 +0000
committeroga <oga@openbsd.org>2011-06-23 22:02:26 +0000
commit9fbc4c610dca3b4b75456abf9c615e14ad26771f (patch)
tree347ac9d2a8dcda30a3629a81b1df3ac0d33b51cd
parentfree(null) ist verboten in the kernel. (diff)
downloadwireguard-openbsd-9fbc4c610dca3b4b75456abf9c615e14ad26771f.tar.xz
wireguard-openbsd-9fbc4c610dca3b4b75456abf9c615e14ad26771f.zip
make malloc calls in isp_pci_mbxdma NOWAIT to match the bus_dma calls that are
all nowait. While here, plug a memory leak if one of the bus_dma calls near the bottom of the function fails because it would fail to free the dmamap, unmap the memory and free the memory. make that part of the code use the standard list of goto labels for error handling that most callers of bus_dmamem_alloc; bus_dmamem_map; bus_dmamap_creat; bus_dmamap_load() use to clean up. ok miod@
-rw-r--r--sys/dev/pci/isp_pci.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/sys/dev/pci/isp_pci.c b/sys/dev/pci/isp_pci.c
index 9de50ae9959..456d58f17fa 100644
--- a/sys/dev/pci/isp_pci.c
+++ b/sys/dev/pci/isp_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: isp_pci.c,v 1.56 2011/06/17 07:06:47 mk Exp $ */
+/* $OpenBSD: isp_pci.c,v 1.57 2011/06/23 22:02:26 oga 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
@@ -1275,15 +1275,13 @@ isp_pci_mbxdma(struct ispsoftc *isp)
return (0);
len = isp->isp_maxcmds * sizeof (XS_T *);
- isp->isp_xflist = malloc(len, M_DEVBUF,
- M_WAITOK | M_CANFAIL | M_ZERO);
+ isp->isp_xflist = malloc(len, 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_WAITOK | M_CANFAIL);
+ pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_NOWAIT);
if (pcs->pci_xfer_dmap == NULL) {
free(isp->isp_xflist, M_DEVBUF);
isp->isp_xflist = NULL;
@@ -1320,18 +1318,20 @@ isp_pci_mbxdma(struct ispsoftc *isp)
}
if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
- BUS_DMA_NOWAIT) ||
- bus_dmamem_map(isp->isp_dmatag, &sg, rs, len,
- &base, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
+ BUS_DMA_NOWAIT))
goto dmafail;
- }
+
+ if (bus_dmamem_map(isp->isp_dmatag, &sg, rs, len, &base,
+ BUS_DMA_NOWAIT | BUS_DMA_COHERENT))
+ goto dmafree;
if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
- &isp->isp_cdmap) || bus_dmamap_load(dmat, isp->isp_cdmap,
- base, len, NULL,
- BUS_DMA_NOWAIT)) {
- goto dmafail;
- }
+ &isp->isp_cdmap))
+ goto dmaunmap;
+
+ if (bus_dmamap_load(dmat, isp->isp_cdmap, base, len, NULL,
+ BUS_DMA_NOWAIT))
+ goto dmadestroy;
addr = isp->isp_cdmap->dm_segs[0].ds_addr;
isp->isp_rquest_dma = addr;
@@ -1353,6 +1353,12 @@ isp_pci_mbxdma(struct ispsoftc *isp)
}
return (0);
+dmadestroy:
+ bus_dmamap_destroy(dmat, isp->isp_cdmap);
+dmaunmap:
+ bus_dmamem_unmap(dmat, base, len);
+dmafree:
+ bus_dmamem_free(dmat, &sg, rs);
dmafail:
isp_prt(isp, ISP_LOGERR, "mailbox dma setup failure");
for (i = 0; i < isp->isp_maxcmds; i++) {