diff options
author | 2020-12-11 14:17:35 +0000 | |
---|---|---|
committer | 2020-12-11 14:17:35 +0000 | |
commit | c47d41f6a77696c25423f589e56a0b5954deb245 (patch) | |
tree | b957ec2e3df592b7325e434da9325e3c0d2d2cf1 /sys/kern | |
parent | Warning: arithmetic on a pointer to void is a GNU extension; merged (diff) | |
download | wireguard-openbsd-c47d41f6a77696c25423f589e56a0b5954deb245.tar.xz wireguard-openbsd-c47d41f6a77696c25423f589e56a0b5954deb245.zip |
Simplify filt_pipedetach()
By storing pipe pointer in kn_hook, filt_pipedetach() does not need
extra logic to find the correct pipe instance. This also lets the kernel
clear the knote lists fully.
OK anton@, mpi@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/sys_pipe.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 04ec907d21f..be8e0a1f867 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_pipe.c,v 1.123 2020/06/29 18:23:18 anton Exp $ */ +/* $OpenBSD: sys_pipe.c,v 1.124 2020/12/11 14:17:35 visa Exp $ */ /* * Copyright (c) 1996 John S. Dyson @@ -886,6 +886,7 @@ pipe_kqfilter(struct file *fp, struct knote *kn) switch (kn->kn_filter) { case EVFILT_READ: kn->kn_fop = &pipe_rfiltops; + kn->kn_hook = rpipe; klist_insert(&rpipe->pipe_sel.si_note, kn); break; case EVFILT_WRITE: @@ -895,6 +896,7 @@ pipe_kqfilter(struct file *fp, struct knote *kn) break; } kn->kn_fop = &pipe_wfiltops; + kn->kn_hook = wpipe; klist_insert(&wpipe->pipe_sel.si_note, kn); break; default: @@ -909,24 +911,11 @@ pipe_kqfilter(struct file *fp, struct knote *kn) void filt_pipedetach(struct knote *kn) { - struct pipe *rpipe = kn->kn_fp->f_data, *wpipe; - struct rwlock *lock = rpipe->pipe_lock; - - rw_enter_write(lock); - wpipe = pipe_peer(rpipe); - - switch (kn->kn_filter) { - case EVFILT_READ: - klist_remove(&rpipe->pipe_sel.si_note, kn); - break; - case EVFILT_WRITE: - if (wpipe == NULL) - break; - klist_remove(&wpipe->pipe_sel.si_note, kn); - break; - } + struct pipe *cpipe = kn->kn_hook; - rw_exit_write(lock); + rw_enter_write(cpipe->pipe_lock); + klist_remove(&cpipe->pipe_sel.si_note, kn); + rw_exit_write(cpipe->pipe_lock); } int |