Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3715798pxb; Mon, 24 Jan 2022 16:09:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJz02j3D3iVwurFWYcLuDKzkDrUAU1nE6umlbxpA+2BUrk6JtEVb8fZ4tf6Kfkhp8JMt3vDh X-Received: by 2002:a17:902:da88:b0:14b:337f:1918 with SMTP id j8-20020a170902da8800b0014b337f1918mr11080554plx.129.1643069378018; Mon, 24 Jan 2022 16:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069378; cv=none; d=google.com; s=arc-20160816; b=lwDIaw4JUzDXB7EhzeoPeQ0x8RNWMrieV7f4eWvdX9JbXRDN05gRPVr6Wsc3c/4xJ+ jW8ayoJ+4lp8ffObKHUa4DedQ+26wfUGF/v8KiR7hqrfGlbVYsVrfDw4vRqRGB9w+HqG EuyWDY13ctaz+CBAa/P3U49IVWYCEVqsMwtgSCeO9Zf+ewtMBwr9qzuieuqm8JnTykaS FqirJF3t2AGZgIZZZbPeJbTmM9U2rxs5/0pXL/1htQvkv2xVEJ5c9bvCLxoUDaa/3Du5 zSouGKYxuFed3cT7PwxaSKx/L+QNgubny17Q+RhKzR4FU3OT/EoYfl0nzjV7irlQ7GQD p7dQ== 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=4+fjvD1vhGne+jowjOdxR6M9TEqApgbsmsX/4KFGLoU=; b=ABzM0zPy6Top1tw1ZffF3/IWWA91a5o2hX5EbYAwBABjCmYHP7mzADUo3T8XA0uyFR cwLR5Z0ufSFXrXKE/OUnmfQy3YYmumxpTB0r6Bnse5pzaI7ScbaUF1bTmd79RF4XV8Il hfikvaXXL2ZYxxahpC1GykYyR/4gIifA9J7TK0NHuYmpKhouEseDWS70EeA9J/2R2oAO 7ysLjSLfzcYeIC7KxIw950q15nD6WtzEKeBeRQMvCR6p1oO0vIkhsNitYvvwXH2T67VS GuDDSCK4CeKt/a1cUfFvnkfrOc98Jwmmy/ZbJuZj/Drb9xATiqGpS9VuQTKGxD4DT7C0 R9Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hRzZEr5a; 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 u12si1235450plg.8.2022.01.24.16.09.25; Mon, 24 Jan 2022 16:09: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=hRzZEr5a; 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 S1388304AbiAYAJP (ORCPT + 99 others); Mon, 24 Jan 2022 19:09:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1848470AbiAXXWe (ORCPT ); Mon, 24 Jan 2022 18:22:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46BE0C073089; Mon, 24 Jan 2022 13:29:21 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D8EFB614DC; Mon, 24 Jan 2022 21:29:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2A0C340ED; Mon, 24 Jan 2022 21:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059760; bh=AOczSnWdWced6oq1iyNUhjT2AeFnG/1hKhyVL7vUbzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hRzZEr5aQUszG5Ok3Yc2vzyJS5MGBvjbwu9FcFwJd4i8DpeE1Q2DwZ8rIpPv13Ufo E4Abacu6rWlzy2kv0dWl2JCU/ZYvMbX+SHfquP9gJSq/8as4Qu5bsa+ViYtBIGPnXG 303DEQ3kd6p8EopQnhmh2p+ThkeDrrU1mCVy5okM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Sasha Levin Subject: [PATCH 5.16 0723/1039] serial: core: Keep mctrl register state and cached copy in sync Date: Mon, 24 Jan 2022 19:41:52 +0100 Message-Id: <20220124184149.637956247@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 61e3dd0222af1..9e7e624a6c9db 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2393,7 +2393,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