diff options
| author | msaitoh <msaitoh@NetBSD.org> | 2017-10-23 09:31:17 +0000 |
|---|---|---|
| committer | msaitoh <msaitoh@NetBSD.org> | 2017-10-23 09:31:17 +0000 |
| commit | 4cec6d9cb8de1b0b8ecf9bffdea9156c488dfd6d (patch) | |
| tree | c1fbf974dd641cff1dfa324f2ea7746a0d63e050 /sys/dev/ic | |
| parent | 766faa964e36ca6d493d4da0f589620950c3db2d (diff) | |
If if_initialize() failed in the attach function, free resources and return.
Diffstat (limited to 'sys/dev/ic')
| -rw-r--r-- | sys/dev/ic/bwfm.c | 12 | ||||
| -rw-r--r-- | sys/dev/ic/malo.c | 17 | ||||
| -rw-r--r-- | sys/dev/ic/rt2560.c | 12 | ||||
| -rw-r--r-- | sys/dev/ic/rt2661.c | 12 | ||||
| -rw-r--r-- | sys/dev/ic/rt2860.c | 24 | ||||
| -rw-r--r-- | sys/dev/ic/rtw.c | 12 | ||||
| -rw-r--r-- | sys/dev/ic/rtwvar.h | 6 | ||||
| -rw-r--r-- | sys/dev/ic/wi.c | 15 |
8 files changed, 85 insertions, 25 deletions
diff --git a/sys/dev/ic/bwfm.c b/sys/dev/ic/bwfm.c index e80c44e6ea8..b608f2a5dee 100644 --- a/sys/dev/ic/bwfm.c +++ b/sys/dev/ic/bwfm.c @@ -1,4 +1,4 @@ -/* $NetBSD: bwfm.c,v 1.2 2017/10/20 23:38:21 jmcneill Exp $ */ +/* $NetBSD: bwfm.c,v 1.3 2017/10/23 09:31:17 msaitoh Exp $ */ /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */ /* * Copyright (c) 2010-2016 Broadcom Corporation @@ -232,7 +232,15 @@ bwfm_attach(struct bwfm_softc *sc) IFQ_SET_READY(&ifp->if_snd); memcpy(ifp->if_xname, DEVNAME(sc), IFNAMSIZ); - if_initialize(ifp); + error = if_initialize(ifp); + if (error != 0) { + printf("%s: if_initialize failed(%d)\n", DEVNAME(sc), error); + pcq_destroy(sc->sc_freetask); + workqueue_destroy(sc->sc_taskq); + + return; /* Error */ + } + ieee80211_ifattach(ic); ifp->if_percpuq = if_percpuq_create(ifp); if_deferred_start_init(ifp, NULL); diff --git a/sys/dev/ic/malo.c b/sys/dev/ic/malo.c index f61ae673071..1be86e6eaef 100644 --- a/sys/dev/ic/malo.c +++ b/sys/dev/ic/malo.c @@ -1,4 +1,4 @@ -/* $NetBSD: malo.c,v 1.9 2017/02/02 10:05:35 nonaka Exp $ */ +/* $NetBSD: malo.c,v 1.10 2017/10/23 09:31:17 msaitoh Exp $ */ /* $OpenBSD: malo.c,v 1.92 2010/08/27 17:08:00 jsg Exp $ */ /* @@ -19,7 +19,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: malo.c,v 1.9 2017/02/02 10:05:35 nonaka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: malo.c,v 1.10 2017/10/23 09:31:17 msaitoh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -366,7 +366,7 @@ malo_attach(struct malo_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &sc->sc_if; - int i; + int i, rv; /* initialize channel scanning timer */ callout_init(&sc->sc_scan_to, 0); @@ -422,7 +422,16 @@ malo_attach(struct malo_softc *sc) aprint_normal(", address %s\n", ether_sprintf(ic->ic_myaddr)); /* attach interface */ - if_initialize(ifp); + rv = if_initialize(ifp); + if (rv != 0) { + aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", rv); + malo_free_tx_ring(sc, &sc->sc_txring); + malo_free_rx_ring(sc, &sc->sc_rxring); + malo_free_cmd(sc); + callout_destroy(&sc->sc_scan_to); + + return rv; /* Error */ + } ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); diff --git a/sys/dev/ic/rt2560.c b/sys/dev/ic/rt2560.c index 279556877d3..2eaade2f328 100644 --- a/sys/dev/ic/rt2560.c +++ b/sys/dev/ic/rt2560.c @@ -1,4 +1,4 @@ -/* $NetBSD: rt2560.c,v 1.30 2017/05/23 02:19:14 ozaki-r Exp $ */ +/* $NetBSD: rt2560.c,v 1.31 2017/10/23 09:31:17 msaitoh Exp $ */ /* $OpenBSD: rt2560.c,v 1.15 2006/04/20 20:31:12 miod Exp $ */ /* $FreeBSD: rt2560.c,v 1.3 2006/03/21 21:15:43 damien Exp $*/ @@ -24,7 +24,7 @@ * http://www.ralinktech.com/ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rt2560.c,v 1.30 2017/05/23 02:19:14 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rt2560.c,v 1.31 2017/10/23 09:31:17 msaitoh Exp $"); #include <sys/param.h> @@ -453,7 +453,12 @@ rt2560_attach(void *xsc, int id) IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; } - if_initialize(ifp); + error = if_initialize(ifp); + if (error != 0) { + aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", + error); + goto fail6; + } ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -492,6 +497,7 @@ rt2560_attach(void *xsc, int id) return 0; +fail6: rt2560_free_rx_ring(sc, &sc->rxq); fail5: rt2560_free_tx_ring(sc, &sc->bcnq); fail4: rt2560_free_tx_ring(sc, &sc->prioq); fail3: rt2560_free_tx_ring(sc, &sc->atimq); diff --git a/sys/dev/ic/rt2661.c b/sys/dev/ic/rt2661.c index ffc65d2f10f..2be74b5e2f0 100644 --- a/sys/dev/ic/rt2661.c +++ b/sys/dev/ic/rt2661.c @@ -1,4 +1,4 @@ -/* $NetBSD: rt2661.c,v 1.35 2017/05/23 02:19:14 ozaki-r Exp $ */ +/* $NetBSD: rt2661.c,v 1.36 2017/10/23 09:31:17 msaitoh Exp $ */ /* $OpenBSD: rt2661.c,v 1.17 2006/05/01 08:41:11 damien Exp $ */ /* $FreeBSD: rt2560.c,v 1.5 2006/06/02 19:59:31 csjp Exp $ */ @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rt2661.c,v 1.35 2017/05/23 02:19:14 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rt2661.c,v 1.36 2017/10/23 09:31:17 msaitoh Exp $"); #include <sys/param.h> @@ -342,7 +342,12 @@ rt2661_attach(void *xsc, int id) IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; } - if_initialize(ifp); + error = if_initialize(ifp); + if (error != 0) { + aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", + error); + goto fail7; + } ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -380,6 +385,7 @@ rt2661_attach(void *xsc, int id) return 0; +fail7: rt2661_free_rx_ring(sc, &sc->rxq); fail6: rt2661_free_tx_ring(sc, &sc->mgtq); fail5: rt2661_free_tx_ring(sc, &sc->txq[3]); fail4: rt2661_free_tx_ring(sc, &sc->txq[2]); diff --git a/sys/dev/ic/rt2860.c b/sys/dev/ic/rt2860.c index f78957721e1..c3abefeb531 100644 --- a/sys/dev/ic/rt2860.c +++ b/sys/dev/ic/rt2860.c @@ -1,4 +1,4 @@ -/* $NetBSD: rt2860.c,v 1.28 2017/07/25 23:17:20 maya Exp $ */ +/* $NetBSD: rt2860.c,v 1.29 2017/10/23 09:31:17 msaitoh Exp $ */ /* $OpenBSD: rt2860.c,v 1.90 2016/04/13 10:49:26 mpi Exp $ */ /* $FreeBSD: head/sys/dev/ral/rt2860.c 306591 2016-10-02 20:35:55Z avos $ */ @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rt2860.c,v 1.28 2017/07/25 23:17:20 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rt2860.c,v 1.29 2017/10/23 09:31:17 msaitoh Exp $"); #include <sys/param.h> #include <sys/sockio.h> @@ -401,7 +401,25 @@ rt2860_attachhook(device_t self) IFQ_SET_READY(&ifp->if_snd); memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); - if_initialize(ifp); + error = if_initialize(ifp); + if (error != 0) { + int qid; + + aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", + error); + for (qid = 0; qid < MAXQS; qid++) + rt2860_free_tx_ring(sc, &sc->txq[qid]); + rt2860_free_rx_ring(sc, &sc->rxq); + rt2860_free_tx_pool(sc); + + if (sc->sc_soft_ih != NULL) { + softint_disestablish(sc->sc_soft_ih); + sc->sc_soft_ih = NULL; + } + if (sc->ucode != NULL) + firmware_free(sc->ucode, sc->ucsize); + return; + } ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); diff --git a/sys/dev/ic/rtw.c b/sys/dev/ic/rtw.c index 83854e19c50..69581e02a18 100644 --- a/sys/dev/ic/rtw.c +++ b/sys/dev/ic/rtw.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtw.c,v 1.126 2017/05/23 02:19:14 ozaki-r Exp $ */ +/* $NetBSD: rtw.c,v 1.127 2017/10/23 09:31:17 msaitoh Exp $ */ /*- * Copyright (c) 2004, 2005, 2006, 2007 David Young. All rights * reserved. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rtw.c,v 1.126 2017/05/23 02:19:14 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtw.c,v 1.127 2017/10/23 09:31:17 msaitoh Exp $"); #include <sys/param.h> @@ -4225,11 +4225,16 @@ rtw_attach(struct rtw_softc *sc) rtw_set80211props(&sc->sc_ic); rtw_led_attach(&sc->sc_led_state, (void *)sc); + NEXT_ATTACH_STATE(sc, FINISH_LED_ATTACH); /* * Call MI attach routines. */ - if_initialize(ifp); + rc = if_initialize(ifp); + if (rc != 0) { + aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", rc); + goto err; + } ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -4276,6 +4281,7 @@ rtw_detach(struct rtw_softc *sc) callout_stop(&sc->sc_scan_ch); ieee80211_ifdetach(&sc->sc_ic); if_detach(ifp); + case FINISH_LED_ATTACH: rtw_led_detach(&sc->sc_led_state); /*FALLTHROUGH*/ case FINISH_ID_STA: diff --git a/sys/dev/ic/rtwvar.h b/sys/dev/ic/rtwvar.h index 4f362eab3d6..89ac642b926 100644 --- a/sys/dev/ic/rtwvar.h +++ b/sys/dev/ic/rtwvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: rtwvar.h,v 1.45 2017/02/02 10:05:35 nonaka Exp $ */ +/* $NetBSD: rtwvar.h,v 1.46 2017/10/23 09:31:17 msaitoh Exp $ */ /*- * Copyright (c) 2004, 2005 David Young. All rights reserved. * @@ -313,8 +313,8 @@ struct rtw_tx_radiotap_header { enum rtw_attach_state {FINISHED, FINISH_DESCMAP_LOAD, FINISH_DESCMAP_CREATE, FINISH_DESC_MAP, FINISH_DESC_ALLOC, FINISH_RXMAPS_CREATE, FINISH_TXMAPS_CREATE, FINISH_RESET, FINISH_READ_SROM, FINISH_PARSE_SROM, - FINISH_RF_ATTACH, FINISH_ID_STA, FINISH_TXDESCBLK_SETUP, - FINISH_TXCTLBLK_SETUP, DETACHED}; + FINISH_RF_ATTACH, FINISH_ID_STA, FINISH_LED_ATTACH, + FINISH_TXDESCBLK_SETUP, FINISH_TXCTLBLK_SETUP, DETACHED}; struct rtw_mtbl { int (*mt_newstate)(struct ieee80211com *, diff --git a/sys/dev/ic/wi.c b/sys/dev/ic/wi.c index 8314f7fef73..aa7cc812e6d 100644 --- a/sys/dev/ic/wi.c +++ b/sys/dev/ic/wi.c @@ -1,4 +1,4 @@ -/* $NetBSD: wi.c,v 1.243 2017/03/29 09:04:35 msaitoh Exp $ */ +/* $NetBSD: wi.c,v 1.244 2017/10/23 09:31:17 msaitoh Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -99,7 +99,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.243 2017/03/29 09:04:35 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.244 2017/10/23 09:31:17 msaitoh Exp $"); #define WI_HERMES_AUTOINC_WAR /* Work around data write autoinc bug. */ #define WI_HERMES_STATS_WAR /* Work around stats counter bug. */ @@ -373,7 +373,7 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr) static const u_int8_t empty_macaddr[IEEE80211_ADDR_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int s; + int s, rv; sc->sc_soft_ih = softint_establish(SOFTINT_NET, wi_softintr, sc); if (sc->sc_soft_ih == NULL) { @@ -550,7 +550,11 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr) /* * Call MI attach routines. */ - if_initialize(ifp); + rv = if_initialize(ifp); + if (rv != 0) { + aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", rv); + goto fail_2; + } ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -588,6 +592,9 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr) ieee80211_announce(ic); return 0; +fail_2: + callout_destroy(&sc->sc_rssadapt_ch); + fail: splx(s); softint_disestablish(sc->sc_soft_ih); sc->sc_soft_ih = NULL; |
