The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=fd9e09cb2ab07993e8dc783c802f273329e70bb8
commit fd9e09cb2ab07993e8dc783c802f273329e70bb8 Author: Konstantin Belousov <k...@freebsd.org> AuthorDate: 2025-09-07 10:59:45 +0000 Commit: Konstantin Belousov <k...@freebsd.org> CommitDate: 2025-09-08 03:01:05 +0000 kern: replace several EBADF with EINVAL EBADF semantic is that the passed fd is invalid, not that it is of wrong type. Using EBADF in these places in kern_event.c and sys_procdesc.c give bad examples to copy from. Note that places in kern_event.c that checks KQ_CLOSING and return EBADF are kept, since KQ_CLOSING is the transient state before the fd is finally closed and become eligible for EBADF. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D52410 --- sys/kern/kern_event.c | 2 +- sys/kern/sys_procdesc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 501adc151d44..b5360f3a1055 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1903,7 +1903,7 @@ kqueue_acquire(struct file *fp, struct kqueue **kqp) kq = fp->f_data; if (fp->f_type != DTYPE_KQUEUE || kq == NULL) - return (EBADF); + return (EINVAL); *kqp = kq; KQ_LOCK(kq); if ((kq->kq_state & KQ_CLOSING) == KQ_CLOSING) { diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c index 11bd1b6f30e1..54b03fc82c90 100644 --- a/sys/kern/sys_procdesc.c +++ b/sys/kern/sys_procdesc.c @@ -129,7 +129,7 @@ procdesc_find(struct thread *td, int fd, const cap_rights_t *rightsp, if (error) return (error); if (fp->f_type != DTYPE_PROCDESC) { - error = EBADF; + error = EINVAL; goto out; } pd = fp->f_data; @@ -175,7 +175,7 @@ kern_pdgetpid(struct thread *td, int fd, const cap_rights_t *rightsp, if (error) return (error); if (fp->f_type != DTYPE_PROCDESC) { - error = EBADF; + error = EINVAL; goto out; } *pidp = procdesc_pid(fp);