Source-Changes-HG archive

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

[src/trunk]: src/sys/kern fcntl(2), flock(2): Assert FHASLOCK is clear if no ...



details:   https://anonhg.NetBSD.org/src/rev/a86d9bb83f9e
branches:  trunk
changeset: 374425:a86d9bb83f9e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Apr 22 14:23:59 2023 +0000

description:
fcntl(2), flock(2): Assert FHASLOCK is clear if no fo_advlock.

diffstat:

 sys/kern/kern_descrip.c |  8 +++++---
 sys/kern/sys_descrip.c  |  5 +++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r 4f6689d93c99 -r a86d9bb83f9e sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Sat Apr 22 14:23:50 2023 +0000
+++ b/sys/kern/kern_descrip.c   Sat Apr 22 14:23:59 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.256 2023/04/22 13:52:46 riastradh Exp $     */
+/*     $NetBSD: kern_descrip.c,v 1.257 2023/04/22 14:23:59 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.256 2023/04/22 13:52:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.257 2023/04/22 14:23:59 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -852,7 +852,9 @@ closef(file_t *fp)
        mutex_exit(&fp->f_lock);
 
        /* We held the last reference - release locks, close and free. */
-       if ((fp->f_flag & FHASLOCK) && fp->f_ops->fo_advlock != NULL) {
+       if (fp->f_ops->fo_advlock == NULL) {
+               KASSERT((fp->f_flag & FHASLOCK) == 0);
+       } else if (fp->f_flag & FHASLOCK) {
                lf.l_whence = SEEK_SET;
                lf.l_start = 0;
                lf.l_len = 0;
diff -r 4f6689d93c99 -r a86d9bb83f9e sys/kern/sys_descrip.c
--- a/sys/kern/sys_descrip.c    Sat Apr 22 14:23:50 2023 +0000
+++ b/sys/kern/sys_descrip.c    Sat Apr 22 14:23:59 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_descrip.c,v 1.45 2023/04/22 14:23:50 riastradh Exp $       */
+/*     $NetBSD: sys_descrip.c,v 1.46 2023/04/22 14:23:59 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.45 2023/04/22 14:23:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.46 2023/04/22 14:23:59 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -620,6 +620,7 @@ sys_flock(struct lwp *l, const struct sy
                goto out;
        }
        if ((fo_advlock = fp->f_ops->fo_advlock) == NULL) {
+               KASSERT((atomic_load_relaxed(&fp->f_flag) & FHASLOCK) == 0);
                error = EOPNOTSUPP;
                goto out;
        }



Home | Main Index | Thread Index | Old Index