Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/dkwedge dk(4): Strengthen dkclose preconditions.



details:   https://anonhg.NetBSD.org/src/rev/d30cd7581ad0
branches:  trunk
changeset: 375936:d30cd7581ad0
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon May 22 14:59:50 2023 +0000

description:
dk(4): Strengthen dkclose preconditions.

Like dkopen, except it is possible for this to be called after the
wedge has transitioned to dying.

XXX sc_state read here races with sc_state write in dkwedge_detach.
Could change this to atomic_load/store.

diffstat:

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

diffs (38 lines):

diff -r 94f50a8f41d2 -r d30cd7581ad0 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Mon May 22 14:59:42 2023 +0000
+++ b/sys/dev/dkwedge/dk.c      Mon May 22 14:59:50 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 riastradh Exp $       */
+/*     $NetBSD: dk.c,v 1.168 2023/05/22 14:59:50 riastradh 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.167 2023/05/22 14:59:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.168 2023/05/22 14:59:50 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1404,11 +1404,16 @@ dkclose(dev_t dev, int flags, int fmt, s
 {
        struct dkwedge_softc *sc = dkwedge_lookup(dev);
 
+       /*
+        * dkclose can be called even if dkopen didn't succeed, so we
+        * have to handle the same possibility that the wedge may not
+        * exist.
+        */
        if (sc == NULL)
                return ENXIO;
-       if (sc->sc_state != DKW_STATE_RUNNING &&
-           sc->sc_state != DKW_STATE_DYING)
-               return ENXIO;
+       KASSERT(sc->sc_dev != NULL);
+       KASSERT(sc->sc_state != DKW_STATE_LARVAL);
+       KASSERT(sc->sc_state != DKW_STATE_DEAD);
 
        mutex_enter(&sc->sc_dk.dk_openlock);
        mutex_enter(&sc->sc_parent->dk_rawlock);



Home | Main Index | Thread Index | Old Index