diff --git a/sys/net/if_tuntap.c b/sys/net/if_tuntap.c index 8094c4b55be..0cfa1643309 100644 --- a/sys/net/if_tuntap.c +++ b/sys/net/if_tuntap.c @@ -538,9 +538,6 @@ tun_destroy(struct tuntap_softc *tp) TUN_UNLOCK(tp); CURVNET_SET(TUN2IFP(tp)->if_vnet); - sx_xlock(&tun_ioctl_sx); - TUN2IFP(tp)->if_softc = NULL; - sx_xunlock(&tun_ioctl_sx); destroy_dev(tp->tun_dev); seldrain(&tp->tun_rsel); @@ -552,6 +549,9 @@ tun_destroy(struct tuntap_softc *tp) bpfdetach(TUN2IFP(tp)); if_detach(TUN2IFP(tp)); } + sx_xlock(&tun_ioctl_sx); + TUN2IFP(tp)->if_softc = NULL; + sx_xunlock(&tun_ioctl_sx); free_unr(tp->tun_drv->unrhdr, TUN2IFP(tp)->if_dunit); if_free(TUN2IFP(tp)); mtx_destroy(&tp->tun_mtx);