Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3109989ybi; Thu, 18 Jul 2019 21:12:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLEVfNc31rXRbRFhkY0c+tE+YAThhLGrPPxCqTw2DyrjQZo8NeYn/TTf8f5cRAGg/Nqs0v X-Received: by 2002:a17:90a:2190:: with SMTP id q16mr53516052pjc.23.1563509579118; Thu, 18 Jul 2019 21:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509579; cv=none; d=google.com; s=arc-20160816; b=aUyM4aKZkFO3Ra1hfTUhBcDEOoLAAkqqLiUob73WIjxaJMWNf1M7GdYZmnaW/2Q0lV XSk8yNWoTkI8OvNNKv7x9rRR5pztYegarQZuIbfG3znBxLkAU4/UTTsJ6JXvI+nMSOXA 2+hMcaLlaM+gZdRM+vY3X9UKKWtVvpq7iDSpXqZa5ml3k5slOCSQCnf1uGrZou7nXwrp Nm1vN3rRF3nl2TOsTxLYnnIVSmhexMczn4FB63jIP6mldlq5GGVFQR+SqUjDAQomSokr k040N1AA7lE49epKqL2OK8At/fW+/oQXIvUQPlI49r9LuxbVmmh0O5vhSczPDLhs6Jng er3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=azTDXVNi0uyZ/wmldkPQGnBeVSNLG5OYPZkAnEQdLaE=; b=BdfjcdjKs+WclSwSaSaVk1xYbevBC8Hz/Et+WkXvY223dAZxZLve++7Z+SdDx1GbdA UPZndMut16CW4R/OWdyNbocwtpu3APP/wdbq72pSHf3Bfnl/pnndFStBpkRDR2v+L1S/ Z0e938qhb2S67NJ6TAk0dNnWjVuLqq0hCnu/f0rz6ISPRD517IZOfU34irMfJZPAhgnG CB6/+TsEo4HgYBmMZYgjIbZUnQuiawB8P+jCKjoTWjqM+3YjYzoQXVi7Plo9IyuF/9Cw L2o5VTX6MxyZi9Q9rQJJ5WH/i6X/0AGQOKoJ8RO9INwc2Lhpf7XNlGoSDZFEhgcj1Mgo Nbkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VrvL+tsa; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si2791560pld.221.2019.07.18.21.12.44; Thu, 18 Jul 2019 21:12:59 -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=@kernel.org header.s=default header.b=VrvL+tsa; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388535AbfGSELr (ORCPT + 99 others); Fri, 19 Jul 2019 00:11:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:46742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388509AbfGSELn (ORCPT ); Fri, 19 Jul 2019 00:11:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3EB0F2189E; Fri, 19 Jul 2019 04:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509502; bh=TvvcABlbRGKUObILSTVX5+PVS+Q2yIAdMwzACKoK6sI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VrvL+tsaJ5Thcrctw6gGWuxwADVZy1hfaXAZ0UN2yNykX/Q/kkzy/CvAw7P4cb7Kd +/ogEn4c051UHciPKRah+TR5B9an/Yh7FOxUFcmV5mfLbxnR+QL1tewhotUnunnIvO U8PiPdPEW6xBZRyGt7ln+b93taPVZFsy7QgbcZUM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Serge Semin , Greg Kroah-Hartman , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 20/60] tty: serial_core: Set port active bit in uart_port_activate Date: Fri, 19 Jul 2019 00:10:29 -0400 Message-Id: <20190719041109.18262-20-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719041109.18262-1-sashal@kernel.org> References: <20190719041109.18262-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serge Semin [ Upstream commit 13b18d35909707571af9539f7731389fbf0feb31 ] A bug was introduced by commit b3b576461864 ("tty: serial_core: convert uart_open to use tty_port_open"). It caused a constant warning printed into the system log regarding the tty and port counter mismatch: [ 21.644197] ttyS ttySx: tty_port_close_start: tty->count = 1 port count = 2 in case if session hangup was detected so the warning is printed starting from the second open-close iteration. Particularly the problem was discovered in situation when there is a serial tty device without hardware back-end being setup. It is considered by the tty-serial subsystems as a hardware problem with session hang up. In this case uart_startup() will return a positive value with TTY_IO_ERROR flag set in corresponding tty_struct instance. The same value will get passed to be returned from the activate() callback and then being returned from tty_port_open(). But since in this case tty_port_block_til_ready() isn't called the TTY_PORT_ACTIVE flag isn't set (while the method had been called before tty_port_open conversion was introduced and the rest of the subsystem code expected the bit being set in this case), which prevents the uart_hangup() method to perform any cleanups including the tty port counter setting to zero. So the next attempt to open/close the tty device will discover the counters mismatch. In order to fix the problem we need to manually set the TTY_PORT_ACTIVE flag in case if uart_startup() returned a positive value. In this case the hang up procedure will perform a full set of cleanup actions including the port ref-counter resetting. Fixes: b3b576461864 "tty: serial_core: convert uart_open to use tty_port_open" Signed-off-by: Serge Semin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/serial_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index c39246b916af..17e2311f7b00 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1742,6 +1742,7 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty) { struct uart_state *state = container_of(port, struct uart_state, port); struct uart_port *uport; + int ret; uport = uart_port_check(state); if (!uport || uport->flags & UPF_DEAD) @@ -1752,7 +1753,11 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty) /* * Start up the serial port. */ - return uart_startup(tty, state, 0); + ret = uart_startup(tty, state, 0); + if (ret > 0) + tty_port_set_active(port, 1); + + return ret; } static const char *uart_type(struct uart_port *port) -- 2.20.1