Module Name:    src
Committed By:   riastradh
Date:           Mon May 22 14:59:42 UTC 2023

Modified Files:
        src/sys/dev/dkwedge: dk.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/dkwedge/dk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.166 src/sys/dev/dkwedge/dk.c:1.167
--- src/sys/dev/dkwedge/dk.c:1.166	Mon May 22 14:59:34 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:42 2023
@@ -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

Reply via email to