summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorryo <ryo@NetBSD.org>2023-01-14 13:17:20 +0000
committerryo <ryo@NetBSD.org>2023-01-14 13:17:20 +0000
commit469febff2afec0c7b2e1ad320cc58eba273dca45 (patch)
tree66ea9e90d7f2bed50e5c49b8276e798c79b1dd39 /sys/dev
parente53cca4654aeca781ca49f1349402cacf1e4b053 (diff)
- avoid panic when failing during attach or detach with modload/drvctl.
- free workqueue resources when detaching. - remove debug message.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_aq.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/sys/dev/pci/if_aq.c b/sys/dev/pci/if_aq.c
index effdc7ab8ef..86df7761aa2 100644
--- a/sys/dev/pci/if_aq.c
+++ b/sys/dev/pci/if_aq.c
@@ -1,4 +1,4 @@
-/* $NetBSD: if_aq.c,v 1.40 2023/01/14 13:16:27 ryo Exp $ */
+/* $NetBSD: if_aq.c,v 1.41 2023/01/14 13:17:20 ryo Exp $ */
/**
* aQuantia Corporation Network Driver
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.40 2023/01/14 13:16:27 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.41 2023/01/14 13:17:20 ryo Exp $");
#ifdef _KERNEL_OPT
#include "opt_if_aq.h"
@@ -931,7 +931,8 @@ struct aq_firmware_ops {
#define AQ_EVCNT_ATTACH_MISC(sc, name, desc) \
AQ_EVCNT_ATTACH(sc, name, desc, EVCNT_TYPE_MISC)
#define AQ_EVCNT_DETACH(sc, name) \
- evcnt_detach(&(sc)->sc_evcount_##name##_ev)
+ if ((sc)->sc_evcount_##name##_name[0] != '\0') \
+ evcnt_detach(&(sc)->sc_evcount_##name##_ev)
#define AQ_EVCNT_ADD(sc, name, val) \
((sc)->sc_evcount_##name##_ev.ev_count += (val))
#endif /* AQ_EVENT_COUNTERS */
@@ -1587,6 +1588,9 @@ aq_detach(device_t self, int flags __unused)
struct ifnet * const ifp = &sc->sc_ethercom.ec_if;
int i;
+ if (sc->sc_dev == NULL)
+ return 0;
+
if (sc->sc_iosize != 0) {
if (ifp->if_softc != NULL) {
IFNET_LOCK(ifp);
@@ -1601,12 +1605,19 @@ aq_detach(device_t self, int flags __unused)
}
}
if (sc->sc_nintrs > 0) {
+ callout_stop(&sc->sc_tick_ch);
+
pci_intr_release(sc->sc_pc, sc->sc_intrs,
sc->sc_nintrs);
sc->sc_intrs = NULL;
sc->sc_nintrs = 0;
}
+ if (sc->sc_reset_wq != NULL) {
+ workqueue_destroy(sc->sc_reset_wq);
+ sc->sc_reset_wq = NULL;
+ }
+
aq_txrx_rings_free(sc);
if (ifp->if_softc != NULL) {
@@ -1614,7 +1625,6 @@ aq_detach(device_t self, int flags __unused)
if_detach(ifp);
}
- aprint_debug_dev(sc->sc_dev, "%s: bus_space_unmap\n", __func__);
bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
sc->sc_iosize = 0;
}
@@ -1647,10 +1657,14 @@ aq_detach(device_t self, int flags __unused)
AQ_EVCNT_DETACH(sc, cprc);
#endif
- ifmedia_fini(&sc->sc_media);
+ if (sc->sc_ethercom.ec_ifmedia != NULL) {
+ ifmedia_fini(&sc->sc_media);
+ sc->sc_ethercom.ec_ifmedia = NULL;
+ }
mutex_destroy(&sc->sc_mpi_mutex);
mutex_destroy(&sc->sc_mutex);
+ sc->sc_dev = NULL;
return 0;
}