From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f68.google.com ([209.85.208.68]:46244 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729147AbeH2ULK (ORCPT ); Wed, 29 Aug 2018 16:11:10 -0400 Received: by mail-ed1-f68.google.com with SMTP id k14-v6so4327621edr.13 for ; Wed, 29 Aug 2018 09:13:31 -0700 (PDT) Message-ID: <1535559207.23560.55.camel@arista.com> Subject: Re: [PATCH 1/4] tty: Drop tty->count on tty_reopen() failure From: Dmitry Safonov To: Jiri Slaby , linux-kernel@vger.kernel.org Cc: Daniel Axtens , Dmitry Safonov <0x7f454c46@gmail.com>, Sergey Senozhatsky , Dmitry Vyukov , Tan Xiaojun , Peter Hurley , Pasi =?ISO-8859-1?Q?K=E4rkk=E4inen?= , Greg Kroah-Hartman , Michael Neuling , Mikulas Patocka , stable@vger.kernel.org Date: Wed, 29 Aug 2018 17:13:27 +0100 In-Reply-To: References: <20180829022353.23568-1-dima@arista.com> <20180829022353.23568-2-dima@arista.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: stable-owner@vger.kernel.org List-ID: On Wed, 2018-08-29 at 16:38 +0200, Jiri Slaby wrote: > On 08/29/2018, 04:23 AM, Dmitry Safonov wrote: > > In case of tty_ldisc_reinit() failure, tty->count should be > > decremented > > back, otherwise we will never release_tty(). > > Never seen it in the real life, but it seems not really hard to > > hit. > > I did see it. And this fixes it. Thanks, I'll add your tested-by, if I'll have to resend. > > > Cc: Greg Kroah-Hartman > > Cc: Jiri Slaby > > Cc: stable@vger.kernel.org > > Signed-off-by: Dmitry Safonov > > --- > > drivers/tty/tty_io.c | 11 ++++++++--- > > 1 file changed, 8 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c > > index 32bc3e3fe4d3..5e5da9acaf0a 100644 > > --- a/drivers/tty/tty_io.c > > +++ b/drivers/tty/tty_io.c > > @@ -1255,6 +1255,7 @@ static void tty_driver_remove_tty(struct > > tty_driver *driver, struct tty_struct * > > static int tty_reopen(struct tty_struct *tty) > > { > > struct tty_driver *driver = tty->driver; > > + int retval; > > > > if (driver->type == TTY_DRIVER_TYPE_PTY && > > driver->subtype == PTY_TYPE_MASTER) > > @@ -1268,10 +1269,14 @@ static int tty_reopen(struct tty_struct > > *tty) > > > > tty->count++; > > > > - if (!tty->ldisc) > > - return tty_ldisc_reinit(tty, tty->termios.c_line); > > + if (tty->ldisc) > > + return 0; > > > > - return 0; > > + retval = tty_ldisc_reinit(tty, tty->termios.c_line); > > + if (retval) > > + tty->count--; > > I would just do: > if (!retval) > tty->count++; > here. Nobody from ldiscs should rely on tty->count. I thought about that and probably should have described in commit message why I haven't done that: I prefer to keep it as was as I did Cc stable tree - to keep the chance of regression to minimum. I agree that your way is cleaner, but probably it may be done as cleanup on top for linux-next.. -- Thanks, Dmitry