mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-13 00:29:50 +00:00
tty: ehv_bytechan: clean up init error handling
Straighten out the initcall error handling to avoid deregistering a never-registered tty driver (something which would lead to a NULL-pointer dereference) in the most unlikely event that driver registration fails (e.g. we've run out of major numbers). Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1e948479b3
commit
11d4d32158
@ -764,7 +764,7 @@ static int __init ehv_bc_init(void)
|
|||||||
ehv_bc_driver = alloc_tty_driver(count);
|
ehv_bc_driver = alloc_tty_driver(count);
|
||||||
if (!ehv_bc_driver) {
|
if (!ehv_bc_driver) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto error;
|
goto err_free_bcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
ehv_bc_driver->driver_name = "ehv-bc";
|
ehv_bc_driver->driver_name = "ehv-bc";
|
||||||
@ -778,24 +778,23 @@ static int __init ehv_bc_init(void)
|
|||||||
ret = tty_register_driver(ehv_bc_driver);
|
ret = tty_register_driver(ehv_bc_driver);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("ehv-bc: could not register tty driver (ret=%i)\n", ret);
|
pr_err("ehv-bc: could not register tty driver (ret=%i)\n", ret);
|
||||||
goto error;
|
goto err_put_tty_driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = platform_driver_register(&ehv_bc_tty_driver);
|
ret = platform_driver_register(&ehv_bc_tty_driver);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("ehv-bc: could not register platform driver (ret=%i)\n",
|
pr_err("ehv-bc: could not register platform driver (ret=%i)\n",
|
||||||
ret);
|
ret);
|
||||||
goto error;
|
goto err_deregister_tty_driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
err_deregister_tty_driver:
|
||||||
if (ehv_bc_driver) {
|
tty_unregister_driver(ehv_bc_driver);
|
||||||
tty_unregister_driver(ehv_bc_driver);
|
err_put_tty_driver:
|
||||||
put_tty_driver(ehv_bc_driver);
|
put_tty_driver(ehv_bc_driver);
|
||||||
}
|
err_free_bcs:
|
||||||
|
|
||||||
kfree(bcs);
|
kfree(bcs);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user