char: misc: fix error path
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Mon, 13 Jul 2015 12:02:28 +0000 (17:32 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jul 2015 17:30:47 +0000 (10:30 -0700)
Lets call remove_proc_entry() in the error path only if we have
successfully created "misc" in procfs.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/misc.c

index 3b95795cb640cad01ff8cf742771c9b3fedbf1f1..c83ef9652bc9c6dd38b6f52f8fc9f08853b995a5 100644 (file)
@@ -281,8 +281,9 @@ static char *misc_devnode(struct device *dev, umode_t *mode)
 static int __init misc_init(void)
 {
        int err;
+       struct proc_dir_entry *ret;
 
-       proc_create("misc", 0, NULL, &misc_proc_fops);
+       ret = proc_create("misc", 0, NULL, &misc_proc_fops);
        misc_class = class_create(THIS_MODULE, "misc");
        err = PTR_ERR(misc_class);
        if (IS_ERR(misc_class))
@@ -298,7 +299,8 @@ fail_printk:
        printk("unable to get major %d for misc devices\n", MISC_MAJOR);
        class_destroy(misc_class);
 fail_remove:
-       remove_proc_entry("misc", NULL);
+       if (ret)
+               remove_proc_entry("misc", NULL);
        return err;
 }
 subsys_initcall(misc_init);