Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern drvctl(4): Take the kernel lock around entry into a...



details:   https://anonhg.NetBSD.org/src/rev/b2c0162f1b27
branches:  trunk
changeset: 1021641:b2c0162f1b27
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Jun 12 12:11:59 2021 +0000

description:
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.

diffstat:

 sys/kern/kern_drvctl.c |  17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diffs (58 lines):

diff -r d856a74e2334 -r b2c0162f1b27 sys/kern/kern_drvctl.c
--- a/sys/kern/kern_drvctl.c    Sat Jun 12 12:11:49 2021 +0000
+++ b/sys/kern/kern_drvctl.c    Sat Jun 12 12:11:59 2021 +0000
@@ -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 @@
        int *locs;
        size_t locs_sz = 0; /* XXXgcc */
 
+       KERNEL_LOCK(1, NULL);
        switch (cmd) {
        case DRVSUSPENDDEV:
        case DRVRESUMEDEV:
@@ -363,14 +364,16 @@
                        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 @@
                    fp->f_flag);
                break;
        default:
-               return EPASSTHROUGH;
+               res = EPASSTHROUGH;
+               break;
        }
+out:   KERNEL_UNLOCK_ONE(NULL);
        return res;
 }
 



Home | Main Index | Thread Index | Old Index