From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752451AbdGGTNM (ORCPT ); Fri, 7 Jul 2017 15:13:12 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33523 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750938AbdGGTNK (ORCPT ); Fri, 7 Jul 2017 15:13:10 -0400 Date: Fri, 7 Jul 2017 20:13:01 +0100 From: Okash Khawaja To: Greg Kroah-Hartman , Samuel Thibault , linux-kernel@vger.kernel.org Cc: William Hubbs , Chris Brannon , Kirk Reiser , speakup@linux-speakup.org, devel@driverdev.osuosl.org Subject: [patch] staging: speakup: safely close tty Message-ID: <20170707191301.GA3798@sanghar> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Speakup opens tty using tty_open_by_driver. When closing, it calls tty_ldisc_release but doesn't close and remove the tty itself. As a result, that tty cannot then be opened from user space. This patch calls tty_release_struct which ensures that tty is safely removed and freed up. It also calls tty_ldisc_release, so speakup doesn't need to call it. This patch also unregisters N_SPEAKUP. It is registered when a speakup module is loaded. Signed-off-by: Okash Khawaja --- drivers/staging/speakup/spk_ttyio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/staging/speakup/spk_ttyio.c +++ b/drivers/staging/speakup/spk_ttyio.c @@ -300,7 +300,9 @@ void spk_ttyio_release(void) tty_ldisc_flush(speakup_tty); tty_unlock(speakup_tty); - tty_ldisc_release(speakup_tty); + tty_release_struct(speakup_tty, speakup_tty->index); + if (tty_unregister_ldisc(N_SPEAKUP)) + pr_warn("speakup: failed to unregister line discipline N_SPEAKUP\n"); } EXPORT_SYMBOL_GPL(spk_ttyio_release);