Module Name: src Committed By: msaitoh Date: Mon Oct 23 09:24:34 UTC 2017
Modified Files: src/sys/dev/ic: an.c src/sys/dev/pcmcia: if_malo_pcmcia.c src/sys/rump/net/lib/libvirtif: if_virt.c Log Message: If error occured in the attach function, free resources and return. To generate a diff of this commit: cvs rdiff -u -r1.65 -r1.66 src/sys/dev/ic/an.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/pcmcia/if_malo_pcmcia.c cvs rdiff -u -r1.54 -r1.55 src/sys/rump/net/lib/libvirtif/if_virt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/an.c diff -u src/sys/dev/ic/an.c:1.65 src/sys/dev/ic/an.c:1.66 --- src/sys/dev/ic/an.c:1.65 Tue May 23 02:19:14 2017 +++ src/sys/dev/ic/an.c Mon Oct 23 09:24:34 2017 @@ -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 <wp...@ctr.columbia.edu>. 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 @@ an_attach(struct an_softc *sc) { 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_attach(struct an_softc *sc) 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 @@ an_attach(struct an_softc *sc) /* * 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 @@ an_attach(struct an_softc *sc) 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 Index: src/sys/dev/pcmcia/if_malo_pcmcia.c diff -u src/sys/dev/pcmcia/if_malo_pcmcia.c:1.14 src/sys/dev/pcmcia/if_malo_pcmcia.c:1.15 --- src/sys/dev/pcmcia/if_malo_pcmcia.c:1.14 Sun Jun 25 12:25:02 2017 +++ src/sys/dev/pcmcia/if_malo_pcmcia.c Mon Oct 23 09:24:34 2017 @@ -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 @@ cmalo_attach(void *arg) 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_attach(void *arg) 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 @@ cmalo_attach(void *arg) } /* 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 @@ cmalo_attach(void *arg) /* 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 Index: src/sys/rump/net/lib/libvirtif/if_virt.c diff -u src/sys/rump/net/lib/libvirtif/if_virt.c:1.54 src/sys/rump/net/lib/libvirtif/if_virt.c:1.55 --- src/sys/rump/net/lib/libvirtif/if_virt.c:1.54 Thu Dec 15 09:28:07 2016 +++ src/sys/rump/net/lib/libvirtif/if_virt.c Mon Oct 23 09:24:34 2017 @@ -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 @@ virtif_clone(struct if_clone *ifc, int n 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 @@ virtif_clone(struct if_clone *ifc, int n */ #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; }