Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/vax/if le(4): Fix resource leaks for error paths.
details: https://anonhg.NetBSD.org/src/rev/c6b8210a958a
branches: trunk
changeset: 366501:c6b8210a958a
user: rin <rin%NetBSD.org@localhost>
date: Sun May 29 10:45:05 2022 +0000
description:
le(4): Fix resource leaks for error paths.
XXX
Compile test only (at least one arch per driver).
diffstat:
sys/arch/evbppc/explora/dev/le_elb.c | 25 +++++++++++++++++--------
sys/arch/mipsco/obio/if_le.c | 20 ++++++++++++--------
sys/arch/mvme68k/dev/if_le.c | 16 +++++++++++-----
sys/arch/sparc/dev/if_le_obio.c | 26 +++++++++++++++++---------
sys/arch/vax/if/if_le_vsbus.c | 23 ++++++++++++++---------
5 files changed, 71 insertions(+), 39 deletions(-)
diffs (truncated from 306 to 300 lines):
diff -r dc90128d7704 -r c6b8210a958a sys/arch/evbppc/explora/dev/le_elb.c
--- a/sys/arch/evbppc/explora/dev/le_elb.c Sun May 29 10:43:45 2022 +0000
+++ b/sys/arch/evbppc/explora/dev/le_elb.c Sun May 29 10:45:05 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: le_elb.c,v 1.11 2021/12/08 20:50:02 andvar Exp $ */
+/* $NetBSD: le_elb.c,v 1.12 2022/05/29 10:45:05 rin Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: le_elb.c,v 1.11 2021/12/08 20:50:02 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: le_elb.c,v 1.12 2022/05/29 10:45:05 rin Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -116,13 +116,13 @@
if (bus_dmamem_alloc(msc->sc_dmat, LE_MEMSIZE, PAGE_SIZE, 0,
&seg, 1, &rseg, BUS_DMA_NOWAIT)) {
aprint_error_dev(self, "couldn't allocate memory for card\n");
- return;
+ goto bad_bsunmap;
}
if (bus_dmamem_map(msc->sc_dmat, &seg, rseg, LE_MEMSIZE,
(void **)&sc->sc_mem,
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
aprint_error_dev(self, "couldn't map memory for card\n");
- return;
+ goto bad_free;
}
/*
@@ -131,14 +131,12 @@
if (bus_dmamap_create(msc->sc_dmat, LE_MEMSIZE, 1,
LE_MEMSIZE, 0, BUS_DMA_NOWAIT, &msc->sc_dmam)) {
aprint_error_dev(self, "couldn't create DMA map\n");
- bus_dmamem_free(msc->sc_dmat, &seg, rseg);
- return;
+ goto bad_unmap;
}
if (bus_dmamap_load(msc->sc_dmat, msc->sc_dmam,
sc->sc_mem, LE_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
aprint_error_dev(self, "couldn't load DMA map\n");
- bus_dmamem_free(msc->sc_dmat, &seg, rseg);
- return;
+ goto bad_destroy;
}
/*
@@ -172,6 +170,17 @@
intr_establish_xname(eaa->elb_irq, IST_LEVEL, IPL_NET, am79900_intr,
sc, device_xname(self));
+
+ return;
+
+ bad_destroy:
+ bus_dmamap_destroy(msc->sc_dmat, msc->sc_dmam);
+ bad_unmap:
+ bus_dmamem_unmap(msc->sc_dmat, sc->sc_mem, LE_MEMSIZE);
+ bad_free:
+ bus_dmamem_free(msc->sc_dmat, &seg, rseg);
+ bad_bsunmap:
+ bus_space_unmap(msc->sc_iot, msc->sc_ioh, LE_NPORTS);
}
/*
diff -r dc90128d7704 -r c6b8210a958a sys/arch/mipsco/obio/if_le.c
--- a/sys/arch/mipsco/obio/if_le.c Sun May 29 10:43:45 2022 +0000
+++ b/sys/arch/mipsco/obio/if_le.c Sun May 29 10:45:05 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_le.c,v 1.13 2010/01/19 22:06:21 pooka Exp $ */
+/* $NetBSD: if_le.c,v 1.14 2022/05/29 10:45:05 rin Exp $ */
/*-
* Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.13 2010/01/19 22:06:21 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.14 2022/05/29 10:45:05 rin Exp $");
#include "opt_inet.h"
@@ -177,25 +177,24 @@
if (bus_dmamem_alloc(dmat, LE_MEMSIZE, 0, 0, &seg, 1,
&rseg, BUS_DMA_NOWAIT)) {
aprint_error(": can't allocate DMA area\n");
- return;
+ goto bad_bsunmap;
}
/* Map pages into kernel memory */
if (bus_dmamem_map(dmat, &seg, rseg, LE_MEMSIZE,
&kvaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
aprint_error(": can't map DMA area\n");
- bus_dmamem_free(dmat, &seg, rseg);
- return;
+ goto bad_free;
}
/* Build DMA map so we can get physical address */
if (bus_dmamap_create(dmat, LE_MEMSIZE, 1, LE_MEMSIZE,
0, BUS_DMA_NOWAIT, &lesc->sc_dmamap)) {
aprint_error(": can't create DMA map\n");
- goto bad;
+ goto bad_unmap;
}
if (bus_dmamap_load(dmat, lesc->sc_dmamap, kvaddr, LE_MEMSIZE,
NULL, BUS_DMA_NOWAIT)) {
aprint_error(": can't load DMA map\n");
- goto bad;
+ goto bad_destroy;
}
sc->sc_memsize = LE_MEMSIZE; /* 16K Buffer space*/
@@ -226,9 +225,14 @@
am7990_config(&lesc->sc_am7990);
return;
-bad:
+ bad_destroy:
+ bus_dmamap_destroy(dmat, lesc->sc_dmamap);
+ bad_unmap:
bus_dmamem_unmap(dmat, kvaddr, LE_MEMSIZE);
+ bad_free:
bus_dmamem_free(dmat, &seg, rseg);
+ bad_bsunmap:
+ bus_space_unmap(ca->ca_bustag, lesc->sc_reg, 8);
}
int
diff -r dc90128d7704 -r c6b8210a958a sys/arch/mvme68k/dev/if_le.c
--- a/sys/arch/mvme68k/dev/if_le.c Sun May 29 10:43:45 2022 +0000
+++ b/sys/arch/mvme68k/dev/if_le.c Sun May 29 10:45:05 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_le.c,v 1.36 2010/01/19 22:06:21 pooka Exp $ */
+/* $NetBSD: if_le.c,v 1.37 2022/05/29 10:45:05 rin Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.36 2010/01/19 22:06:21 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.37 2022/05/29 10:45:05 rin Exp $");
#include "opt_inet.h"
@@ -179,13 +179,12 @@
&seg, 1, &rseg,
BUS_DMA_NOWAIT | BUS_DMA_ONBOARD_RAM | BUS_DMA_24BIT)) {
aprint_error(": Failed to allocate ether buffer\n");
- return;
+ goto bad_unmap;
}
if (bus_dmamem_map(pa->pa_dmat, &seg, rseg, ether_data_buff_size,
(void **)&sc->sc_mem, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) {
aprint_error(": Failed to map ether buffer\n");
- bus_dmamem_free(pa->pa_dmat, &seg, rseg);
- return;
+ goto bad_free;
}
sc->sc_addr = seg.ds_addr;
sc->sc_memsize = ether_data_buff_size;
@@ -212,4 +211,11 @@
pcc_reg_write(sys_pcc, PCCREG_LANCE_INTR_CTRL,
pa->pa_ipl | PCC_IENABLE);
+
+ return;
+
+ bad_free:
+ bus_dmamem_free(pa->pa_dmat, &seg, rseg);
+ bad_unmap:
+ bus_space_unmap(pa->pa_bust, lsc->sc_bush, 4);
}
diff -r dc90128d7704 -r c6b8210a958a sys/arch/sparc/dev/if_le_obio.c
--- a/sys/arch/sparc/dev/if_le_obio.c Sun May 29 10:43:45 2022 +0000
+++ b/sys/arch/sparc/dev/if_le_obio.c Sun May 29 10:45:05 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_le_obio.c,v 1.28 2019/04/25 10:08:45 msaitoh Exp $ */
+/* $NetBSD: if_le_obio.c,v 1.29 2022/05/29 10:45:05 rin Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_le_obio.c,v 1.28 2019/04/25 10:08:45 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_le_obio.c,v 1.29 2022/05/29 10:45:05 rin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -151,29 +151,26 @@
if ((error = bus_dmamap_create(dmatag, MEMSIZE, 1, MEMSIZE, 0,
BUS_DMA_NOWAIT|BUS_DMA_24BIT, &lesc->sc_dmamap)) != 0) {
aprint_error(": DMA map create error %d\n", error);
- return;
+ goto bad_bsunmap;
}
/* Allocate DMA buffer */
if ((error = bus_dmamem_alloc(dmatag, MEMSIZE, PAGE_SIZE, 0,
&seg, 1, &rseg, BUS_DMA_NOWAIT | BUS_DMA_24BIT)) != 0) {
aprint_error(": DMA memory allocation error %d\n", error);
- return;
+ goto bad_destroy;
}
/* Map DMA buffer into kernel space */
if ((error = bus_dmamem_map(dmatag, &seg, rseg, MEMSIZE,
(void **)&sc->sc_mem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
aprint_error(": DMA memory map error %d\n", error);
- bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
- return;
+ goto bad_free;
}
/* Load DMA buffer */
if ((error = bus_dmamap_load(dmatag, lesc->sc_dmamap,
sc->sc_mem, MEMSIZE, NULL, BUS_DMA_NOWAIT)) != 0) {
aprint_error(": DMA buffer map load error %d\n", error);
- bus_dmamem_unmap(dmatag, (void *)sc->sc_mem, MEMSIZE);
- bus_dmamem_free(dmatag, &seg, rseg);
- return;
+ goto bad_unmap;
}
sc->sc_addr = lesc->sc_dmamap->dm_segs[0].ds_addr & 0xffffff;
@@ -200,4 +197,15 @@
/* Install interrupt */
(void)bus_intr_establish(lesc->sc_bustag, oba->oba_pri, IPL_NET,
am7990_intr, sc);
+
+ return;
+
+ bad_unmap:
+ bus_dmamem_unmap(dmatag, (void *)sc->sc_mem, MEMSIZE);
+ bad_free:
+ bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
+ bad_destroy:
+ bus_dmamap_destroy(dmatag, lesc->sc_dmamap);
+ bad_bsunmap:
+ bus_space_unmap(oba->oba_bustag, lesc->sc_reg, 2 * sizeof(uint16_t));
}
diff -r dc90128d7704 -r c6b8210a958a sys/arch/vax/if/if_le_vsbus.c
--- a/sys/arch/vax/if/if_le_vsbus.c Sun May 29 10:43:45 2022 +0000
+++ b/sys/arch/vax/if/if_le_vsbus.c Sun May 29 10:45:05 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_le_vsbus.c,v 1.28 2010/12/14 23:38:30 matt Exp $ */
+/* $NetBSD: if_le_vsbus.c,v 1.29 2022/05/29 10:45:05 rin Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_le_vsbus.c,v 1.28 2010/12/14 23:38:30 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_le_vsbus.c,v 1.29 2022/05/29 10:45:05 rin Exp $");
#include "opt_inet.h"
@@ -229,23 +229,19 @@
BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
if (err) {
aprint_error(": unable to map buffer block: err %d\n", err);
- bus_dmamem_free(va->va_dmat, &seg, rseg);
- return;
+ goto bad_free;
}
bus_dmamap_create(va->va_dmat, ALLOCSIZ, rseg, ALLOCSIZ,
0, BUS_DMA_NOWAIT, &sc->sc_dm);
if (err) {
aprint_error(": unable to create DMA map: err %d\n", err);
- bus_dmamem_free(va->va_dmat, &seg, rseg);
- return;
+ goto bad_unmap;
}
err = bus_dmamap_load(va->va_dmat, sc->sc_dm, sc->sc_am7990.lsc.sc_mem,
ALLOCSIZ, NULL, BUS_DMA_NOWAIT);
if (err) {
aprint_error(": unable to load DMA map: err %d\n", err);
- bus_dmamap_destroy(va->va_dmat, sc->sc_dm);
- bus_dmamem_free(va->va_dmat, &seg, rseg);
- return;
+ goto bad_destroy;
}
aprint_normal(" buf 0x%lx-0x%lx", sc->sc_dm->dm_segs->ds_addr,
sc->sc_dm->dm_segs->ds_addr + sc->sc_dm->dm_segs->ds_len - 1);
@@ -276,4 +272,13 @@
aprint_normal("\n%s", device_xname(self));
am7990_config(&sc->sc_am7990);
+
+ return;
+
+ bad_destroy:
Home |
Main Index |
Thread Index |
Old Index