Source-Changes-HG archive

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

[src/prg-localcount2]: src/sys/kern No need to panic if a modular driver does...



details:   https://anonhg.NetBSD.org/src/rev/1b8961c0cabb
branches:  prg-localcount2
changeset: 823516:1b8961c0cabb
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Fri Apr 28 02:36:10 2017 +0000

description:
No need to panic if a modular driver doesn't include the required
localcount members in the {b,c}devsw.  Just log a console message
and return EINVAL to signal failure.

diffstat:

 sys/kern/subr_devsw.c |  39 ++++++++++++++++++++++++++-------------
 1 files changed, 26 insertions(+), 13 deletions(-)

diffs (76 lines):

diff -r 39a5a07cf40c -r 1b8961c0cabb sys/kern/subr_devsw.c
--- a/sys/kern/subr_devsw.c     Fri Apr 28 02:13:19 2017 +0000
+++ b/sys/kern/subr_devsw.c     Fri Apr 28 02:36:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_devsw.c,v 1.37.2.1 2017/04/27 05:36:37 pgoyette Exp $     */
+/*     $NetBSD: subr_devsw.c,v 1.37.2.2 2017/04/28 02:36:10 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.37.2.1 2017/04/27 05:36:37 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.37.2.2 2017/04/28 02:36:10 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -150,15 +150,22 @@
        mutex_enter(&device_lock);
 
        if (bdev != NULL) {
-               KASSERTMSG(bdev->d_localcount != NULL,
-                   "%s: bdev %s has no d_localcount", __func__, devname);
-               KASSERTMSG(bdev->d_localcount != cdev->d_localcount,
-                   "%s: bdev and cdev for %s have same d_localcount",
+               if (bdev->d_localcount == NULL) {
+                       aprint_normal("%s: %s's bdevsw has no localcount",
+                           __func__, devname);
+                       return EINVAL;
+               }
+               if (bdev->d_localcount == cdev->d_localcount) {
+                       aprint_normal("%s: %s uses same localcount for both "
+                           cdevsw and bdevsw", __func__, devname);
+                       return EINVAL;
+               }
+       }
+       if (cdev != NULL) {
+               aprint_normal("%s: %s's cdevsw has no localcount",
                    __func__, devname);
+               return EINVAL;
        }
-       if (cdev != NULL)
-               KASSERTMSG(cdev->d_localcount != NULL,
-                   "%s: cdev %s has no d_localcount", __func__, devname);
 
        for (i = 0 ; i < max_devsw_convs ; i++) {
                conv = &devsw_conv[i];
@@ -300,8 +307,11 @@
        if (bdevsw[*devmajor] != NULL)
                return (EEXIST);
 
-       KASSERTMSG(devsw->d_localcount != NULL, "%s: bdev for major %d has "
-           "no localcount", __func__, *devmajor);
+       if (devsw->d_localcount == NULL) {
+               aprint_normal("%s: %s's bdevsw has no localcount",
+                   __func__, devname);
+               return EINVAL;
+       }
        localcount_init(devsw->d_localcount);
 
        /* ensure visibility of the bdevsw */
@@ -354,8 +364,11 @@
        if (cdevsw[*devmajor] != NULL)
                return (EEXIST);
 
-       KASSERTMSG(devsw->d_localcount != NULL, "%s: cdev for major %d has "
-           "no localcount", __func__, *devmajor);
+       if (devsw->d_localcount == NULL) {
+               aprint_normal("%s: %s's cdevsw has no localcount",
+                   __func__, devname);
+               return EINVAL;
+       }
        localcount_init(devsw->d_localcount);
 
        /* ensure visibility of the cdevsw */



Home | Main Index | Thread Index | Old Index