Commit 4384a3fa authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

Char: rocket, remove potential leak in module_init

if (controller && !request_region) then we leaked a tty driver struct, fix it
by adding function deinit tail with goto-ing into it (and from other fail
paths too)
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 57fedc7a
...@@ -2359,14 +2359,14 @@ static const struct tty_operations rocket_ops = { ...@@ -2359,14 +2359,14 @@ static const struct tty_operations rocket_ops = {
*/ */
static int __init rp_init(void) static int __init rp_init(void)
{ {
int retval, pci_boards_found, isa_boards_found, i; int ret = -ENOMEM, pci_boards_found, isa_boards_found, i;
printk(KERN_INFO "RocketPort device driver module, version %s, %s\n", printk(KERN_INFO "RocketPort device driver module, version %s, %s\n",
ROCKET_VERSION, ROCKET_DATE); ROCKET_VERSION, ROCKET_DATE);
rocket_driver = alloc_tty_driver(MAX_RP_PORTS); rocket_driver = alloc_tty_driver(MAX_RP_PORTS);
if (!rocket_driver) if (!rocket_driver)
return -ENOMEM; goto err;
/* /*
* If board 1 is non-zero, there is at least one ISA configured. If controller is * If board 1 is non-zero, there is at least one ISA configured. If controller is
...@@ -2381,8 +2381,11 @@ static int __init rp_init(void) ...@@ -2381,8 +2381,11 @@ static int __init rp_init(void)
/* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */ /* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */
if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) { if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) {
printk(KERN_INFO "Unable to reserve IO region for first configured ISA RocketPort controller 0x%lx. Driver exiting \n", controller); printk(KERN_ERR "Unable to reserve IO region for first "
return -EBUSY; "configured ISA RocketPort controller 0x%lx. "
"Driver exiting\n", controller);
ret = -EBUSY;
goto err_tty;
} }
/* Store ISA variable retrieved from command line or .conf file. */ /* Store ISA variable retrieved from command line or .conf file. */
...@@ -2423,11 +2426,10 @@ static int __init rp_init(void) ...@@ -2423,11 +2426,10 @@ static int __init rp_init(void)
#endif #endif
tty_set_operations(rocket_driver, &rocket_ops); tty_set_operations(rocket_driver, &rocket_ops);
retval = tty_register_driver(rocket_driver); ret = tty_register_driver(rocket_driver);
if (retval < 0) { if (ret < 0) {
printk(KERN_INFO "Couldn't install tty RocketPort driver (error %d)\n", -retval); printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
put_tty_driver(rocket_driver); goto err_tty;
return -1;
} }
#ifdef ROCKET_DEBUG_OPEN #ifdef ROCKET_DEBUG_OPEN
...@@ -2454,14 +2456,18 @@ static int __init rp_init(void) ...@@ -2454,14 +2456,18 @@ static int __init rp_init(void)
max_board = pci_boards_found + isa_boards_found; max_board = pci_boards_found + isa_boards_found;
if (max_board == 0) { if (max_board == 0) {
printk(KERN_INFO "No rocketport ports found; unloading driver.\n"); printk(KERN_ERR "No rocketport ports found; unloading driver\n");
del_timer_sync(&rocket_timer); ret = -ENXIO;
tty_unregister_driver(rocket_driver); goto err_ttyu;
put_tty_driver(rocket_driver);
return -ENXIO;
} }
return 0; return 0;
err_ttyu:
tty_unregister_driver(rocket_driver);
err_tty:
put_tty_driver(rocket_driver);
err:
return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment