staging: speakup: fix failure handling
authorWilliam Hubbs <w.d.hubbs@gmail.com>
Thu, 16 Dec 2010 19:26:58 +0000 (13:26 -0600)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 10 Jan 2011 20:26:10 +0000 (12:26 -0800)
fix the failure handling in kobjects and the main function so that we
release the virtual keyboard if we exit due to another failure.

Signed-off-by: William Hubbs <w.d.hubbs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/speakup/kobjects.c
drivers/staging/speakup/main.c

index cc79f9edfe9eea01e3af06d854b95a38af2196d4..408bb9b3303e89d7c0f95e1d8c25cb99af05cc94 100644 (file)
@@ -984,8 +984,10 @@ int speakup_kobj_init(void)
         * not known ahead of time.
         */
        accessibility_kobj = kobject_create_and_add("accessibility", NULL);
-       if (!accessibility_kobj)
-               return -ENOMEM;
+       if (!accessibility_kobj) {
+               retval = -ENOMEM;
+               goto out;
+       }
 
        speakup_kobj = kobject_create_and_add("speakup", accessibility_kobj);
        if (!speakup_kobj) {
@@ -1002,7 +1004,7 @@ int speakup_kobj_init(void)
        if (retval)
                goto err_group;
 
-       return 0;
+       goto out;
 
 err_group:
        sysfs_remove_group(speakup_kobj, &main_attr_group);
@@ -1010,6 +1012,7 @@ err_speakup:
        kobject_put(speakup_kobj);
 err_acc:
        kobject_put(accessibility_kobj);
+out:
        return retval;
 }
 
index 4b7a9c2b965fd0e958d22603ea790b21e80801f2..3cd00396a462baf3d3837ca192778c25f746c683 100644 (file)
@@ -2253,17 +2253,17 @@ static int __init speakup_init(void)
 
        err = speakup_add_virtual_keyboard();
        if (err)
-               return err;
+               goto out;
 
        initialize_msgs();      /* Initialize arrays for i18n. */
        first_console = kzalloc(sizeof(*first_console), GFP_KERNEL);
-       if (!first_console)
-               return -ENOMEM;
-       err = speakup_kobj_init();
-       if (err) {
-               kfree(first_console);
-               return err;
+       if (!first_console) {
+               err = -ENOMEM;
+               goto err_cons;
        }
+       err = speakup_kobj_init();
+       if (err)
+               goto err_kobject;
 
        reset_default_chars();
        reset_default_chartab();
@@ -2299,11 +2299,20 @@ static int __init speakup_init(void)
 
        speakup_task = kthread_create(speakup_thread, NULL, "speakup");
        set_user_nice(speakup_task, 10);
-       if (!IS_ERR(speakup_task))
-               wake_up_process(speakup_task);
-       else
-               return -ENOMEM;
-       return 0;
+       if (IS_ERR(speakup_task)) {
+               err = -ENOMEM;
+               goto err_kobject;
+       }
+       wake_up_process(speakup_task);
+       goto out;
+
+err_kobject:
+speakup_kobj_exit();
+       kfree(first_console);
+err_cons:
+       speakup_remove_virtual_keyboard();
+out:
+       return err;
 }
 
 module_init(speakup_init);