From patchwork Tue Jan 8 20:18:49 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: 1022124 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 43Z3WR0yDVz9sDT; Wed, 9 Jan 2019 07:19:15 +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 1ggxqA-0008Ac-D9; Tue, 08 Jan 2019 20:19:10 +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 1ggxq8-00089U-OE for kernel-team@lists.ubuntu.com; Tue, 08 Jan 2019 20:19:08 +0000 Received: from mail-qt1-f200.google.com ([209.85.160.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ggxq8-0007W2-Cp for kernel-team@lists.ubuntu.com; Tue, 08 Jan 2019 20:19:08 +0000 Received: by mail-qt1-f200.google.com with SMTP id q33so4433445qte.23 for ; Tue, 08 Jan 2019 12:19:08 -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=ffmMCU1KCBzmnlF6X6PSQymDye13r/ObwNXg06AP3oY=; b=e1hYn82Cv3X+XtQhYpAXpHvF8Gb1M0LoiWzYcREBhrnWDTPycKe0P42x27EIbxs+r7 A5dxFY3xkj3D6gD9xmjH/c3fANH6YjQLRQ1nlehDnJnKXCM8WN9O6DtiNxiD8u4pE/X9 KU+ZPbA9Pmi6Q8/ia9xT0FAjho/x0wNwl8Y2mKKxHqalAmwwW4SKGIS0tHHkOTX5e8CT ZdAk1uAjE+QjYcLXF2ox0Jq1z4qNXvQLH2mq3qPGAj01aqTDlGmHHYB2EX4mjcUX+bHd k2LEHNcojumXz02pphq4XRqbuKKP2ttEW3kktJzD2wXOBnDmRKCfKQHsb3+58h+SkRJI 6pPw== X-Gm-Message-State: AJcUukd/L030CnWAHoc3xSJYzSw72A0zn1CBuxBBbzyt12MSKO4xaCiB rbn+rGmc7drZnetbsI842coFK3QmpynH5RIe448/Iwf/yaWzoSILNRVy5VELqyQaPFStVO5YNSq 2CtmvqAkwOFYEjNux/EAlHys23t5H5Gk7LiK+NOPOKg== X-Received: by 2002:ac8:16d8:: with SMTP id y24mr3085566qtk.253.1546978747170; Tue, 08 Jan 2019 12:19:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Y5L69IrXeSYcDBAY2qQVLVsUf/PZGguz0+4GJrBoLFBFoS5hFNnL8VKzu98Rx5MHFIhMi/g== X-Received: by 2002:ac8:16d8:: with SMTP id y24mr3085544qtk.253.1546978746743; Tue, 08 Jan 2019 12:19:06 -0800 (PST) Received: from localhost ([191.13.50.232]) by smtp.gmail.com with ESMTPSA id g19sm7208513qke.2.2019.01.08.12.19.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 12:19:06 -0800 (PST) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [SRU X] [PATCH 5/5] tty: Simplify tty->count math in tty_reopen() Date: Tue, 8 Jan 2019 18:18:49 -0200 Message-Id: <20190108201849.11907-6-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 As notted by Jiri, tty_ldisc_reinit() shouldn't rely on tty counter. Simplify math by increasing the counter after reinit success. Cc: Jiri Slaby Link: lkml.kernel.org/r/<20180829022353.23568-2-dima@arista.com> Suggested-by: Jiri Slaby Reviewed-by: Jiri Slaby Tested-by: Mark Rutland Signed-off-by: Dmitry Safonov Signed-off-by: Greg Kroah-Hartman (cherry-picked from cf62a1a13749db0d32b5cdd800ea91a4087319de upstream) Signed-off-by: Guilherme G. Piccoli --- drivers/tty/tty_io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 3784f55f3dc9..a7511d5fad9e 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1490,16 +1490,13 @@ static int tty_reopen(struct tty_struct *tty) if (retval) return retval; - tty->count++; - if (tty->ldisc) - goto out_unlock; - - retval = tty_ldisc_reinit(tty, tty->termios.c_line); - if (retval) - tty->count--; - -out_unlock: + if (!tty->ldisc) + retval = tty_ldisc_reinit(tty, tty->termios.c_line); tty_ldisc_unlock(tty); + + if (retval == 0) + tty->count++; + return retval; }