Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/dkwedge Update sc->sc_parent->dk_rawvp while the loc...



details:   https://anonhg.NetBSD.org/src/rev/a4bda6d33c69
branches:  trunk
changeset: 745312:a4bda6d33c69
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Fri Feb 28 06:01:23 2020 +0000

description:
Update sc->sc_parent->dk_rawvp while the lock named dk_rawlock held
to prevent a race condition

Fixes PR kern/55026

OKed by mlelstv@, thanks

diffstat:

 sys/dev/dkwedge/dk.c |  22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diffs (50 lines):

diff -r b9bb6d9854b8 -r a4bda6d33c69 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Fri Feb 28 05:13:19 2020 +0000
+++ b/sys/dev/dkwedge/dk.c      Fri Feb 28 06:01:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.97 2018/05/12 10:33:06 mlelstv Exp $  */
+/*     $NetBSD: dk.c,v 1.98 2020/02/28 06:01:23 yamaguchi Exp $        */
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.97 2018/05/12 10:33:06 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.98 2020/02/28 06:01:23 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1152,21 +1152,23 @@
 static int
 dklastclose(struct dkwedge_softc *sc)
 {
-       int error = 0, doclose;
+       struct vnode *vp;
+       int error = 0;
 
-       doclose = 0;
+       vp = NULL;
        if (sc->sc_parent->dk_rawopens > 0) {
-               if (--sc->sc_parent->dk_rawopens == 0)
-                       doclose = 1;
+               if (--sc->sc_parent->dk_rawopens == 0) {
+                       KASSERT(sc->sc_parent->dk_rawvp != NULL);
+                       vp = sc->sc_parent->dk_rawvp;
+                       sc->sc_parent->dk_rawvp = NULL;
+               }
        }
 
        mutex_exit(&sc->sc_parent->dk_rawlock);
        mutex_exit(&sc->sc_dk.dk_openlock);
 
-       if (doclose) {
-               KASSERT(sc->sc_parent->dk_rawvp != NULL);
-               dk_close_parent(sc->sc_parent->dk_rawvp, FREAD | FWRITE);
-               sc->sc_parent->dk_rawvp = NULL;
+       if (vp) {
+               dk_close_parent(vp, FREAD | FWRITE);
        }
 
        return error;



Home | Main Index | Thread Index | Old Index