Source-Changes-HG archive

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

[src/trunk]: src/sys/dev check for when cnopen() will call itself recursively...



details:   https://anonhg.NetBSD.org/src/rev/36190be721cf
branches:  trunk
changeset: 487722:36190be721cf
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Jun 12 05:02:22 2000 +0000

description:
check for when cnopen() will call itself recursively, and panic instead of losing badly.

diffstat:

 sys/dev/cons.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (52 lines):

diff -r 33b229b55d62 -r 36190be721cf sys/dev/cons.c
--- a/sys/dev/cons.c    Mon Jun 12 04:43:11 2000 +0000
+++ b/sys/dev/cons.c    Mon Jun 12 05:02:22 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cons.c,v 1.36 2000/05/08 16:30:57 itojun Exp $ */
+/*     $NetBSD: cons.c,v 1.37 2000/06/12 05:02:22 mrg Exp $    */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -65,6 +65,7 @@
        int flag, mode;
        struct proc *p;
 {
+       dev_t cndev;
 
        if (cn_tab == NULL)
                return (0);
@@ -74,8 +75,8 @@
         * later.  This follows normal device semantics; they always get
         * open() calls.
         */
-       dev = cn_tab->cn_dev;
-       if (dev == NODEV) {
+       cndev = cn_tab->cn_dev;
+       if (cndev == NODEV) {
                /*
                 * This is most likely an error in the console attach
                 * code. Panicing looks better than jumping into nowhere
@@ -83,12 +84,21 @@
                 */
                panic("cnopen: cn_tab->cn_dev == NODEV\n");
        }
+       if (dev == cndev) {
+               /*
+                * This causes cnopen() to be called recursively, which
+                * is generally a bad thing.  It is often caused when
+                * dev == 0 and cn_dev has not been set, but was probably
+                * initialised to 0.
+                */
+               panic("cnopen: cn_tab->cn_dev == dev\n");
+       }
 
        if (cn_devvp == NULLVP) {
                /* try to get a reference on its vnode, but fail silently */
-               cdevvp(dev, &cn_devvp);
+               cdevvp(cndev, &cn_devvp);
        }
-       return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p));
+       return ((*cdevsw[major(cndev)].d_open)(cndev, flag, mode, p));
 }
  
 int



Home | Main Index | Thread Index | Old Index