summaryrefslogtreecommitdiff
path: root/drivers/tty/ehv_bytechan.c
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2021-07-23 09:43:12 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-07-27 12:17:20 +0200
commit0524513afe45a4a79f418c0377160b7712cab78a (patch)
treeeab43a3f41c183818029805709a1abbf6625ef21 /drivers/tty/ehv_bytechan.c
parent7ccbdcc4d08a6d7041e4849219bbb12ffa45db4c (diff)
tty: don't store semi-state into tty drivers
When a tty driver pointer is used as a return value of struct console's device() hook, don't store a semi-state into global variable which holds the tty driver. It could mean console::device() would return a bogus value. This is important esp. after the next patch where we switch from alloc_tty_driver to tty_alloc_driver. tty_alloc_driver returns ERR_PTR in case of error and that might have unexpected results as the code doesn't expect this. Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: Helge Deller <deller@gmx.de> Cc: Chris Zankel <chris@zankel.net> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com> Cc: Felipe Balbi <balbi@kernel.org> Reviewed-by: Max Filippov <jcmvbkbc@gmail.com> Acked-by: Helge Deller <deller@gmx.de> # parisc Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20210723074317.32690-4-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/ehv_bytechan.c')
-rw-r--r--drivers/tty/ehv_bytechan.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
index 445e5ff9b36d..97ae940af478 100644
--- a/drivers/tty/ehv_bytechan.c
+++ b/drivers/tty/ehv_bytechan.c
@@ -751,6 +751,7 @@ static struct platform_driver ehv_bc_tty_driver = {
*/
static int __init ehv_bc_init(void)
{
+ struct tty_driver *driver;
struct device_node *np;
unsigned int count = 0; /* Number of elements in bcs[] */
int ret;
@@ -773,26 +774,28 @@ static int __init ehv_bc_init(void)
if (!bcs)
return -ENOMEM;
- ehv_bc_driver = alloc_tty_driver(count);
- if (!ehv_bc_driver) {
+ driver = alloc_tty_driver(count);
+ if (!driver) {
ret = -ENOMEM;
goto err_free_bcs;
}
- ehv_bc_driver->driver_name = "ehv-bc";
- ehv_bc_driver->name = ehv_bc_console.name;
- ehv_bc_driver->type = TTY_DRIVER_TYPE_CONSOLE;
- ehv_bc_driver->subtype = SYSTEM_TYPE_CONSOLE;
- ehv_bc_driver->init_termios = tty_std_termios;
- ehv_bc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
- tty_set_operations(ehv_bc_driver, &ehv_bc_ops);
+ driver->driver_name = "ehv-bc";
+ driver->name = ehv_bc_console.name;
+ driver->type = TTY_DRIVER_TYPE_CONSOLE;
+ driver->subtype = SYSTEM_TYPE_CONSOLE;
+ driver->init_termios = tty_std_termios;
+ driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+ tty_set_operations(driver, &ehv_bc_ops);
- ret = tty_register_driver(ehv_bc_driver);
+ ret = tty_register_driver(driver);
if (ret) {
pr_err("ehv-bc: could not register tty driver (ret=%i)\n", ret);
goto err_put_tty_driver;
}
+ ehv_bc_driver = driver;
+
ret = platform_driver_register(&ehv_bc_tty_driver);
if (ret) {
pr_err("ehv-bc: could not register platform driver (ret=%i)\n",
@@ -803,9 +806,10 @@ static int __init ehv_bc_init(void)
return 0;
err_deregister_tty_driver:
- tty_unregister_driver(ehv_bc_driver);
+ ehv_bc_driver = NULL;
+ tty_unregister_driver(driver);
err_put_tty_driver:
- put_tty_driver(ehv_bc_driver);
+ put_tty_driver(driver);
err_free_bcs:
kfree(bcs);