From 31069fdbdae1027a6f1af7d56d418de4428ac6d9 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 10 Apr 2026 11:27:51 +0300 Subject: [PATCH] kevent: do not check knote lists being empty before removing a knote If a knote belongs to the list, there is no reason to check for the list emptiness. On the other hand, if the knote does not belong to the list, then checking for emptiness is not enough since there might be a different knote there. Reviewed bu: kevans, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D56341 --- sys/kern/kern_event.c | 3 +-- sys/kern/vfs_aio.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 01731ca46b6..8c7a0949f02 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -2953,8 +2953,7 @@ knote_drop_detached(struct knote *kn, struct thread *td) else list = &kq->kq_knhash[KN_HASH(kn->kn_id, kq->kq_knhashmask)]; - if (!SLIST_EMPTY(list)) - SLIST_REMOVE(list, kn, knote, kn_link); + SLIST_REMOVE(list, kn, knote, kn_link); if (kn->kn_status & KN_QUEUED) knote_dequeue(kn); KQ_UNLOCK_FLUX(kq); diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 2a790237d30..da0e36fc1ec 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -2668,8 +2668,7 @@ filt_aiodetach(struct knote *kn) knl = &kn->kn_ptr.p_aio->klist; knl->kl_lock(knl->kl_lockarg); - if (!knlist_empty(knl)) - knlist_remove(knl, kn, 1); + knlist_remove(knl, kn, 1); knl->kl_unlock(knl->kl_lockarg); } @@ -2718,8 +2717,7 @@ filt_liodetach(struct knote *kn) knl = &kn->kn_ptr.p_lio->klist; knl->kl_lock(knl->kl_lockarg); - if (!knlist_empty(knl)) - knlist_remove(knl, kn, 1); + knlist_remove(knl, kn, 1); knl->kl_unlock(knl->kl_lockarg); }