Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3552511pxb; Mon, 24 Jan 2022 12:03:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIboQ+N8jKp7hc4XRti3pCH3NZO5rCDC5DFBxf+1zP1Qm3DzgXy10xHSdq699/mN/4k9RP X-Received: by 2002:a17:903:1c2:b0:14b:465f:2482 with SMTP id e2-20020a17090301c200b0014b465f2482mr7822028plh.73.1643054629647; Mon, 24 Jan 2022 12:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054629; cv=none; d=google.com; s=arc-20160816; b=BXLTBN8XCV/iL0EDJ6Yzcp2AnWHBjLnumJFIc+Hk3nBl0ug06aXlVWUep3T+hlQFVz 20w6OUfhc/OobMt8/MEMqpGxkZm/5ZDZclGNIO4Zmro4xXqk7UKwamzZy5HGX3Hh6TVT aGsYkVyTgFLYZtDKBQhMffgoJWsA6lTji+CVABbufuKBzUe4jKNUDkgjthRH1wlXVeJy kJ8V30kIR1vdwHV/L7hUr8oZpYm9IimqxvQYRHuta9alHqeyYpM4tAZbQpshVpHyAEin 7sLpaU+wLSUc7m7GNzS3br+XV0SgHC4TCFTsXfB8dLjufofiuosxDy6fvG/YX2IYlgHx QVJA== 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=tFFsjxsTEQPfQs2b0tCSzwkMrQ6U0LQ12CNTH6lB/TA=; b=BZseQ43zGFlm5wteN7q/pY04SEJk0A/wUFpaany3MJemTn2V0hM1yTyVleReSG+kbU 8XiC4gFulKem73zHj9iD6IkBFQCvRuXbT/0Db3oyg4/5P+JhXFiSDQbxu783K9vMsH2i ppgRf18E829Su5XcfJsh89bIn2KHdBmVWssr+8oA/N4krKvFEaY/YQDew9sgigLZZ4Nl L2YSWAeYAOUFTAmQu9zv/q6i3+LSy2yIP/mtE6gEfVvCE7Znyt5ZosjMgb2+AitjNItK qdNkNTa4M0wC5OZVkfLU9IqtByy15mPiWZiIA1ygl5vyAKaqRWy3cZ7kmeD2K+kUU4O5 PpHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZZRCyZTD; 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 kx13si254731pjb.43.2022.01.24.12.03.37; Mon, 24 Jan 2022 12:03:49 -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=ZZRCyZTD; 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 S1344808AbiAXTDk (ORCPT + 99 others); Mon, 24 Jan 2022 14:03:40 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:56362 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344839AbiAXS7U (ORCPT ); Mon, 24 Jan 2022 13:59:20 -0500 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 357ED608D4; Mon, 24 Jan 2022 18:59:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1149C340E7; Mon, 24 Jan 2022 18:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050759; bh=JcvhSTU1IQqq+oYId9prgK7Cki2I3kfKY0v6RsGm2zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZZRCyZTDZyPus2+l4q0LdJRch7rrwToPzmfdrchKkx/NsSdfTlSMdLQF/BawoYX8a 78FylcI1c47+0HY0hSsCRTaC3ztSh4zN+vYf/UKxh6hRkGW3ZNVBI1n63z6ONdxhCN NoIbIxqzJVm8rMtd9dTd/t3lX7NhyLH4ECZvBlPw= 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.9 103/157] serial: core: Keep mctrl register state and cached copy in sync Date: Mon, 24 Jan 2022 19:43:13 +0100 Message-Id: <20220124183936.032114999@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@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 e97961dc3622d..ec458add38833 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2349,7 +2349,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