Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1805684imm; Mon, 3 Sep 2018 09:55:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbclR+l/q9nEtZwJ3XybpIsScZJJ1ZStehbq78EMAW43fa7Zr3N17qrSPY9kpoAREHvD4BL X-Received: by 2002:a17:902:e190:: with SMTP id cd16-v6mr29203468plb.305.1535993715145; Mon, 03 Sep 2018 09:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535993715; cv=none; d=google.com; s=arc-20160816; b=lvN3CRGUACNAgele7SJqM2jSkICoiVEDpabRXfhIIhEtCu3/l+q7GlSXdrFFoH/akj sKs7MNqUp/j7bbjDinUKzmDlD4rqVQWvSjvuI3iGrQxvUYmL6dB157MgAg9fxGH6bco7 HC6VqOmx98IsP5O2put0r/gxLr+Mn/3/1As0lzG56ZYrjKTARhwYrRei4jUc/hWiz0R2 JhrdiGj0iT6O7A1FyHE8RDLtussPDNcUMRzYThNOebSYEYlVvoDUzG16SzHzd9T2/bRb pMU6yNrMIYHzfCCcPyHauPbiI/i2Oh6YYrk4nFN6Mj+X8Bz4SvlqMQae7QYJmAqMlPcc Nm2Q== 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=jvdqY9eG7WLUmp029ivjAYmnogrvA/F5X2EcXNbUPzQ=; b=RvMl+u6eOne7t/Nlj7EX/VMzRLSgSq4JGyA64lw+wI+9t1P/8kzvxUkkhiYXqp65DD J6Z9hpO6dxdNo3FOsvjxcsmx6pOrBf73gDslLxAg7+uMA6S0Rg35nK1jB6PUgjlyHjEd VnSU/msxQSSDe7nt0bngqCD/3LB+HKy+t4vE3oWkQYSmf1v2NGSPdadXAJRhrNBKH/IT jRArC0pbIgg7mek5VJm/UwhTmGQuNpJXJhKNGmLcLLopiFF8u0ozt6iO9B9bE3BeOWn8 KX0dQ9oEVfbPHrJyu2lFWAVu86COLc3LkzUI4UMyoXkAiMAcxsm5Sb76KP1gr8k4z6sl MJvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=XCiT5ceK; 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 z20-v6si17972590pgk.17.2018.09.03.09.55.00; Mon, 03 Sep 2018 09:55:15 -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=XCiT5ceK; 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 S1728725AbeICVOF (ORCPT + 99 others); Mon, 3 Sep 2018 17:14:05 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:46321 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbeICVOD (ORCPT ); Mon, 3 Sep 2018 17:14:03 -0400 Received: by mail-ed1-f68.google.com with SMTP id k14-v6so1214873edr.13 for ; Mon, 03 Sep 2018 09:53:06 -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=jvdqY9eG7WLUmp029ivjAYmnogrvA/F5X2EcXNbUPzQ=; b=XCiT5ceKdBDONTnHw1Pu1aGFNqrGwvM2qNZ4OcXV5L7QNCWu27W6gLOmLNj6jYGgeg EKcNyEjy7XTZU/t69rFZF8fErGgIqki6zJodEV+u243ZBXlpdgqm/vwsRG5mXt7llnwo STTTi8f0r5mTztjBYQ8ET6z52u0r39QZWc+LF5U9xKeimEQU5yCrbhACLLaz820jYgcH OysFDdvy5FrRicl8j1z/qpkGbVDOfyZ8XjKNnHa+AgaCarfvBg5AV5xTUB/xXyTIjECz XIbHSSXPFZAO2yWh4q2hkoxS3YHSwhiZXkfCfRMzpq+wVbTpRPFPPOybm84Buh3S/yNq VYRg== 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=jvdqY9eG7WLUmp029ivjAYmnogrvA/F5X2EcXNbUPzQ=; b=dJhWnAn9f7qFB5m1Qr5d6q/Iwz7TnBuPvHn5v2WS74hbSEThy9chZGkax3HYRDxHL2 JDIGr7kmM9nmbrKA3aE5DPkZ/OgvljqxWJrkBRQ6m8IoeOvs1G3CUGLsJrpmqtPpjYTX c2cb+fPsQLNTXbgU+LLXTTp8IEsVic/sLh0cbQV5iY4JRTqT4a/944xCEBfqcijvDE4I KdT3jIEgQnxsYStPlJLsrlCUbKseSwAUJCv0MnMPrJpLjXLefm+cVo6X0hTLTWH8rkPb MjsQhXKXGLuvqJSxN4+L0CLznbdJ7W4JPRszeX3ztA2ucEhDAZQWgI53euBJUZtqgb3N js5w== X-Gm-Message-State: APzg51ADFI56JGsNq2BiJu32+d112QMq7e27mhXk8uTFNVlPXjGEia4W IqCUNtjaj+DdGghITOq7iWOnJEG76pc= X-Received: by 2002:a50:80e6:: with SMTP id 93-v6mr31333297edb.73.1535993585465; Mon, 03 Sep 2018 09:53:05 -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.53.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 09:53:04 -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 , Greg Kroah-Hartman Subject: [PATCHv2 4/4] tty: Simplify tty->count math in tty_reopen() Date: Mon, 3 Sep 2018 17:52:57 +0100 Message-Id: <20180903165257.29227-5-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 As noted by Jiri, tty_ldisc_reinit() shouldn't rely on tty counter. Simplify math by increasing the counter after reinit success. Cc: Greg Kroah-Hartman Cc: Jiri Slaby Link: lkml.kernel.org/r/<20180829022353.23568-2-dima@arista.com> Suggested-by: Jiri Slaby Signed-off-by: Dmitry Safonov --- drivers/tty/tty_io.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index a947719b4626..7f968ac14bbd 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1268,17 +1268,13 @@ static int tty_reopen(struct tty_struct *tty) return -EBUSY; tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT); + if (!tty->ldisc) + retval = tty_ldisc_reinit(tty, tty->termios.c_line); + tty_ldisc_unlock(tty); - tty->count++; - if (tty->ldisc) - goto out_unlock; + if (retval == 0) + tty->count++; - retval = tty_ldisc_reinit(tty, tty->termios.c_line); - if (retval) - tty->count--; - -out_unlock: - tty_ldisc_unlock(tty); return retval; } -- 2.13.6