diff options
| author | riastradh <riastradh@NetBSD.org> | 2021-06-16 00:21:17 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2021-06-16 00:21:17 +0000 |
| commit | bbdda93be2f0bfefe91466b398fe42700a6ea284 (patch) | |
| tree | e75e77046575209dbb21f73d0bc44c61ec0ec6c0 /sys/dev/ic | |
| parent | 5a96957fa793651c8e7093a5a4c2fcae87232af2 (diff) | |
if_attach and if_initialize cannot fail, don't test return value
These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:
https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html
However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:
https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html
So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)
There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.
(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)
Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
Diffstat (limited to 'sys/dev/ic')
| -rw-r--r-- | sys/dev/ic/an.c | 10 | ||||
| -rw-r--r-- | sys/dev/ic/athn.c | 15 | ||||
| -rw-r--r-- | sys/dev/ic/atw.c | 11 | ||||
| -rw-r--r-- | sys/dev/ic/bwfm.c | 12 | ||||
| -rw-r--r-- | sys/dev/ic/bwi.c | 11 | ||||
| -rw-r--r-- | sys/dev/ic/dwc_gmac.c | 15 | ||||
| -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 | 10 | ||||
| -rw-r--r-- | sys/dev/ic/wi.c | 15 |
12 files changed, 37 insertions, 127 deletions
diff --git a/sys/dev/ic/an.c b/sys/dev/ic/an.c index 939e2915e54..4804ffca48c 100644 --- a/sys/dev/ic/an.c +++ b/sys/dev/ic/an.c @@ -1,4 +1,4 @@ -/* $NetBSD: an.c,v 1.74 2021/06/11 05:00:41 jdc Exp $ */ +/* $NetBSD: an.c,v 1.75 2021/06/16 00:21:18 riastradh Exp $ */ /* * Copyright (c) 1997, 1998, 1999 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.74 2021/06/11 05:00:41 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.75 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> @@ -315,11 +315,7 @@ an_attach(struct an_softc *sc) /* * Call MI attach routine. */ - rv = if_initialize(ifp); - if (rv != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", rv); - goto fail_2; - } + if_initialize(ifp); ieee80211_ifattach(ic); ifp->if_percpuq = if_percpuq_create(ifp); if_register(ifp); diff --git a/sys/dev/ic/athn.c b/sys/dev/ic/athn.c index b6163dcf5a4..0a5779938c7 100644 --- a/sys/dev/ic/athn.c +++ b/sys/dev/ic/athn.c @@ -1,4 +1,4 @@ -/* $NetBSD: athn.c,v 1.24 2020/11/15 12:33:53 mlelstv Exp $ */ +/* $NetBSD: athn.c,v 1.25 2021/06/16 00:21:18 riastradh Exp $ */ /* $OpenBSD: athn.c,v 1.83 2014/07/22 13:12:11 mpi Exp $ */ /*- @@ -23,7 +23,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: athn.c,v 1.24 2020/11/15 12:33:53 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: athn.c,v 1.25 2021/06/16 00:21:18 riastradh Exp $"); #ifndef _MODULE #include "athn_usb.h" /* for NATHN_USB */ @@ -348,16 +348,7 @@ athn_attach(struct athn_softc *sc) IFQ_SET_READY(&ifp->if_snd); memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); - error = if_initialize(ifp); - if (error != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", - error); - pmf_event_deregister(sc->sc_dev, PMFE_RADIO_OFF, - athn_pmf_wlan_off, false); - callout_destroy(&sc->sc_scan_to); - callout_destroy(&sc->sc_calib_to); - return error; - } + if_initialize(ifp); ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); diff --git a/sys/dev/ic/atw.c b/sys/dev/ic/atw.c index 4367ee58b9a..c628da6d61f 100644 --- a/sys/dev/ic/atw.c +++ b/sys/dev/ic/atw.c @@ -1,4 +1,4 @@ -/* $NetBSD: atw.c,v 1.170 2020/01/29 14:09:58 thorpej Exp $ */ +/* $NetBSD: atw.c,v 1.171 2021/06/16 00:21:18 riastradh Exp $ */ /*- * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: atw.c,v 1.170 2020/01/29 14:09:58 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: atw.c,v 1.171 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> @@ -780,12 +780,7 @@ atw_attach(struct atw_softc *sc) * Call MI attach routines. */ - error = if_initialize(ifp); - if (error != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", - error); - goto fail_5; - } + if_initialize(ifp); ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); diff --git a/sys/dev/ic/bwfm.c b/sys/dev/ic/bwfm.c index 89c1b08aefa..b42abf3004c 100644 --- a/sys/dev/ic/bwfm.c +++ b/sys/dev/ic/bwfm.c @@ -1,4 +1,4 @@ -/* $NetBSD: bwfm.c,v 1.30 2021/04/13 04:13:52 mrg Exp $ */ +/* $NetBSD: bwfm.c,v 1.31 2021/06/16 00:21:18 riastradh Exp $ */ /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */ /* * Copyright (c) 2010-2016 Broadcom Corporation @@ -422,15 +422,7 @@ bwfm_attach(struct bwfm_softc *sc) IFQ_SET_READY(&ifp->if_snd); memcpy(ifp->if_xname, DEVNAME(sc), IFNAMSIZ); - error = if_initialize(ifp); - if (error != 0) { - printf("%s: if_initialize failed(%d)\n", DEVNAME(sc), error); - pool_cache_destroy(sc->sc_freetask); - workqueue_destroy(sc->sc_taskq); - - return; /* Error */ - } - + if_initialize(ifp); ieee80211_ifattach(ic); sc->sc_newstate = ic->ic_newstate; ic->ic_newstate = bwfm_newstate; diff --git a/sys/dev/ic/bwi.c b/sys/dev/ic/bwi.c index 32c819de01c..4483d23043c 100644 --- a/sys/dev/ic/bwi.c +++ b/sys/dev/ic/bwi.c @@ -1,4 +1,4 @@ -/* $NetBSD: bwi.c,v 1.37 2020/01/29 14:14:55 thorpej Exp $ */ +/* $NetBSD: bwi.c,v 1.38 2021/06/16 00:21:18 riastradh Exp $ */ /* $OpenBSD: bwi.c,v 1.74 2008/02/25 21:13:30 mglocker Exp $ */ /* @@ -48,7 +48,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bwi.c,v 1.37 2020/01/29 14:14:55 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bwi.c,v 1.38 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> #include <sys/callout.h> @@ -1021,12 +1021,7 @@ bwi_attach(struct bwi_softc *sc) ic->ic_updateslot = bwi_updateslot; - error = if_initialize(ifp); - if (error != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", - error); - goto fail; - } + if_initialize(ifp); ieee80211_ifattach(ic); ifp->if_percpuq = if_percpuq_create(ifp); if_register(ifp); diff --git a/sys/dev/ic/dwc_gmac.c b/sys/dev/ic/dwc_gmac.c index e12d86a8ffa..1d2a7fa50a0 100644 --- a/sys/dev/ic/dwc_gmac.c +++ b/sys/dev/ic/dwc_gmac.c @@ -1,4 +1,4 @@ -/* $NetBSD: dwc_gmac.c,v 1.73 2021/05/13 05:56:39 msaitoh Exp $ */ +/* $NetBSD: dwc_gmac.c,v 1.74 2021/06/16 00:21:18 riastradh Exp $ */ /*- * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.73 2021/05/13 05:56:39 msaitoh Exp $"); +__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.74 2021/06/16 00:21:18 riastradh Exp $"); /* #define DWC_GMAC_DEBUG 1 */ @@ -188,7 +188,6 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, int phy_id, uint32_t mii_clk) struct mii_data * const mii = &sc->sc_mii; struct ifnet * const ifp = &sc->sc_ec.ec_if; prop_dictionary_t dict; - int rv; mutex_init(&sc->sc_mdio_lock, MUTEX_DEFAULT, IPL_NET); sc->sc_mii_clk = mii_clk & 7; @@ -332,9 +331,7 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, int phy_id, uint32_t mii_clk) * Ready, attach interface */ /* Attach the interface. */ - rv = if_initialize(ifp); - if (rv != 0) - goto fail_2; + if_initialize(ifp); sc->sc_ipq = if_percpuq_create(&sc->sc_ec.ec_if); if_deferred_start_init(ifp, NULL); ether_ifattach(ifp, enaddr); @@ -355,12 +352,6 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, int phy_id, uint32_t mii_clk) return 0; -fail_2: - ifmedia_removeall(&mii->mii_media); - mii_detach(mii, MII_PHY_ANY, MII_OFFSET_ANY); - mutex_destroy(&sc->sc_txq.t_mtx); - mutex_destroy(&sc->sc_rxq.r_mtx); - mutex_obj_free(sc->sc_lock); fail: dwc_gmac_free_rx_ring(sc, &sc->sc_rxq); dwc_gmac_free_tx_ring(sc, &sc->sc_txq); diff --git a/sys/dev/ic/malo.c b/sys/dev/ic/malo.c index 535645dddcf..07aba8cd77d 100644 --- a/sys/dev/ic/malo.c +++ b/sys/dev/ic/malo.c @@ -1,4 +1,4 @@ -/* $NetBSD: malo.c,v 1.18 2020/01/29 15:00:39 thorpej Exp $ */ +/* $NetBSD: malo.c,v 1.19 2021/06/16 00:21:18 riastradh 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.18 2020/01/29 15:00:39 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: malo.c,v 1.19 2021/06/16 00:21:18 riastradh 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, rv; + int i; /* initialize channel scanning timer */ callout_init(&sc->sc_scan_to, 0); @@ -422,16 +422,7 @@ malo_attach(struct malo_softc *sc) aprint_normal(", address %s\n", ether_sprintf(ic->ic_myaddr)); /* attach interface */ - 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 */ - } + if_initialize(ifp); 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 7d21b6b820c..b32f6de6f8e 100644 --- a/sys/dev/ic/rt2560.c +++ b/sys/dev/ic/rt2560.c @@ -1,4 +1,4 @@ -/* $NetBSD: rt2560.c,v 1.38 2020/01/29 15:06:12 thorpej Exp $ */ +/* $NetBSD: rt2560.c,v 1.39 2021/06/16 00:21:18 riastradh 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.38 2020/01/29 15:06:12 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rt2560.c,v 1.39 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> @@ -441,12 +441,7 @@ rt2560_attach(void *xsc, int id) IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; } - error = if_initialize(ifp); - if (error != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", - error); - goto fail6; - } + if_initialize(ifp); ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -485,7 +480,6 @@ 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 8be915d72f5..3bdeed88e45 100644 --- a/sys/dev/ic/rt2661.c +++ b/sys/dev/ic/rt2661.c @@ -1,4 +1,4 @@ -/* $NetBSD: rt2661.c,v 1.43 2020/01/29 15:06:12 thorpej Exp $ */ +/* $NetBSD: rt2661.c,v 1.44 2021/06/16 00:21:18 riastradh 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.43 2020/01/29 15:06:12 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rt2661.c,v 1.44 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> @@ -330,12 +330,7 @@ rt2661_attach(void *xsc, int id) IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; } - error = if_initialize(ifp); - if (error != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", - error); - goto fail7; - } + if_initialize(ifp); ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -373,7 +368,6 @@ 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 d4b9dd6271c..0238b02bad0 100644 --- a/sys/dev/ic/rt2860.c +++ b/sys/dev/ic/rt2860.c @@ -1,4 +1,4 @@ -/* $NetBSD: rt2860.c,v 1.35 2020/01/29 15:06:12 thorpej Exp $ */ +/* $NetBSD: rt2860.c,v 1.36 2021/06/16 00:21:18 riastradh 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.35 2020/01/29 15:06:12 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rt2860.c,v 1.36 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> #include <sys/sockio.h> @@ -401,25 +401,7 @@ rt2860_attachhook(device_t self) IFQ_SET_READY(&ifp->if_snd); memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); - 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; - } + if_initialize(ifp); 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 d88f3f070c0..6249e566e6a 100644 --- a/sys/dev/ic/rtw.c +++ b/sys/dev/ic/rtw.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtw.c,v 1.135 2020/01/29 15:06:12 thorpej Exp $ */ +/* $NetBSD: rtw.c,v 1.136 2021/06/16 00:21:18 riastradh 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.135 2020/01/29 15:06:12 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtw.c,v 1.136 2021/06/16 00:21:18 riastradh Exp $"); #include <sys/param.h> @@ -4224,11 +4224,7 @@ rtw_attach(struct rtw_softc *sc) /* * Call MI attach routines. */ - rc = if_initialize(ifp); - if (rc != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", rc); - goto err; - } + if_initialize(ifp); ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); diff --git a/sys/dev/ic/wi.c b/sys/dev/ic/wi.c index 787fcc481a9..602ce27ce55 100644 --- a/sys/dev/ic/wi.c +++ b/sys/dev/ic/wi.c @@ -1,4 +1,4 @@ -/* $NetBSD: wi.c,v 1.255 2020/01/30 04:56:11 thorpej Exp $ */ +/* $NetBSD: wi.c,v 1.256 2021/06/16 00:21:18 riastradh Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -99,7 +99,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.255 2020/01/30 04:56:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.256 2021/06/16 00:21:18 riastradh Exp $"); #define WI_HERMES_AUTOINC_WAR /* Work around data write autoinc bug. */ #define WI_HERMES_STATS_WAR /* Work around stats counter bug. */ @@ -370,7 +370,7 @@ wi_attach(struct wi_softc *sc, const uint8_t *macaddr) static const uint8_t empty_macaddr[IEEE80211_ADDR_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int s, rv; + int s; sc->sc_soft_ih = softint_establish(SOFTINT_NET, wi_softintr, sc); if (sc->sc_soft_ih == NULL) { @@ -546,11 +546,7 @@ wi_attach(struct wi_softc *sc, const uint8_t *macaddr) /* * Call MI attach routines. */ - rv = if_initialize(ifp); - if (rv != 0) { - aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n", rv); - goto fail_2; - } + if_initialize(ifp); ieee80211_ifattach(ic); /* Use common softint-based if_input */ ifp->if_percpuq = if_percpuq_create(ifp); @@ -588,9 +584,6 @@ wi_attach(struct wi_softc *sc, const uint8_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; |
