Index: sys/kern/kern_event.c =================================================================== --- sys/kern/kern_event.c +++ sys/kern/kern_event.c @@ -1359,8 +1359,6 @@ if (kev->flags & EV_DELETE) { kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); goto done; } @@ -1684,8 +1682,6 @@ * We don't need to lock the list since we've * marked it as in flux. */ - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); continue; @@ -1699,8 +1695,6 @@ * marked the knote as being in flux. */ *kevp = kn->kn_kevent; - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); kn = NULL; @@ -1902,8 +1896,6 @@ } kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); } @@ -1919,8 +1911,6 @@ } kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); } @@ -2323,7 +2313,6 @@ } knlist_remove_kq(knl, kn, 1, 1); if (killkn) { - kn->kn_status |= KN_DETACHED; kn_enter_flux(kn); KQ_UNLOCK(kq); knote_drop(kn, td); @@ -2392,10 +2381,8 @@ } kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); - knote_drop(kn, td); influx = 1; + knote_drop(kn, td); KQ_LOCK(kq); } KQ_UNLOCK_FLUX(kq); @@ -2423,11 +2410,6 @@ return (0); } -/* - * knote must already have been detached using the f_detach method. - * no lock need to be held, it is assumed that the influx state is set - * to prevent other removal. - */ static void knote_drop(struct knote *kn, struct thread *td) { @@ -2437,6 +2419,10 @@ kq = kn->kn_kq; KQ_NOTOWNED(kq); + + if ((kn->kn_status & KN_DETACHED) == 0) + kn->kn_fop->f_detach(kn); + KQ_LOCK(kq); KASSERT(kn->kn_influx == 1, ("knote_drop called on %p with influx %d", kn, kn->kn_influx));