The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a507a40f3b587bde7ab391f8f1400a25f33e65c1

commit a507a40f3b587bde7ab391f8f1400a25f33e65c1
Author:     Mark Johnston <ma...@freebsd.org>
AuthorDate: 2021-08-25 20:20:07 +0000
Commit:     Mark Johnston <ma...@freebsd.org>
CommitDate: 2021-08-25 20:20:07 +0000

    fsetown: Simplify error handling
    
    No functional change intended.
    
    Suggested by:   kib
    Reviewed by:    kib
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D31671
---
 sys/kern/kern_descrip.c | 106 ++++++++++++++++++++----------------------------
 1 file changed, 45 insertions(+), 61 deletions(-)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index e6a6a36801e4..f78e999ab3b5 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1153,88 +1153,72 @@ fsetown(pid_t pgid, struct sigio **sigiop)
                return (0);
        }
 
-       ret = 0;
-       osigio = NULL;
-
        sigio = malloc(sizeof(struct sigio), M_SIGIO, M_WAITOK);
        sigio->sio_pgid = pgid;
        sigio->sio_ucred = crhold(curthread->td_ucred);
        sigio->sio_myref = sigiop;
 
+       osigio = NULL;
+       ret = 0;
        if (pgid > 0) {
                ret = pget(pgid, PGET_NOTWEXIT | PGET_NOTID | PGET_HOLD, &proc);
                SIGIO_LOCK();
-               if (ret != 0)
-                       goto fail;
-
-               osigio = funsetown_locked(*sigiop);
-
-               PROC_LOCK(proc);
-               _PRELE(proc);
-               if ((proc->p_flag & P_WEXIT) != 0) {
-                       PROC_UNLOCK(proc);
-                       ret = ESRCH;
-                       goto fail;
-               }
-
-               /*
-                * Policy - Don't allow a process to FSETOWN a process
-                * in another session.
-                *
-                * Remove this test to allow maximum flexibility or
-                * restrict FSETOWN to the current process or process
-                * group for maximum safety.
-                */
-               if (proc->p_session != curthread->td_proc->p_session) {
+               if (ret == 0) {
+                       osigio = funsetown_locked(*sigiop);
+
+                       PROC_LOCK(proc);
+                       _PRELE(proc);
+                       if ((proc->p_flag & P_WEXIT) != 0) {
+                               ret = ESRCH;
+                       } else if (proc->p_session !=
+                           curthread->td_proc->p_session) {
+                               /*
+                                * Policy - Don't allow a process to FSETOWN a
+                                * process in another session.
+                                *
+                                * Remove this test to allow maximum flexibility
+                                * or restrict FSETOWN to the current process or
+                                * process group for maximum safety.
+                                */
+                               ret = EPERM;
+                       } else {
+                               sigio->sio_proc = proc;
+                               SLIST_INSERT_HEAD(&proc->p_sigiolst, sigio,
+                                   sio_pgsigio);
+                       }
                        PROC_UNLOCK(proc);
-                       ret = EPERM;
-                       goto fail;
                }
-
-               sigio->sio_proc = proc;
-               SLIST_INSERT_HEAD(&proc->p_sigiolst, sigio, sio_pgsigio);
-               PROC_UNLOCK(proc);
        } else /* if (pgid < 0) */ {
                sx_slock(&proctree_lock);
                SIGIO_LOCK();
                pgrp = pgfind(-pgid);
                if (pgrp == NULL) {
-                       sx_sunlock(&proctree_lock);
                        ret = ESRCH;
-                       goto fail;
-               }
-
-               osigio = funsetown_locked(*sigiop);
-
-               /*
-                * Policy - Don't allow a process to FSETOWN a process
-                * in another session.
-                *
-                * Remove this test to allow maximum flexibility or
-                * restrict FSETOWN to the current process or process
-                * group for maximum safety.
-                */
-               if (pgrp->pg_session != curthread->td_proc->p_session) {
-                       sx_sunlock(&proctree_lock);
+               } else {
+                       osigio = funsetown_locked(*sigiop);
+
+                       if (pgrp->pg_session != curthread->td_proc->p_session) {
+                               /*
+                                * Policy - Don't allow a process to FSETOWN a
+                                * process in another session.
+                                *
+                                * Remove this test to allow maximum flexibility
+                                * or restrict FSETOWN to the current process or
+                                * process group for maximum safety.
+                                */
+                               ret = EPERM;
+                       } else {
+                               sigio->sio_pgrp = pgrp;
+                               SLIST_INSERT_HEAD(&pgrp->pg_sigiolst, sigio,
+                                   sio_pgsigio);
+                       }
                        PGRP_UNLOCK(pgrp);
-                       ret = EPERM;
-                       goto fail;
                }
-
-               sigio->sio_pgrp = pgrp;
-               SLIST_INSERT_HEAD(&pgrp->pg_sigiolst, sigio, sio_pgsigio);
-               PGRP_UNLOCK(pgrp);
                sx_sunlock(&proctree_lock);
        }
-       *sigiop = sigio;
-       SIGIO_UNLOCK();
-       if (osigio != NULL)
-               sigiofree(osigio);
-       return (0);
-
-fail:
+       if (ret == 0)
+               *sigiop = sigio;
        SIGIO_UNLOCK();
-       sigiofree(sigio);
        if (osigio != NULL)
                sigiofree(osigio);
        return (ret);
_______________________________________________
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"

Reply via email to