Module Name:    src
Committed By:   riastradh
Date:           Sat Jun 12 12:11:59 UTC 2021

Modified Files:
        src/sys/kern: kern_drvctl.c

Log Message:
drvctl(4): Take the kernel lock around entry into autoconf(9).

Can make this finer-grained once the rest of autoconf(9) is in good
enough shape to support it.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/kern/kern_drvctl.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/kern/kern_drvctl.c
diff -u src/sys/kern/kern_drvctl.c:1.45 src/sys/kern/kern_drvctl.c:1.46
--- src/sys/kern/kern_drvctl.c:1.45	Thu Jun 11 02:28:01 2020
+++ src/sys/kern/kern_drvctl.c	Sat Jun 12 12:11:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_drvctl.c,v 1.45 2020/06/11 02:28:01 thorpej Exp $ */
+/* $NetBSD: kern_drvctl.c,v 1.46 2021/06/12 12:11:59 riastradh Exp $ */
 
 /*
  * Copyright (c) 2004
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.45 2020/06/11 02:28:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.46 2021/06/12 12:11:59 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -336,6 +336,7 @@ drvctl_ioctl(struct file *fp, u_long cmd
 	int *locs;
 	size_t locs_sz = 0; /* XXXgcc */
 
+	KERNEL_LOCK(1, NULL);
 	switch (cmd) {
 	case DRVSUSPENDDEV:
 	case DRVRESUMEDEV:
@@ -363,14 +364,16 @@ drvctl_ioctl(struct file *fp, u_long cmd
 			ifattr = 0;
 
 		if (d->numlocators) {
-			if (d->numlocators > MAXLOCATORS)
-				return EINVAL;
+			if (d->numlocators > MAXLOCATORS) {
+				res = EINVAL;
+				goto out;
+			}
 			locs_sz = d->numlocators * sizeof(int);
 			locs = kmem_alloc(locs_sz, KM_SLEEP);
 			res = copyin(d->locators, locs, locs_sz);
 			if (res) {
 				kmem_free(locs, locs_sz);
-				return res;
+				goto out;
 			}
 		} else
 			locs = NULL;
@@ -388,8 +391,10 @@ drvctl_ioctl(struct file *fp, u_long cmd
 		    fp->f_flag);
 		break;
 	default:
-		return EPASSTHROUGH;
+		res = EPASSTHROUGH;
+		break;
 	}
+out:	KERNEL_UNLOCK_ONE(NULL);
 	return res;
 }
 

Reply via email to