dtlk: fix error checks in module_init()
authorAkinobu Mita <akinobu.mita@gmail.com>
Tue, 8 May 2007 07:29:18 +0000 (00:29 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 8 May 2007 18:15:09 +0000 (11:15 -0700)
This patch fixes two things in module_init.

- fix register_chrdev() error check

  Currently dtlk doesn't check register_chrdev() failure correctly.
  register_chrdev() returns a errno on failure.

- check probe failure

  dtlk ignores probe failure and allows the module loading without
  such device. I got "Trying to free nonexistent resource" message
  by release_region() when unloading module without device.

[akpm@linux-foundation.org: fix error code return]
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Chris Pallotta <chris@allmedia.com>
Cc: Jim Van Zandt <jrv@vanzandt.mv.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/char/dtlk.c

index 9695f88badc6fccdac61d7539a820e299125e81f..abde6ddefe696e7e0af352e918085c68a83f4d89 100644 (file)
@@ -324,16 +324,22 @@ static int dtlk_release(struct inode *inode, struct file *file)
 
 static int __init dtlk_init(void)
 {
+       int err;
+
        dtlk_port_lpc = 0;
        dtlk_port_tts = 0;
        dtlk_busy = 0;
        dtlk_major = register_chrdev(0, "dtlk", &dtlk_fops);
-       if (dtlk_major == 0) {
+       if (dtlk_major < 0) {
                printk(KERN_ERR "DoubleTalk PC - cannot register device\n");
-               return 0;
+               return dtlk_major;
+       }
+       err = dtlk_dev_probe();
+       if (err) {
+               unregister_chrdev(dtlk_major, "dtlk");
+               return err;
        }
-       if (dtlk_dev_probe() == 0)
-               printk(", MAJOR %d\n", dtlk_major);
+       printk(", MAJOR %d\n", dtlk_major);
 
        init_waitqueue_head(&dtlk_process_list);