summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2023-04-21 18:29:18 +0000
committerriastradh <riastradh@NetBSD.org>2023-04-21 18:29:18 +0000
commitf96fb0a7f03ec4550f39aaf59b242b70e6e09bfd (patch)
treecd5852c6d626961cc42ba5935da07213830103e1 /sys/dev
parent7db941f2bf4b1d6b06fdc42468810ef0817f098c (diff)
dk(4): Don't touch dkwedges or ndkwedges outside dkwedges_lock.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/dkwedge/dk.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/sys/dev/dkwedge/dk.c b/sys/dev/dkwedge/dk.c
index 354d695abde..c1338c247d8 100644
--- a/sys/dev/dkwedge/dk.c
+++ b/sys/dev/dkwedge/dk.c
@@ -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_int *unitp)
}
}
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 vnode *vp, daddr_t blkno,
static struct dkwedge_softc *
dkwedge_lookup(dev_t dev)
{
- int unit = minor(dev);
-
- if (unit >= ndkwedges)
- return NULL;
+ const int unit = minor(dev);
+ struct dkwedge_softc *sc;
- KASSERT(dkwedges != NULL);
+ rw_enter(&dkwedges_lock, RW_READER);
+ if (unit < 0 || unit >= ndkwedges)
+ sc = NULL;
+ else
+ sc = dkwedges[unit];
+ rw_exit(&dkwedges_lock);
- return dkwedges[unit];
+ return sc;
}
static int