From patchwork Tue Jan 8 20:18:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 1022121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43Z3WJ5dn8z9sCr; Wed, 9 Jan 2019 07:19:08 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ggxq3-000850-F4; Tue, 08 Jan 2019 20:19:03 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1ggxq0-00083D-IE for kernel-team@lists.ubuntu.com; Tue, 08 Jan 2019 20:19:00 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ggxq0-0007Uk-8O for kernel-team@lists.ubuntu.com; Tue, 08 Jan 2019 20:19:00 +0000 Received: by mail-qk1-f198.google.com with SMTP id y27so4176156qkj.21 for ; Tue, 08 Jan 2019 12:19:00 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=wWdG+GMtzbcrUg0Pc/q3Qs0BeOnjeoRFT6zFM7R6vCU=; b=ovmsgJKQxVINZdBoyyGFlpUZcJtPWTUW3ntbpca0gdTR4PQUBeCDe5crZp/FBjKy7q At0nUvCGwKw7Ks2iN1p4A/kYKYARmTY8KFAScZgmVSqe1qTK2kkUw02zUiVVRp/pDo2C p6t19D/6yh21VEWUR94ZWOEnS6MGApmJGWAi/AAJ1w/6DL6U6GB1fjCI/LD+bPL/mS+2 M9O/NX9Jv/5F4manmwoygkPMcYB4yH39II5V6k/16HQAG8ZiIWRFeKv1SZGEv8qp6rcR rEmTkAFlndf0IKsSSiaQjWgZVGydcPGowcm6uRhNUqfyduxdDcjpYoxnntkYMJt1dJRM aTJQ== X-Gm-Message-State: AJcUukcqe93bhKaaqImOLZ7zRYfy4KzRcnKJI2AFjpKS/ozmDIiS+q8Y FEis35ZUdpOQZTGBV0v8rTn7rEj1ltxcdxVqgsyVrN5Od1MsE0X0BUFDXUDzjv4jrE0WtE1RvRe ZI9AJEbcvXFmmNDSAl/+mVqQKZEomX06kTshZ3FQ1KA== X-Received: by 2002:aed:39a1:: with SMTP id m30mr2980113qte.354.1546978739038; Tue, 08 Jan 2019 12:18:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN5q6zwX4MIAbjtIieCoIeLC+FL8DG/+x0UEG4FeoUnU0BBishtnXA2iHJHX2NNDdqFs61Xcaw== X-Received: by 2002:aed:39a1:: with SMTP id m30mr2980095qte.354.1546978738757; Tue, 08 Jan 2019 12:18:58 -0800 (PST) Received: from localhost ([191.13.50.232]) by smtp.gmail.com with ESMTPSA id c12sm43377929qka.42.2019.01.08.12.18.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 12:18:58 -0800 (PST) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [SRU X] [PATCH 2/5] tty: Drop tty->count on tty_reopen() failure Date: Tue, 8 Jan 2019 18:18:46 -0200 Message-Id: <20190108201849.11907-3-gpiccoli@canonical.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190108201849.11907-1-gpiccoli@canonical.com> References: <20190108201849.11907-1-gpiccoli@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gpiccoli@canonical.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dmitry Safonov BugLink: https://bugs.launchpad.net/bugs/1791758 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)) Fixes: commit 892d1fa7eaae ("tty: Destroy ldisc instance on hangup") Cc: stable@vger.kernel.org # v4.6+ Cc: Greg Kroah-Hartman Cc: Jiri Slaby Reviewed-by: Jiri Slaby Tested-by: Jiri Slaby Tested-by: Mark Rutland Tested-by: Tetsuo Handa Signed-off-by: Dmitry Safonov Signed-off-by: Greg Kroah-Hartman (cherry-picked from fe32416790093b31364c08395727de17ec96ace1 upstream) Signed-off-by: Guilherme G. Piccoli --- 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 2ed3d2add7d4..d2f00378fc18 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1474,6 +1474,7 @@ void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty) 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) @@ -1487,10 +1488,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; } /**