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 dkopen preconditions.



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

description:
dk(4): Strengthen dkopen preconditions.

This cannot be called before dkwedge_attach for the same unit
returns, so sc->sc_dev is guaranteed to be set to a nonnull device_t
and the state is guaranteed not to be larval.

And this cannot be called concurrently with dkwedge_detach, or after
dkwedge_detach does vdevgone until another wedge with the same number
is attached (which can't happen until dkwedge_detach completes), so
the state is guaranteed not to be dying or dead.

Hence sc->sc_dev != NULL and sc->sc_state == DKW_STATE_RUNNING.

diffstat:

 sys/dev/dkwedge/dk.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (29 lines):

diff -r 80233a23f7b0 -r 94f50a8f41d2 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Mon May 22 14:59:34 2023 +0000
+++ b/sys/dev/dkwedge/dk.c      Mon May 22 14:59:42 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.166 2023/05/22 14:59:34 riastradh Exp $       */
+/*     $NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 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.166 2023/05/22 14:59:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1277,8 +1277,8 @@ dkopen(dev_t dev, int flags, int fmt, st
 
        if (sc == NULL)
                return ENXIO;
-       if (sc->sc_state != DKW_STATE_RUNNING)
-               return ENXIO;
+       KASSERT(sc->sc_dev != NULL);
+       KASSERT(sc->sc_state == DKW_STATE_RUNNING);
 
        /*
         * We go through a complicated little dance to only open the parent



Home | Main Index | Thread Index | Old Index