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): Don't touch dkwedges or ndkwedges out...



details:   https://anonhg.NetBSD.org/src/rev/ed90c34c5dae
branches:  trunk
changeset: 374382:ed90c34c5dae
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Apr 21 18:29:18 2023 +0000

description:
dk(4): Don't touch dkwedges or ndkwedges outside dkwedges_lock.

diffstat:

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

diffs (51 lines):

diff -r 287c26dcfb13 -r ed90c34c5dae sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Fri Apr 21 18:26:35 2023 +0000
+++ b/sys/dev/dkwedge/dk.c      Fri Apr 21 18:29:18 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.136 2023/04/21 18:26:35 riastradh Exp $       */
+/*     $NetBSD: dk.c,v 1.137 2023/04/21 18:29:18 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.136 2023/04/21 18:26:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.137 2023/04/21 18:29:18 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -624,7 +624,7 @@ dkwedge_find(struct dkwedge_info *dkw, u
                }
        }
        rw_exit(&dkwedges_lock);
-       if (unit == ndkwedges)
+       if (sc == NULL)
                return NULL;
 
        if (unitp != NULL)
@@ -1159,14 +1159,17 @@ dkwedge_read(struct disk *pdk, struct vn
 static struct dkwedge_softc *
 dkwedge_lookup(dev_t dev)
 {
-       int unit = minor(dev);
+       const int unit = minor(dev);
+       struct dkwedge_softc *sc;
 
-       if (unit >= ndkwedges)
-               return NULL;
+       rw_enter(&dkwedges_lock, RW_READER);
+       if (unit < 0 || unit >= ndkwedges)
+               sc = NULL;
+       else
+               sc = dkwedges[unit];
+       rw_exit(&dkwedges_lock);
 
-       KASSERT(dkwedges != NULL);
-
-       return dkwedges[unit];
+       return sc;
 }
 
 static int



Home | Main Index | Thread Index | Old Index