Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3584010pxb; Mon, 24 Jan 2022 12:49:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIS7FxscUgZNY6W52oDT0q/PyFMfy+HLiH4Tlj3simq6nWLWDLa/PylIn6hc55i6ZvFFrL X-Received: by 2002:a63:40c5:: with SMTP id n188mr13084418pga.118.1643057378837; Mon, 24 Jan 2022 12:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057378; cv=none; d=google.com; s=arc-20160816; b=yvCxyckQ4QPeTXVgq2SeFYGaCh3uYCjJgTSurxi+zmOrK2YjkBo1UM8g6Ma6IuHTDj zrhws+tQolcDg5rEB2kKv0k7wkjGe4Jd0bEmab3KPfecCs7zmv1/yermPXORX8+o190Q 7ObnllIjTotTy8T5+BRsiLJsS4c7WXld7EMfOjX7UKBINykslPBFsgmQlTqNcMAsAgK2 e4glJjehZjgJu/2IGY6ydpiAnSnI+uDM9kAQchae6IrjRWA9MJtO0tS6CpgHkP2kLuRP qeDi40VEHdfacwTh6uhV0wUDRYqBMZH8kVAFkuM01+lK5C41VgG/JTn5171hov+cyaz7 R2CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KhgLr4qGrnGhxlwqhqloaOIOSFi9le+IzeklrZRWXIk=; b=pNl9VwRUZVnrtP+SLzRzpwpd6gSITqbFnQtgbXoftC6HrOw96amxQo+PVhgRKhN3nb cXEbIQ5mJrdCC5VB1eGL9//dw30ezQ7Fzp2kcFblr21jyuOBQRx1hKktwysb3lhqktuR 4jWXMaGQXiVid0frQ8uzEZna4PToXjaEvkWd51AR+sojJYQaYUAW+Wn720uiH9yX2vKM IL24Q99PHZqOg/bgIoOMd5SW23p/MPm3nQHf4IfogfHzIlxfSkG9+cn4TMW+uOp77pJR U4qj/RTbxZMYdowCAZzunb5DeiPnYhAHSs0rnj7Cz/d6Vn6dmjOmRTr4Nd6hHoHjfO99 KEFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vCWCgfat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si13842470pge.854.2022.01.24.12.49.26; Mon, 24 Jan 2022 12:49:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vCWCgfat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377377AbiAXUFY (ORCPT + 99 others); Mon, 24 Jan 2022 15:05:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356828AbiAXTr0 (ORCPT ); Mon, 24 Jan 2022 14:47:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11834C038AEB; Mon, 24 Jan 2022 11:23:18 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BABFBB810BD; Mon, 24 Jan 2022 19:23:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6331C340E5; Mon, 24 Jan 2022 19:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052194; bh=5Ymn2AW/zGqbjw3qp2nR15M/bmz7QlMmrneVUroSo4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vCWCgfat/DXx8mHeHIK5uMfDo57a1tGH2ypsclv3GOznEHRsFXV8safVxpJb30TVU NGrBCrD/gleI45GwhSbjDUVBXfOdMQEbIsICjzno6ES7tSuEMwohT4S+XnL4ofs2tt K8QvIvUYKBAgojFuYtBOxBhyf4oZJSRc3MWMX7uo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Sasha Levin Subject: [PATCH 4.19 176/239] serial: core: Keep mctrl register state and cached copy in sync Date: Mon, 24 Jan 2022 19:43:34 +0100 Message-Id: <20220124183948.698401680@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner [ Upstream commit 93a770b7e16772530196674ffc79bb13fa927dc6 ] struct uart_port contains a cached copy of the Modem Control signals. It is used to skip register writes in uart_update_mctrl() if the new signal state equals the old signal state. It also avoids a register read to obtain the current state of output signals. When a uart_port is registered, uart_configure_port() changes signal state but neglects to keep the cached copy in sync. That may cause a subsequent register write to be incorrectly skipped. Fix it before it trips somebody up. This behavior has been present ever since the serial core was introduced in 2002: https://git.kernel.org/history/history/c/33c0d1b0c3eb So far it was never an issue because the cached copy is initialized to 0 by kzalloc() and when uart_configure_port() is executed, at most DTR has been set by uart_set_options() or sunsu_console_setup(). Therefore, a stable designation seems unnecessary. Signed-off-by: Lukas Wunner Link: https://lore.kernel.org/r/bceeaba030b028ed810272d55d5fc6f3656ddddb.1641129752.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/serial_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 63aefe7e91be1..ab4d0f6058c04 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2347,7 +2347,8 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, * We probably don't need a spinlock around this, but */ spin_lock_irqsave(&port->lock, flags); - port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR); + port->mctrl &= TIOCM_DTR; + port->ops->set_mctrl(port, port->mctrl); spin_unlock_irqrestore(&port->lock, flags); /* -- 2.34.1