Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4082960ybi; Mon, 29 Jul 2019 18:53:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjZ9bnTDA1fW5fc8r3wb7wKSiTkuPUgs7aq17xwoBSX3tYBAYXwwRdew+jrZfzu6o93DrJ X-Received: by 2002:aa7:9514:: with SMTP id b20mr40430471pfp.223.1564451628065; Mon, 29 Jul 2019 18:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564451628; cv=none; d=google.com; s=arc-20160816; b=EWL9eNRDTk6Shr334GtXYwzycpo30r4Pynr+IlJNMPERTkHmhy8h66RKmXRD6q2AIR pZTlXZ1tTT3PJK/B5TtgzzZr0/MlvWMwOsDyWLVEfKVcB6qYMIOYhISIt3XWxHC7ubTD Eir3C0IiPugp0QzQgFG6ml9+6WPq3ApQn/6i+xcXTpyIqOUmvtAx+kksbKhnshdotLVH WK0fM8VmNuO2ijNapiOiKn7BSnn6TmTrQz8b5y2LWDOzkGsnVuYGo3tV3YIIKlPuHeyd 1VTdNbAO49dAlk1dZjC/pAw53CVxXatwxCkE/HYg5THeHLVQ6fxzJGtWOriRS3PRiedj Qgrw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oib5mn+xzqMbgM9MGS7T9SK6cOQPwg/xPFkZ4e8mVv4=; b=SP5EkqMvk1sgKc5LnE7/aEpAyp+UdDKcHt4p/g7w7re5NwZ0hj0jYh6VqliIebkx5s GBQehY7HymcL9Q1eXuEM5/jSRREVz+ebUulBRJplixWNHEJfnVZKZs3To9TDOADqh/hs XHF7AcExQOIZejYxiQ5TxMQGVDLHODAyGlkIwBtBC20tZ7ZTxHtIIfUDIK5o/MJDPJyY TkgBX/fqlGmUpGYGQkYdAEVvzxEp0NWK6MGGiZR4ZuA+IgW3dE1l9n5i+cdrGlCaQ21U DvizWfY4V6orqkVdwyCzHsj3lfhwDdhO11Z7SJJ0+0D8RZWO+Ftn0hXKTq0J0cnYG7PF 0a4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GJxluEHP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si32915358pfb.132.2019.07.29.18.53.33; Mon, 29 Jul 2019 18:53:48 -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=GJxluEHP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390139AbfG2Tsd (ORCPT + 99 others); Mon, 29 Jul 2019 15:48:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:38746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390094AbfG2Tsc (ORCPT ); Mon, 29 Jul 2019 15:48:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9923E205F4; Mon, 29 Jul 2019 19:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429711; bh=dY4+MCoX2L9K8Jk3aHUD3La1eiee6KJrz9EY35TJmxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GJxluEHPg3whow8CBaLV4zMZSuE/GQuQP/UnmCAuB8pj7xrqQQragvQt8CfxFvC3N 7SLh9hxLNeyZpyaa/u9fbira06CsZS5uoFqQqqXuHqJ+GZF0mVYyIHWgj8lGxUu7j9 B7+A8IcDMMrUrIB6c/XKZkQmmmR4q8/Psx8w8wIs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Serge Semin , Sasha Levin Subject: [PATCH 5.2 069/215] tty: serial_core: Set port active bit in uart_port_activate Date: Mon, 29 Jul 2019 21:21:05 +0200 Message-Id: <20190729190752.259653310@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 83f4dd0bfd74..4223cb496764 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1777,6 +1777,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) @@ -1787,7 +1788,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