[PATCH] Char: stallion, move init/deinit
authorJiri Slaby <jirislaby@gmail.com>
Fri, 8 Dec 2006 10:38:40 +0000 (02:38 -0800)
committerLinus Torvalds <torvalds@woody.osdl.org>
Fri, 8 Dec 2006 16:28:55 +0000 (08:28 -0800)
- Move code from stl_init into module init function, because calling it was the
  only one thing, that it did.
- Move this code to the end of the driver (usual place for this) to resolve
  dependencies simply -- without prototypes.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/char/stallion.c

index b108ac6e3d83a18c23827cc6cf7b6e27fbbb67a2..f49f145e20ee267819b54e1e59c33ee234494f15 100644 (file)
@@ -278,9 +278,6 @@ static struct {
 /*
  *     Define the module agruments.
  */
-MODULE_AUTHOR("Greg Ungerer");
-MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
-MODULE_LICENSE("GPL");
 
 module_param_array(board0, charp, &stl_nargs, 0);
 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
@@ -458,7 +455,6 @@ static int  stl_parsebrd(struct stlconf *confp, char **argp);
 
 static unsigned long stl_atol(char *str);
 
-static int     stl_init(void);
 static int     stl_open(struct tty_struct *tty, struct file *filp);
 static void    stl_close(struct tty_struct *tty, struct file *filp);
 static int     stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
@@ -708,90 +704,8 @@ static const struct file_operations        stl_fsiomem = {
        .ioctl          = stl_memioctl,
 };
 
-/*****************************************************************************/
-
 static struct class *stallion_class;
 
-/*
- *     Loadable module initialization stuff.
- */
-
-static int __init stallion_module_init(void)
-{
-       stl_init();
-       return 0;
-}
-
-/*****************************************************************************/
-
-static void __exit stallion_module_exit(void)
-{
-       struct stlbrd   *brdp;
-       struct stlpanel *panelp;
-       struct stlport  *portp;
-       int             i, j, k;
-
-       pr_debug("cleanup_module()\n");
-
-       printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
-               stl_drvversion);
-
-/*
- *     Free up all allocated resources used by the ports. This includes
- *     memory and interrupts. As part of this process we will also do
- *     a hangup on every open port - to try to flush out any processes
- *     hanging onto ports.
- */
-       i = tty_unregister_driver(stl_serial);
-       put_tty_driver(stl_serial);
-       if (i) {
-               printk("STALLION: failed to un-register tty driver, "
-                       "errno=%d\n", -i);
-               return;
-       }
-       for (i = 0; i < 4; i++)
-               class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
-       if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
-               printk("STALLION: failed to un-register serial memory device, "
-                       "errno=%d\n", -i);
-       class_destroy(stallion_class);
-
-       for (i = 0; (i < stl_nrbrds); i++) {
-               if ((brdp = stl_brds[i]) == NULL)
-                       continue;
-
-               free_irq(brdp->irq, brdp);
-
-               for (j = 0; (j < STL_MAXPANELS); j++) {
-                       panelp = brdp->panels[j];
-                       if (panelp == NULL)
-                               continue;
-                       for (k = 0; (k < STL_PORTSPERPANEL); k++) {
-                               portp = panelp->ports[k];
-                               if (portp == NULL)
-                                       continue;
-                               if (portp->tty != NULL)
-                                       stl_hangup(portp->tty);
-                               kfree(portp->tx.buf);
-                               kfree(portp);
-                       }
-                       kfree(panelp);
-               }
-
-               release_region(brdp->ioaddr1, brdp->iosize1);
-               if (brdp->iosize2 > 0)
-                       release_region(brdp->ioaddr2, brdp->iosize2);
-
-               kfree(brdp);
-               stl_brds[i] = NULL;
-       }
-}
-
-module_init(stallion_module_init);
-module_exit(stallion_module_exit);
-
-/*****************************************************************************/
-
 /*
  *     Check for any arguments passed in on the module load command line.
  */
@@ -2934,55 +2848,6 @@ static const struct tty_operations stl_ops = {
        .tiocmset = stl_tiocmset,
 };
 
