Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys If if_initialize() failed in the attach function, free r...
details: https://anonhg.NetBSD.org/src/rev/a51f63ccaddf
branches: trunk
changeset: 357014:a51f63ccaddf
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Mon Oct 23 09:31:17 2017 +0000
description:
If if_initialize() failed in the attach function, free resources and return.
diffstat:
sys/arch/usermode/dev/if_veth.c | 13 ++++++++++---
sys/dev/ic/bwfm.c | 12 ++++++++++--
sys/dev/ic/malo.c | 17 +++++++++++++----
sys/dev/ic/rt2560.c | 12 +++++++++---
sys/dev/ic/rt2661.c | 12 +++++++++---
sys/dev/ic/rt2860.c | 24 +++++++++++++++++++++---
sys/dev/ic/rtw.c | 12 +++++++++---
sys/dev/ic/rtwvar.h | 6 +++---
sys/dev/ic/wi.c | 15 +++++++++++----
sys/dev/pci/if_ipw.c | 12 +++++++++---
sys/dev/pci/if_iwn.c | 12 +++++++++---
sys/dev/pci/if_rtwn.c | 18 +++++++++++++-----
sys/dev/pci/if_wpi.c | 12 +++++++++---
sys/dev/pci/ixgbe/ixgbe.c | 9 +++++++--
sys/dev/pci/ixgbe/ixv.c | 21 +++++++++++++++------
sys/dev/scsipi/if_se.c | 13 ++++++++++---
sys/net/if_etherip.c | 12 +++++++++---
sys/net/if_gif.c | 26 ++++++++++++++++++--------
sys/net/if_vlan.c | 26 ++++++++++++++++++++++----
sys/netinet/ip_carp.c | 15 ++++++++++++---
sys/rump/net/lib/libshmif/if_shmem.c | 14 +++++++++++---
21 files changed, 239 insertions(+), 74 deletions(-)
diffs (truncated from 917 to 300 lines):
diff -r c81b26a09afa -r a51f63ccaddf sys/arch/usermode/dev/if_veth.c
--- a/sys/arch/usermode/dev/if_veth.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/arch/usermode/dev/if_veth.c Mon Oct 23 09:31:17 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_veth.c,v 1.8 2016/12/15 09:28:04 ozaki-r Exp $ */
+/* $NetBSD: if_veth.c,v 1.9 2017/10/23 09:31:17 msaitoh Exp $ */
/*-
* Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_veth.c,v 1.8 2016/12/15 09:28:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_veth.c,v 1.9 2017/10/23 09:31:17 msaitoh Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@@ -102,6 +102,7 @@
struct veth_softc *sc = device_private(self);
struct thunkbus_attach_args *taa = opaque;
struct ifnet *ifp = &sc->sc_ec.ec_if;
+ int rv;
sc->sc_dev = self;
@@ -137,7 +138,13 @@
IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
IFQ_SET_READY(&ifq->if_snd);
- if_initialize(ifp);
+ rv = if_initialize(ifp);
+ if (rv != 0) {
+ aprint_error_dev(self, "if_initialize failed(%d)\n", rv);
+ thunk_close(sc->sc_tapfd);
+ pmf_device_deregister(self);
+ return; /* Error */
+ }
ether_ifattach(ifp, sc->sc_eaddr);
if_register(ifp);
diff -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/bwfm.c
--- a/sys/dev/ic/bwfm.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/bwfm.c Mon Oct 23 09:31:17 2017 +0000
@@ -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 @@
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 -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/malo.c
--- a/sys/dev/ic/malo.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/malo.c Mon Oct 23 09:31:17 2017 +0000
@@ -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 @@
{
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 @@
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 -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/rt2560.c
--- a/sys/dev/ic/rt2560.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/rt2560.c Mon Oct 23 09:31:17 2017 +0000
@@ -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 @@
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 @@
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 -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/rt2661.c
--- a/sys/dev/ic/rt2661.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/rt2661.c Mon Oct 23 09:31:17 2017 +0000
@@ -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 @@
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 @@
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 -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/rt2860.c
--- a/sys/dev/ic/rt2860.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/rt2860.c Mon Oct 23 09:31:17 2017 +0000
@@ -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 @@
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 -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/rtw.c
--- a/sys/dev/ic/rtw.c Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/rtw.c Mon Oct 23 09:31:17 2017 +0000
@@ -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_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 @@
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 -r c81b26a09afa -r a51f63ccaddf sys/dev/ic/rtwvar.h
--- a/sys/dev/ic/rtwvar.h Mon Oct 23 09:28:38 2017 +0000
+++ b/sys/dev/ic/rtwvar.h Mon Oct 23 09:31:17 2017 +0000
@@ -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 @@
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 {
Home |
Main Index |
Thread Index |
Old Index