Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys If error occured in the attach function, free resources ...
details: https://anonhg.NetBSD.org/src/rev/241a22782651
branches: trunk
changeset: 827308:241a22782651
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Mon Oct 23 09:24:34 2017 +0000
description:
If error occured in the attach function, free resources and return.
diffstat:
sys/dev/ic/an.c | 40 +++++++++++++++++++++++------------
sys/dev/pcmcia/if_malo_pcmcia.c | 24 +++++++++++++++++----
sys/rump/net/lib/libvirtif/if_virt.c | 20 +++++++++++++++--
3 files changed, 62 insertions(+), 22 deletions(-)
diffs (223 lines):
diff -r 40d2f504073e -r 241a22782651 sys/dev/ic/an.c
--- a/sys/dev/ic/an.c Mon Oct 23 09:23:48 2017 +0000
+++ b/sys/dev/ic/an.c Mon Oct 23 09:24:34 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: an.c,v 1.65 2017/05/23 02:19:14 ozaki-r Exp $ */
+/* $NetBSD: an.c,v 1.66 2017/10/23 09:24:34 msaitoh Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
* Bill Paul <wpaul%ctr.columbia.edu@localhost>. All rights reserved.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.65 2017/05/23 02:19:14 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.66 2017/10/23 09:24:34 msaitoh Exp $");
#include <sys/param.h>
@@ -166,7 +166,7 @@
{
struct ieee80211com *ic = &sc->sc_ic;
struct ifnet *ifp = &sc->sc_if;
- int i, s;
+ int i, s, rv = 0;
struct an_rid_wepkey *akey;
int buflen, kid, rid;
int chan, chan_min, chan_max;
@@ -176,38 +176,38 @@
an_wait(sc);
if (an_reset(sc) != 0) {
config_deactivate(sc->sc_dev);
- splx(s);
- return 1;
+ rv = 1;
+ goto fail_1;
}
sc->sc_soft_ih = softint_establish(SOFTINT_NET, an_softintr, sc);
if (sc->sc_soft_ih == NULL) {
- splx(s);
aprint_error_dev(sc->sc_dev, "failed to establish softint\n");
- return 1;
+ rv = 1;
+ goto fail_1;
}
/* Load factory config */
if (an_cmd(sc, AN_CMD_READCFG, 0) != 0) {
- splx(s);
aprint_error_dev(sc->sc_dev, "failed to load config data\n");
- return 1;
+ rv = 1;
+ goto fail_2;
}
/* Read the current configuration */
buflen = sizeof(sc->sc_config);
if (an_read_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, &buflen) != 0) {
- splx(s);
aprint_error_dev(sc->sc_dev, "read config failed\n");
- return 1;
+ rv = 1;
+ goto fail_2;
}
/* Read the card capabilities */
buflen = sizeof(sc->sc_caps);
if (an_read_rid(sc, AN_RID_CAPABILITIES, &sc->sc_caps, &buflen) != 0) {
- splx(s);
aprint_error_dev(sc->sc_dev, "read caps failed\n");
- return 1;
+ rv = 1;
+ goto fail_2;
}
#ifdef AN_DEBUG
@@ -317,7 +317,11 @@
/*
* Call MI attach routine.
*/
- 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);
ifp->if_percpuq = if_percpuq_create(ifp);
if_register(ifp);
@@ -346,6 +350,14 @@
ieee80211_announce(ic);
return 0;
+
+fail_2:
+ if (sc->sc_soft_ih != NULL)
+ softint_disestablish(sc->sc_soft_ih);
+fail_1:
+ splx(s);
+
+ return rv;
}
#ifdef AN_DEBUG
diff -r 40d2f504073e -r 241a22782651 sys/dev/pcmcia/if_malo_pcmcia.c
--- a/sys/dev/pcmcia/if_malo_pcmcia.c Mon Oct 23 09:23:48 2017 +0000
+++ b/sys/dev/pcmcia/if_malo_pcmcia.c Mon Oct 23 09:24:34 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_malo_pcmcia.c,v 1.14 2017/06/25 12:25:02 maxv Exp $ */
+/* $NetBSD: if_malo_pcmcia.c,v 1.15 2017/10/23 09:24:34 msaitoh Exp $ */
/* $OpenBSD: if_malo.c,v 1.65 2009/03/29 21:53:53 sthen Exp $ */
/*
@@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_malo_pcmcia.c,v 1.14 2017/06/25 12:25:02 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_malo_pcmcia.c,v 1.15 2017/10/23 09:24:34 msaitoh Exp $");
#ifdef _MODULE
#include <sys/module.h>
@@ -307,7 +307,7 @@
struct malo_softc *sc = arg;
struct ieee80211com *ic = &sc->sc_ic;
struct ifnet *ifp = &sc->sc_if;
- int i;
+ int i, rv;
/* disable interrupts */
cmalo_intr_mask(sc, 0);
@@ -318,7 +318,7 @@
cmalo_fw_load_main(sc) != 0) {
/* free firmware */
cmalo_fw_free(sc);
- return;
+ goto fail_1;
}
sc->sc_flags |= MALO_FW_LOADED;
@@ -368,7 +368,11 @@
}
/* attach interface */
- 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);
@@ -386,6 +390,16 @@
/* device attached */
sc->sc_flags |= MALO_DEVICE_ATTACHED;
+
+ return;
+
+fail_2:
+ cv_destroy(&sc->sc_cv);
+ mutex_destroy(&sc->sc_mtx);
+ free(sc->sc_cmd, M_DEVBUF);
+ free(sc->sc_data, M_DEVBUF);
+fail_1:
+ cmalo_fw_free(sc);
}
static void
diff -r 40d2f504073e -r 241a22782651 sys/rump/net/lib/libvirtif/if_virt.c
--- a/sys/rump/net/lib/libvirtif/if_virt.c Mon Oct 23 09:23:48 2017 +0000
+++ b/sys/rump/net/lib/libvirtif/if_virt.c Mon Oct 23 09:24:34 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_virt.c,v 1.54 2016/12/15 09:28:07 ozaki-r Exp $ */
+/* $NetBSD: if_virt.c,v 1.55 2017/10/23 09:24:34 msaitoh Exp $ */
/*
* Copyright (c) 2008, 2013 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.54 2016/12/15 09:28:07 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.55 2017/10/23 09:24:34 msaitoh Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -121,7 +121,13 @@
ifp->if_mtu = ETHERMTU;
ifp->if_dlt = DLT_EN10MB;
- if_initialize(ifp);
+ error = if_initialize(ifp);
+ if (error != 0) {
+ aprint_error("%s: if_initialize failed(%d)\n", ifp->if_xname,
+ error);
+ goto fail_1;
+ }
+
if_register(ifp);
#ifndef RUMP_VIF_LINKSTR
@@ -132,11 +138,19 @@
*/
#define LINKSTRNUMLEN 16
sc->sc_linkstr = kmem_alloc(LINKSTRNUMLEN, KM_SLEEP);
+ if (sc->sc_linkstr == NULL) {
+ error = ENOMEM;
+ goto fail_2;
+ }
snprintf(sc->sc_linkstr, LINKSTRNUMLEN, "%d", sc->sc_num);
#undef LINKSTRNUMLEN
error = virtif_create(ifp);
if (error) {
+fail_2:
if_detach(ifp);
+ if (sc->sc_linkstr != NULL)
+ kmem_free(sc->sc_linkstr, LINKSTRNUMLEN);
+fail_1:
kmem_free(sc, sizeof(*sc));
ifp->if_softc = NULL;
}
Home |
Main Index |
Thread Index |
Old Index