staging: fwserial: fix resource leak
authorVladimirs Ambrosovs <rodriguez.twister@gmail.com>
Mon, 25 May 2015 20:22:44 +0000 (23:22 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 31 May 2015 02:47:57 +0000 (11:47 +0900)
This patch fixes the leak, which was present in fwserial driver in the
init function. In case the tty driver allocation failed the function
returned error, leaving debugfs entry in the filesystem.

To fix the issue additional error label was added, so that the code will
jump to it in case of allocation failure, and free debugfs entries.

Signed-off-by: Vladimirs Ambrosovs <rodriguez.twister@gmail.com>
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/fwserial/fwserial.c

index fdb2418c5f888b070111ab38a98f7898e9b060e6..b3ea4bb54e2c7a80f25f86f5e01008712d22142a 100644 (file)
@@ -2815,13 +2815,14 @@ static int __init fwserial_init(void)
        /* num_ttys/num_ports must not be set above the static alloc avail */
        if (num_ttys + num_loops > MAX_CARD_PORTS)
                num_ttys = MAX_CARD_PORTS - num_loops;
+
        num_ports = num_ttys + num_loops;
 
        fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW
                                        | TTY_DRIVER_DYNAMIC_DEV);
        if (IS_ERR(fwtty_driver)) {
                err = PTR_ERR(fwtty_driver);
-               return err;
+               goto remove_debugfs;
        }
 
        fwtty_driver->driver_name       = KBUILD_MODNAME;
@@ -2923,7 +2924,9 @@ unregister_driver:
        tty_unregister_driver(fwtty_driver);
 put_tty:
        put_tty_driver(fwtty_driver);
+remove_debugfs:
        debugfs_remove_recursive(fwserial_debugfs);
+
        return err;
 }