summaryrefslogtreecommitdiff
path: root/drivers/staging/speakup
diff options
context:
space:
mode:
authorOkash Khawaja <okash.khawaja@gmail.com>2017-07-16 17:18:26 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-07-18 09:03:22 +0200
commite23a9b439ce9bd9cbd3d92e4c15db086d3e11410 (patch)
tree821668be689cb841cb5b0c33ca163862fb9d762c /drivers/staging/speakup
parent9f8dced2085c33a633d2f0a1abbf13ff5a7ed8c9 (diff)
staging: speakup: safely register and unregister ldisc
This patch makes use of functions added in the previous patch. It registers ldisc during init of main speakup module and unregisters it during exit. It also removes the code to register ldisc every time a synth module is loaded. This way we only register the ldisc once when main speakup module is loaded. Since main speakup module is required by all synth modules, it is only unloaded when all synths have been unloaded. Therefore we unregister the ldisc once, when all speakup related references to the ldisc have returned. In unlikely scenario of something outside speakup using the ldisc, the ldisc refcount check in tty_unregister_ldisc will ensure that it is not unregistered while in use. The function to register ldisc doesn't cause speakup init function to fail. That is different from current behaviour where failure to register ldisc results in failure to load the specific synth module. This is because speakup module is also required by those synths which don't use tty and ldisc. We don't want to prevent those modules from loading when ldisc fails to register. The synth modules will correctly fail when trying to set N_SPEAKUP to tty, if ldisc registrationi had failed. Signed-off-by: Okash Khawaja <okash.khawaja@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/speakup')
-rw-r--r--drivers/staging/speakup/main.c2
-rw-r--r--drivers/staging/speakup/spk_ttyio.c8
2 files changed, 4 insertions, 6 deletions
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index 82e5de248947..67956e24779c 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -2314,6 +2314,7 @@ static void __exit speakup_exit(void)
mutex_lock(&spk_mutex);
synth_release();
mutex_unlock(&spk_mutex);
+ spk_ttyio_unregister_ldisc();
speakup_kobj_exit();
@@ -2376,6 +2377,7 @@ static int __init speakup_init(void)
if (err)
goto error_kobjects;
+ spk_ttyio_register_ldisc();
synth_init(synth_name);
speakup_register_devsynth();
/*
diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
index 9b02345f66cc..fe340b07c482 100644
--- a/drivers/staging/speakup/spk_ttyio.c
+++ b/drivers/staging/speakup/spk_ttyio.c
@@ -154,12 +154,6 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth)
struct ktermios tmp_termios;
dev_t dev;
- ret = tty_register_ldisc(N_SPEAKUP, &spk_ttyio_ldisc_ops);
- if (ret) {
- pr_err("Error registering line discipline.\n");
- return ret;
- }
-
ret = get_dev_to_use(synth, &dev);
if (ret)
return ret;
@@ -196,6 +190,8 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth)
tty_unlock(tty);
ret = tty_set_ldisc(tty, N_SPEAKUP);
+ if (ret)
+ pr_err("speakup: Failed to set N_SPEAKUP on tty\n");
return ret;
}