Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Tweak filt_piperead() and filt_pipewrite() so that:



details:   https://anonhg.NetBSD.org/src/rev/f68e0989277a
branches:  trunk
changeset: 1023828:f68e0989277a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Sep 27 00:51:10 2021 +0000

description:
Tweak filt_piperead() and filt_pipewrite() so that:
- There is only a single return from the function (and thus a single
  place where the pipe lock must be released).
- kn->kn_data is referenced only inside the lock perimeter.

diffstat:

 sys/kern/sys_pipe.c |  26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diffs (78 lines):

diff -r a63b21f15434 -r f68e0989277a sys/kern/sys_pipe.c
--- a/sys/kern/sys_pipe.c       Mon Sep 27 00:40:49 2021 +0000
+++ b/sys/kern/sys_pipe.c       Mon Sep 27 00:51:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_pipe.c,v 1.155 2021/09/26 15:48:54 thorpej Exp $   */
+/*     $NetBSD: sys_pipe.c,v 1.156 2021/09/27 00:51:10 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.155 2021/09/26 15:48:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.156 2021/09/27 00:51:10 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1045,6 +1045,7 @@
 {
        struct pipe *rpipe = ((file_t *)kn->kn_obj)->f_pipe;
        struct pipe *wpipe;
+       int rv;
 
        if ((hint & NOTE_SUBMIT) == 0) {
                mutex_enter(rpipe->pipe_lock);
@@ -1055,16 +1056,15 @@
        if ((rpipe->pipe_state & PIPE_EOF) ||
            (wpipe == NULL) || (wpipe->pipe_state & PIPE_EOF)) {
                kn->kn_flags |= EV_EOF;
-               if ((hint & NOTE_SUBMIT) == 0) {
-                       mutex_exit(rpipe->pipe_lock);
-               }
-               return (1);
+               rv = 1;
+       } else {
+               rv = kn->kn_data > 0;
        }
 
        if ((hint & NOTE_SUBMIT) == 0) {
                mutex_exit(rpipe->pipe_lock);
        }
-       return (kn->kn_data > 0);
+       return rv;
 }
 
 static int
@@ -1072,6 +1072,7 @@
 {
        struct pipe *rpipe = ((file_t *)kn->kn_obj)->f_pipe;
        struct pipe *wpipe;
+       int rv;
 
        if ((hint & NOTE_SUBMIT) == 0) {
                mutex_enter(rpipe->pipe_lock);
@@ -1081,17 +1082,16 @@
        if ((wpipe == NULL) || (wpipe->pipe_state & PIPE_EOF)) {
                kn->kn_data = 0;
                kn->kn_flags |= EV_EOF;
-               if ((hint & NOTE_SUBMIT) == 0) {
-                       mutex_exit(rpipe->pipe_lock);
-               }
-               return (1);
+               rv = 1;
+       } else {
+               kn->kn_data = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt;
+               rv = kn->kn_data >= PIPE_BUF;
        }
-       kn->kn_data = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt;
 
        if ((hint & NOTE_SUBMIT) == 0) {
                mutex_exit(rpipe->pipe_lock);
        }
-       return (kn->kn_data >= PIPE_BUF);
+       return rv;
 }
 
 static const struct filterops pipe_rfiltops = {



Home | Main Index | Thread Index | Old Index