Clean up the list of chips upon detach and mark us uninitialized.
authorpatrick <patrick@openbsd.org>
Tue, 31 Aug 2021 21:46:00 +0000 (21:46 +0000)
committerpatrick <patrick@openbsd.org>
Tue, 31 Aug 2021 21:46:00 +0000 (21:46 +0000)
sys/dev/ic/bwfm.c

index 0c52220..7428aae 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: bwfm.c,v 1.88 2021/08/19 14:13:39 patrick Exp $ */
+/* $OpenBSD: bwfm.c,v 1.89 2021/08/31 21:46:00 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
  * Copyright (c) 2016,2017 Patrick Wildt <patrick@blueri.se>
@@ -73,7 +73,7 @@ int    bwfm_media_change(struct ifnet *);
 void    bwfm_process_clm_blob(struct bwfm_softc *);
 
 int     bwfm_chip_attach(struct bwfm_softc *);
-int     bwfm_chip_detach(struct bwfm_softc *, int);
+void    bwfm_chip_detach(struct bwfm_softc *);
 struct bwfm_core *bwfm_chip_get_core_idx(struct bwfm_softc *, int, int);
 struct bwfm_core *bwfm_chip_get_core(struct bwfm_softc *, int);
 struct bwfm_core *bwfm_chip_get_pmu(struct bwfm_softc *);
@@ -342,10 +342,14 @@ bwfm_detach(struct bwfm_softc *sc, int flags)
 {
        struct ieee80211com *ic = &sc->sc_ic;
        struct ifnet *ifp = &ic->ic_if;
+
        task_del(sc->sc_taskq, &sc->sc_task);
        taskq_destroy(sc->sc_taskq);
        ieee80211_ifdetach(ifp);
        if_detach(ifp);
+
+       bwfm_chip_detach(sc);
+       sc->sc_initialized = 0;
        return 0;
 }
 
@@ -932,6 +936,17 @@ bwfm_chip_attach(struct bwfm_softc *sc)
        return 0;
 }
 
+void
+bwfm_chip_detach(struct bwfm_softc *sc)
+{
+       struct bwfm_core *core, *tmp;
+
+       LIST_FOREACH_SAFE(core, &sc->sc_chip.ch_list, co_link, tmp) {
+               LIST_REMOVE(core, co_link);
+               free(core, M_DEVBUF, sizeof(*core));
+       }
+}
+
 struct bwfm_core *
 bwfm_chip_get_core_idx(struct bwfm_softc *sc, int id, int idx)
 {