staging: speakup: fix async usb removal
authorOkash Khawaja <okash.khawaja@gmail.com>
Sat, 12 Aug 2017 08:05:47 +0000 (09:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Aug 2017 22:57:17 +0000 (15:57 -0700)
commitf5bee24d866efd73413d7b88c734a194fa46fdc5
tree5a28ec137d064828450a2e208c7413444ff38750
parent043a2e7520f23da5487c2493acf4712cd7c1461b
staging: speakup: fix async usb removal

When an external USB synth is unplugged while the module is loaded, we
get a null pointer deref. This is because the tty disappears while
speakup tries to use to to communicate with the synth. This patch fixes
it by checking tty for null before using it. Since tty can become null
between the check and its usage, a mutex is introduced. tty usage is
now surrounded by the mutex, as is the code in speakup_ldisc_close which
sets the tty to null. The mutex also serialises calls to tty from
speakup code.

In case of tty being null, this sets synth->alive to zero and restarts
ttys in case they were stopped by speakup.

Signed-off-by: Okash Khawaja <okash.khawaja@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/speakup/spk_ttyio.c