提交 904998bf 编写于 作者: V Vladimirs Ambrosovs 提交者: Greg Kroah-Hartman

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: NVladimirs Ambrosovs <rodriguez.twister@gmail.com>
Reviewed-by: NPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 71d667b8
...@@ -2815,13 +2815,14 @@ static int __init fwserial_init(void) ...@@ -2815,13 +2815,14 @@ static int __init fwserial_init(void)
/* num_ttys/num_ports must not be set above the static alloc avail */ /* num_ttys/num_ports must not be set above the static alloc avail */
if (num_ttys + num_loops > MAX_CARD_PORTS) if (num_ttys + num_loops > MAX_CARD_PORTS)
num_ttys = MAX_CARD_PORTS - num_loops; num_ttys = MAX_CARD_PORTS - num_loops;
num_ports = num_ttys + num_loops; num_ports = num_ttys + num_loops;
fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV); | TTY_DRIVER_DYNAMIC_DEV);
if (IS_ERR(fwtty_driver)) { if (IS_ERR(fwtty_driver)) {
err = PTR_ERR(fwtty_driver); err = PTR_ERR(fwtty_driver);
return err; goto remove_debugfs;
} }
fwtty_driver->driver_name = KBUILD_MODNAME; fwtty_driver->driver_name = KBUILD_MODNAME;
...@@ -2923,7 +2924,9 @@ static int __init fwserial_init(void) ...@@ -2923,7 +2924,9 @@ static int __init fwserial_init(void)
tty_unregister_driver(fwtty_driver); tty_unregister_driver(fwtty_driver);
put_tty: put_tty:
put_tty_driver(fwtty_driver); put_tty_driver(fwtty_driver);
remove_debugfs:
debugfs_remove_recursive(fwserial_debugfs); debugfs_remove_recursive(fwserial_debugfs);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册