Module Name:    src
Committed By:   riastradh
Date:           Thu Apr 13 08:30:41 UTC 2023

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

Log Message:
dk(4): Explain why dk_rawopens can't overflow and assert it.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.124 src/sys/dev/dkwedge/dk.c:1.125
--- src/sys/dev/dkwedge/dk.c:1.124	Tue Sep 27 17:04:52 2022
+++ src/sys/dev/dkwedge/dk.c	Thu Apr 13 08:30:40 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.124 2022/09/27 17:04:52 mlelstv Exp $	*/
+/*	$NetBSD: dk.c,v 1.125 2023/04/13 08:30:40 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.124 2022/09/27 17:04:52 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.125 2023/04/13 08:30:40 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1200,7 +1200,13 @@ dkfirstopen(struct dkwedge_softc *sc, in
 	} else {
 		/*
 		 * Retrieve mode from an already opened wedge.
+		 *
+		 * At this point, dk_rawopens is bounded by the number
+		 * of dkwedge devices in the system, which is limited
+		 * by autoconf device numbering to INT_MAX.  Since
+		 * dk_rawopens is unsigned, this can't overflow.
 		 */
+		KASSERT(sc->sc_parent->dk_rawopens < UINT_MAX);
 		mode = 0;
 		LIST_FOREACH(nsc, &sc->sc_parent->dk_wedges, sc_plink) {
 			if (nsc == sc || nsc->sc_dk.dk_openmask == 0)

Reply via email to