[PATCH]: fix kobject initialization in drivers/char/tty_io.c

From: Nikita Danilov (Nikita@Namesys.COM)
Date: Fri Jun 06 2003 - 12:07:35 EST


Hello,

in 2.5.70, UML fails to boot with

Initializing stdio console driver
Badness in kobject_get at lib/kobject.c:351

it seems that problem is that drivers/char/tty_io.c:tty_init() is now
called after arch/um/stdio_console.c:stdio_init(), and when the latter
calls tty_register_driver(), neither tty_kobj, nor tty_cdev are yet
initialized. Below is a work around.

Nikita.
===== drivers/char/tty_io.c 1.105 vs edited =====
--- 1.105/drivers/char/tty_io.c Fri Jun 6 02:19:36 2003
+++ edited/drivers/char/tty_io.c Fri Jun 6 20:27:05 2003
@@ -2233,6 +2233,19 @@
 EXPORT_SYMBOL(tty_unregister_device);
 
 static struct kobject tty_kobj = {.name = "tty"};
+static struct cdev tty_cdev, console_cdev;
+static int kobj_bootstraped = 0;
+static void kobj_bootstrap(void)
+{
+ if (!kobj_bootstraped) {
+ kobj_bootstraped = 1;
+ strcpy(tty_cdev.kobj.name, "dev.tty");
+ cdev_init(&tty_cdev, &tty_fops);
+ tty_kobj.kset = tty_cdev.kobj.kset;
+ kobject_register(&tty_kobj);
+ }
+}
+
 /*
  * Called by a tty driver to register itself.
  */
@@ -2261,6 +2274,8 @@
         if (error < 0)
                 return error;
 
+ kobj_bootstrap();
+
         driver->cdev.kobj.parent = &tty_kobj;
         strcpy(driver->cdev.kobj.name, driver->name);
         for (s = strchr(driver->cdev.kobj.name, '/'); s; s = strchr(s, '/'))
@@ -2372,7 +2387,6 @@
 
 postcore_initcall(tty_class_init);
  
-static struct cdev tty_cdev, console_cdev;
 #ifdef CONFIG_UNIX98_PTYS
 static struct cdev ptmx_cdev;
 #endif
@@ -2386,8 +2400,7 @@
  */
 void __init tty_init(void)
 {
- strcpy(tty_cdev.kobj.name, "dev.tty");
- cdev_init(&tty_cdev, &tty_fops);
+ kobj_bootstrap();
         if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
             register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
                 panic("Couldn't register /dev/tty driver\n");
@@ -2401,9 +2414,6 @@
                 panic("Couldn't register /dev/console driver\n");
         devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
         tty_add_class_device ("console", MKDEV(TTYAUX_MAJOR, 1), NULL);
-
- tty_kobj.kset = tty_cdev.kobj.kset;
- kobject_register(&tty_kobj);
 
 #ifdef CONFIG_UNIX98_PTYS
         strcpy(ptmx_cdev.kobj.name, "dev.ptmx");

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jun 07 2003 - 22:00:30 EST