Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: fwserial: fix resource leak

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>

authored by

Vladimirs Ambrosovs and committed by
Greg Kroah-Hartman
904998bf 71d667b8

+4 -1
+4 -1
drivers/staging/fwserial/fwserial.c
··· 2815 2815 /* num_ttys/num_ports must not be set above the static alloc avail */ 2816 2816 if (num_ttys + num_loops > MAX_CARD_PORTS) 2817 2817 num_ttys = MAX_CARD_PORTS - num_loops; 2818 + 2818 2819 num_ports = num_ttys + num_loops; 2819 2820 2820 2821 fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW 2821 2822 | TTY_DRIVER_DYNAMIC_DEV); 2822 2823 if (IS_ERR(fwtty_driver)) { 2823 2824 err = PTR_ERR(fwtty_driver); 2824 - return err; 2825 + goto remove_debugfs; 2825 2826 } 2826 2827 2827 2828 fwtty_driver->driver_name = KBUILD_MODNAME; ··· 2924 2923 tty_unregister_driver(fwtty_driver); 2925 2924 put_tty: 2926 2925 put_tty_driver(fwtty_driver); 2926 + remove_debugfs: 2927 2927 debugfs_remove_recursive(fwserial_debugfs); 2928 + 2928 2929 return err; 2929 2930 } 2930 2931