Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1807859imm; Mon, 3 Sep 2018 09:58:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaUcxzsam/fvwKifYBUVWax2lzCCahDHWb1F09Z9psCI4L9nxiJtJDkzIpeMkWeNLkvVxA2 X-Received: by 2002:a17:902:20c6:: with SMTP id v6-v6mr9256987plg.228.1535993934423; Mon, 03 Sep 2018 09:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535993934; cv=none; d=google.com; s=arc-20160816; b=H7YAnqMDdpPpq5uZUq6SGWeEcLn58/95pAesacoFi03R2dEmXZ7aCkr+3kXwUM1a3l Ec3aK5bC25KLy9w9kqiaVwDRkqBmTi3AmTaOYBitirMiluxKiqDok6PfPWcoHruy2g4F y2+KeNzPAWudZG4y1nS8PoCRDs1YW65/RNEvCJqgnyXoBWR+rYR3YeQRptBgvO0d70so KSJkRFvJTkV/H6eO5cafGMO+CVaE+EpO22V1WF/vvivt8uQl1eicFEj/Rh3jUaezUqxt 1FYmyiOzE3ElSUSOJ6rA0AZwoKKzZ6vmUE7AhkfH+889s/W1BlJPQ3FjqQakpB1P/RXO UY+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=iHs5nPsCs9uvHVOBwfAqH+S8GyHzjtIhAK2oeqfZ/B4=; b=ekNEmZ9CfWsaf/SxjYTOImP8mksyprLFXSOIqrtJH09bic/JQ6XD/ohHS9HV07dbvV sV9tuij/5mNWNW3WMQZPF30isYya42V4Yx0Xj38NftWLgsYfEBbZnI4KU+FnpxgD7MUB VU6rg7JOupky0K2IXEAcsE+KA/cVx45Ojz23TDkNFPugorPOurPQ1/H6LmXknpAbfyCX sCg5mdw6jECE3MATUBnKY86hy3LnGy8Ry2guoBEECEouvQj+Q5e8Ol1Jl7fYtftTwQVy kfNcbj69rG/ahtDrrYBnVSsCPsQ6U/aQDDVTzECu+fRK1x2nDWVfiHR3IZ4zBKBRQTJO 0c3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=gJBdRqMW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3-v6si18919344plc.50.2018.09.03.09.58.39; Mon, 03 Sep 2018 09:58:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=gJBdRqMW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728649AbeICVN7 (ORCPT + 99 others); Mon, 3 Sep 2018 17:13:59 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:46313 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbeICVN7 (ORCPT ); Mon, 3 Sep 2018 17:13:59 -0400 Received: by mail-ed1-f66.google.com with SMTP id k14-v6so1214704edr.13 for ; Mon, 03 Sep 2018 09:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iHs5nPsCs9uvHVOBwfAqH+S8GyHzjtIhAK2oeqfZ/B4=; b=gJBdRqMW/0B7BTGBMxY/ZfhvF/cSUCzGnqTVhkPdCNYJFOYeAnaQ8mWYorDrwuNWUm VAk8uT4iALMT06ESQ30l0BVnkbzXJhn+irhbGznFp8d1l9gIyNDqnZD/45PHefFZutvD jkzLtNcMWmBYiVVtZGYnDJZ1OTPNJyc6l5l0ADXlBJj/XreMeSvfwx7XaPtmgFLz+JQn vUpmftN0E8tPpuaRhc2ExZ6ATSihYYb03snag1P4DJi3/uKY1GQjVxPD2udUcYti8zVC O3k7eqCRNo7/XdjvXGiRRCt1X/GXC6CNqLxbxdcrYtppHDJfnWwDeBPDqyOuowKBj/9p H5UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iHs5nPsCs9uvHVOBwfAqH+S8GyHzjtIhAK2oeqfZ/B4=; b=H9roZhWe5tU4Lh2Tn57fI3vUHvkcsL+E0r2YnkO556nKPsyQjFA3JUXnmFRRTCATxM aJwrMyAGaJRTXLzEVHosO6gFDPc6+HAJnpTkHKCyqVGnvNjv0r7ZsuwP8Q25EqS9Uqmc DPoZPQ8wuBLidnoD71Z+IWtxAkicZXgRh1sCyQZwswiCQS3yIU3kyeBxErn6/MWttlqy 7B8MGL+sdEAHTN+GRoUdDg8UmcCso/47lbmHp6j9FfT2IXySeDjIn2fhhto3qkIm/TBM YzUAeAuSR6SvrYEjR6arzO0bHjgYSM/8KSfrtU3irlxuKVabWRMAjLn+/WPSRCz6xlPP fgfg== X-Gm-Message-State: APzg51ALmeT21rseqdoyEcneyGXOd2cev7QTZYavXTRxAI+57fk9vbjd j/ty5iQZbHrjc7eGxEDDwzxMuBo8QWM= X-Received: by 2002:a50:b8a6:: with SMTP id l35-v6mr33259979ede.273.1535993581231; Mon, 03 Sep 2018 09:53:01 -0700 (PDT) Received: from dhcp.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id m35-v6sm8085745ede.14.2018.09.03.09.52.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 09:53:00 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Daniel Axtens , Dmitry Vyukov , Michael Neuling , Mikulas Patocka , Nathan March , =?UTF-8?q?Pasi=20K=C3=A4rkk=C3=A4inen?= , Peter Hurley , Sergey Senozhatsky , Tan Xiaojun , Tetsuo Handa , Jiri Slaby , Tetsuo Handa , Greg Kroah-Hartman , stable@vger.kernel.org Subject: [PATCHv2 1/4] tty: Drop tty->count on tty_reopen() failure Date: Mon, 3 Sep 2018 17:52:54 +0100 Message-Id: <20180903165257.29227-2-dima@arista.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180903165257.29227-1-dima@arista.com> References: <20180903165257.29227-1-dima@arista.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case of tty_ldisc_reinit() failure, tty->count should be decremented back, otherwise we will never release_tty(). Tetsuo reported that it fixes noisy warnings on tty release like: pts pts4033: tty_release: tty->count(10529) != (#fd's(7) + #kopen's(0)) Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: stable@vger.kernel.org # v4.6+ Fixes: commit 892d1fa7eaae ("tty: Destroy ldisc instance on hangup") Tested-by: Jiri Slaby Tested-by: Tetsuo Handa 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--; + + return retval; } /** -- 2.13.6