[PATCH] epca: prevent panic on tty_register_driver() failure
[pandora-kernel.git] / drivers / char / epca.c
index dc0602a..706733c 100644 (file)
@@ -30,7 +30,6 @@
 /* See README.epca for change history --DAT*/
 
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -1114,11 +1113,8 @@ static void __exit epca_module_exit(void)
                ch = card_ptr[crd];
                for (count = 0; count < bd->numports; count++, ch++) 
                { /* Begin for each port */
-                       if (ch) {
-                               if (ch->tty)
-                                       tty_hangup(ch->tty);
-                               kfree(ch->tmp_buf);
-                       }
+                       if (ch && ch->tty)
+                               tty_hangup(ch->tty);
                } /* End for each port */
        } /* End for each card */
        pci_unregister_driver (&epca_driver);
@@ -1126,7 +1122,7 @@ static void __exit epca_module_exit(void)
 
 module_exit(epca_module_exit);
 
-static struct tty_operations pc_ops = {
+static const struct tty_operations pc_ops = {
        .open = pc_open,
        .close = pc_close,
        .write = pc_write,
@@ -1161,6 +1157,7 @@ static int __init pc_init(void)
        int crd;
        struct board_info *bd;
        unsigned char board_id = 0;
+       int err = -ENOMEM;
 
        int pci_boards_found, pci_count;
 
@@ -1168,13 +1165,11 @@ static int __init pc_init(void)
 
        pc_driver = alloc_tty_driver(MAX_ALLOC);
        if (!pc_driver)
-               return -ENOMEM;
+               goto out1;
 
        pc_info = alloc_tty_driver(MAX_ALLOC);
-       if (!pc_info) {
-               put_tty_driver(pc_driver);
-               return -ENOMEM;
-       }
+       if (!pc_info)
+               goto out2;
 
        /* -----------------------------------------------------------------------
                If epca_setup has not been ran by LILO set num_cards to defaults; copy
@@ -1232,7 +1227,6 @@ static int __init pc_init(void)
 
        pc_driver->owner = THIS_MODULE;
        pc_driver->name = "ttyD"; 
-       pc_driver->devfs_name = "tts/D";
        pc_driver->major = DIGI_MAJOR; 
        pc_driver->minor_start = 0;
        pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
@@ -1375,11 +1369,17 @@ static int __init pc_init(void)
 
        } /* End for each card */
 
-       if (tty_register_driver(pc_driver))
-               panic("Couldn't register Digi PC/ driver");
+       err = tty_register_driver(pc_driver);
+       if (err) {
+               printk(KERN_ERR "Couldn't register Digi PC/ driver");
+               goto out3;
+       }
 
-       if (tty_register_driver(pc_info))
-               panic("Couldn't register Digi PC/ info ");
+       err = tty_register_driver(pc_info);
+       if (err) {
+               printk(KERN_ERR "Couldn't register Digi PC/ info ");
+               goto out4;
+       }
 
        /* -------------------------------------------------------------------
           Start up the poller to check for events on all enabled boards
@@ -1390,6 +1390,15 @@ static int __init pc_init(void)
        mod_timer(&epca_timer, jiffies + HZ/25);
        return 0;
 
+out4:
+       tty_unregister_driver(pc_driver);
+out3:
+       put_tty_driver(pc_info);
+out2:
+       put_tty_driver(pc_driver);
+out1:
+       return err;
+
 } /* End pc_init */
 
 /* ------------------ Begin post_fep_init  ---------------------- */
@@ -1637,16 +1646,6 @@ static void post_fep_init(unsigned int crd)
                init_waitqueue_head(&ch->close_wait);
 
                spin_unlock_irqrestore(&epca_lock, flags);
-
-               ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
-               if (!ch->tmp_buf) {
-                       printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
-                       release_region((int)bd->port, 4);
-                       while(i-- > 0)
-                               kfree((ch--)->tmp_buf);
-                       return;
-               } else
-                       memset((void *)ch->tmp_buf,0,ch->txbufsize);
        } /* End for each port */
 
        printk(KERN_INFO