aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/rocket.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2007-10-18 06:06:28 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-18 17:37:27 -0400
commit4384a3fae10c1badb859d2c98a6d2944b14609f6 (patch)
tree08359a5b77d7535ddf80fddbd641f665213cc2af /drivers/char/rocket.c
parent57fedc7ae5f712c9c24f5baf30a0fbf38c1bda20 (diff)
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: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/rocket.c')
-rw-r--r--drivers/char/rocket.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index ffcd8b4fbf99..abe3ad0f6195 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -2359,14 +2359,14 @@ static const struct tty_operations rocket_ops = {
2359 */ 2359 */
2360static int __init rp_init(void) 2360static int __init rp_init(void)
2361{ 2361{
2362 int retval, pci_boards_found, isa_boards_found, i; 2362 int ret = -ENOMEM, pci_boards_found, isa_boards_found, i;
2363 2363
2364 printk(KERN_INFO "RocketPort device driver module, version %s, %s\n", 2364 printk(KERN_INFO "RocketPort device driver module, version %s, %s\n",
2365 ROCKET_VERSION, ROCKET_DATE); 2365 ROCKET_VERSION, ROCKET_DATE);
2366 2366
2367 rocket_driver = alloc_tty_driver(MAX_RP_PORTS); 2367 rocket_driver = alloc_tty_driver(MAX_RP_PORTS);
2368 if (!rocket_driver) 2368 if (!rocket_driver)
2369 return -ENOMEM; 2369 goto err;
2370 2370
2371 /* 2371 /*
2372 * If board 1 is non-zero, there is at least one ISA configured. If controller is 2372 * 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 2381
2382 /* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */ 2382 /* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */
2383 if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) { 2383 if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) {
2384 printk(KERN_INFO "Unable to reserve IO region for first configured ISA RocketPort controller 0x%lx. Driver exiting \n", controller); 2384 printk(KERN_ERR "Unable to reserve IO region for first "
2385 return -EBUSY; 2385 "configured ISA RocketPort controller 0x%lx. "
2386 "Driver exiting\n", controller);
2387 ret = -EBUSY;
2388 goto err_tty;
2386 } 2389 }
2387 2390
2388 /* Store ISA variable retrieved from command line or .conf file. */ 2391 /* Store ISA variable retrieved from command line or .conf file. */
@@ -2423,11 +2426,10 @@ static int __init rp_init(void)
2423#endif 2426#endif
2424 tty_set_operations(rocket_driver, &rocket_ops); 2427 tty_set_operations(rocket_driver, &rocket_ops);
2425 2428
2426 retval = tty_register_driver(rocket_driver); 2429 ret = tty_register_driver(rocket_driver);
2427 if (retval < 0) { 2430 if (ret < 0) {
2428 printk(KERN_INFO "Couldn't install tty RocketPort driver (error %d)\n", -retval); 2431 printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
2429 put_tty_driver(rocket_driver); 2432 goto err_tty;
2430 return -1;
2431 } 2433 }
2432 2434
2433#ifdef ROCKET_DEBUG_OPEN 2435#ifdef ROCKET_DEBUG_OPEN
@@ -2454,14 +2456,18 @@ static int __init rp_init(void)
2454 max_board = pci_boards_found + isa_boards_found; 2456 max_board = pci_boards_found + isa_boards_found;
2455 2457
2456 if (max_board == 0) { 2458 if (max_board == 0) {
2457 printk(KERN_INFO "No rocketport ports found; unloading driver.\n"); 2459 printk(KERN_ERR "No rocketport ports found; unloading driver\n");
2458 del_timer_sync(&rocket_timer); 2460 ret = -ENXIO;
2459 tty_unregister_driver(rocket_driver); 2461 goto err_ttyu;
2460 put_tty_driver(rocket_driver);
2461 return -ENXIO;
2462 } 2462 }
2463 2463
2464 return 0; 2464 return 0;
2465err_ttyu:
2466 tty_unregister_driver(rocket_driver);
2467err_tty:
2468 put_tty_driver(rocket_driver);
2469err:
2470 return ret;
2465} 2471}
2466 2472
2467 2473