-/*****************************************************************************/
-
-static int __init stl_init(void)
-{
-       int i;
-       printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
-
-       spin_lock_init(&stallion_lock);
-       spin_lock_init(&brd_lock);
-
-       stl_initbrds();
-
-       stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
-       if (!stl_serial)
-               return -1;
-
-/*
- *     Set up a character driver for per board stuff. This is mainly used
- *     to do stats ioctls on the ports.
- */
-       if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
-               printk("STALLION: failed to register serial board device\n");
-
-       stallion_class = class_create(THIS_MODULE, "staliomem");
-       for (i = 0; i < 4; i++)
-               class_device_create(stallion_class, NULL,
-                                   MKDEV(STL_SIOMEMMAJOR, i), NULL,
-                                   "staliomem%d", i);
-
-       stl_serial->owner = THIS_MODULE;
-       stl_serial->driver_name = stl_drvname;
-       stl_serial->name = "ttyE";
-       stl_serial->major = STL_SERIALMAJOR;
-       stl_serial->minor_start = 0;
-       stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
-       stl_serial->subtype = SERIAL_TYPE_NORMAL;
-       stl_serial->init_termios = stl_deftermios;
-       stl_serial->flags = TTY_DRIVER_REAL_RAW;
-       tty_set_operations(stl_serial, &stl_ops);
-
-       if (tty_register_driver(stl_serial)) {
-               put_tty_driver(stl_serial);
-               printk("STALLION: failed to register serial driver\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 /*****************************************************************************/
 /*                       CD1400 HARDWARE FUNCTIONS                           */
 /*****************************************************************************/
@@ -4954,4 +4819,123 @@ static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
        }
 }
 
-/*****************************************************************************/
+/*
+ *     Loadable module initialization stuff.
+ */
+static int __init stallion_module_init(void)
+{
+       unsigned int i;
+
+       printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
+
+       spin_lock_init(&stallion_lock);
+       spin_lock_init(&brd_lock);
+
+       stl_initbrds();
+
+       stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
+       if (!stl_serial)
+               return -1;
+
+/*
+ *     Set up a character driver for per board stuff. This is mainly used
+ *     to do stats ioctls on the ports.
+ */
+       if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
+               printk("STALLION: failed to register serial board device\n");
+
+       stallion_class = class_create(THIS_MODULE, "staliomem");
+       for (i = 0; i < 4; i++)
+               class_device_create(stallion_class, NULL,
+                                   MKDEV(STL_SIOMEMMAJOR, i), NULL,
+                                   "staliomem%d", i);
+
+       stl_serial->owner = THIS_MODULE;
+       stl_serial->driver_name = stl_drvname;
+       stl_serial->name = "ttyE";
+       stl_serial->major = STL_SERIALMAJOR;
+       stl_serial->minor_start = 0;
+       stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
+       stl_serial->subtype = SERIAL_TYPE_NORMAL;
+       stl_serial->init_termios = stl_deftermios;
+       stl_serial->flags = TTY_DRIVER_REAL_RAW;
+       tty_set_operations(stl_serial, &stl_ops);
+
+       if (tty_register_driver(stl_serial)) {
+               put_tty_driver(stl_serial);
+               printk("STALLION: failed to register serial driver\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static void __exit stallion_module_exit(void)
+{
+       struct stlbrd   *brdp;
+       struct stlpanel *panelp;
+       struct stlport  *portp;
+       int             i, j, k;
+
+       pr_debug("cleanup_module()\n");
+
+       printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
+               stl_drvversion);
+
+/*
+ *     Free up all allocated resources used by the ports. This includes
+ *     memory and interrupts. As part of this process we will also do
+ *     a hangup on every open port - to try to flush out any processes
+ *     hanging onto ports.
+ */
+       i = tty_unregister_driver(stl_serial);
+       put_tty_driver(stl_serial);
+       if (i) {
+               printk("STALLION: failed to un-register tty driver, "
+                       "errno=%d\n", -i);
+               return;
+       }
+       for (i = 0; i < 4; i++)
+               class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
+       if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
+               printk("STALLION: failed to un-register serial memory device, "
+                       "errno=%d\n", -i);
+       class_destroy(stallion_class);
+
+       for (i = 0; (i < stl_nrbrds); i++) {
+               if ((brdp = stl_brds[i]) == NULL)
+                       continue;
+
+               free_irq(brdp->irq, brdp);
+
+               for (j = 0; (j < STL_MAXPANELS); j++) {
+                       panelp = brdp->panels[j];
+                       if (panelp == NULL)
+                               continue;
+                       for (k = 0; (k < STL_PORTSPERPANEL); k++) {
+                               portp = panelp->ports[k];
+                               if (portp == NULL)
+                                       continue;
+                               if (portp->tty != NULL)
+                                       stl_hangup(portp->tty);
+                               kfree(portp->tx.buf);
+                               kfree(portp);
+                       }
+                       kfree(panelp);
+               }
+
+               release_region(brdp->ioaddr1, brdp->iosize1);
+               if (brdp->iosize2 > 0)
+                       release_region(brdp->ioaddr2, brdp->iosize2);
+
+               kfree(brdp);
+               stl_brds[i] = NULL;
+       }
+}
+
+module_init(stallion_module_init);
+module_exit(stallion_module_exit);
+
+MODULE_AUTHOR("Greg Ungerer");
+MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
+MODULE_LICENSE("GPL");