sio(4) - Fix double make_dev if used as console
authorAlex Hornung <ahornung@gmail.com>
Mon, 7 Sep 2009 11:34:45 +0000 (12:34 +0100)
committerAlex Hornung <ahornung@gmail.com>
Mon, 7 Sep 2009 11:43:38 +0000 (12:43 +0100)
* sio was calling another make_dev for ttyd0 if it was being used as
  console. This is no longer valid with devfs, so we look for the
  existing ttyd0, as it must exist already if the device has been
  attached.

Dragonfly-bug: http://bugs.dragonflybsd.org/issue1485
Reported-by: Hasso Tepper, Jordan Gordeev
sys/dev/serial/sio/sio.c

index 71e62b1..edc30ad 100644 (file)
@@ -2977,16 +2977,22 @@ siocninit(struct consdev *cp)
 static void
 siocninit_fini(struct consdev *cp)
 {
+       cdev_t dev;
        int unit;
 
        if (cp->cn_probegood) {
                unit = (int)(intptr_t)cp->cn_private;
-               //kprintf("siocninit_fini: make_dev for ttyd%r\n", unit);
-               //if ((cp->cn_dev = devfs_find_device_by_name("ttyd%r", unit)) == NULL) {
-               cp->cn_dev = make_dev(&sio_ops, unit,
-                             UID_ROOT, GID_WHEEL, 0600,
-                                 "ttyd%r", unit);
-               //}
+               /*
+                * Call devfs_find_device_by_name on ttydX to find the correct device,
+                * as it should have been created already at this point by the
+                * attach routine.
+                * If it isn't found, the serial port was not attached at all and we
+                * shouldn't be here, so assert this case.
+                */
+               dev = devfs_find_device_by_name("ttyd%r", unit);
+
+               KKASSERT(dev != NULL);
+               cp->cn_dev = dev;
        }
 }