Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4520816rwb; Tue, 6 Sep 2022 08:37:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NE7rAd0W7VebSD75jIhMhdnEFNa/mb3DbWUx2DsBShn0hfpgVUvcBcoPSexPRzVwza5m1 X-Received: by 2002:aa7:8614:0:b0:538:1024:904e with SMTP id p20-20020aa78614000000b005381024904emr46524228pfn.49.1662478660727; Tue, 06 Sep 2022 08:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662478660; cv=none; d=google.com; s=arc-20160816; b=ELNZuRb8fNPnZtDHKJapX+zC6NKHEJ75uVXAGbUf47qHanhKJr9+JSkcDTaT+n+T9P gk4Ngjc1yCdJhPy7PAGpQJwwYYP988KTcJsZcTd+Nair0/F+W1k6RzbqCIe9kzKRMV5g lmgpzUsxNt/KFiRCj1F3toZ6s9T/dQTf/i6eXnhQbdV75RE3CxcQy7OQNe60gf1s+8F0 TQvS8UXwI8a1dwwheyNFO+sikY4E3gIV8I9kUm9Y0GqliURmULM4VSrnw+ssyeerJXrx Qe/5pRl0uYWOs2tmoaacUuAc545QI6VaY2simjDK98/9lkpsRAcV0RV0wwmoRrWUUQHI jNqw== 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=Xt0QM1rNfdquUdfmdYGOXL45hQogeHcL96RXcMpFOTE=; b=c170CkGypXawhdZer1eE748T2Y4q2bJaDug6AcEB6g4OMxz7uz4d8ldUbkmg8ohdRg HdmvduulIpOGWRkTZLy9b1mXvIdQlxI2njOVPLCGevN1hsF28RzbQaaRl88AfHdiOBLt N1nY7UfOvrOV1en2hJ759jFnmeT6/9nlhNVGdnUoXCcLsSbTZwm5JGxwcQhLJrMv8Tj7 gsyn5H/y4N5qwBrL9L9KiI1cQfDzgs+cIbqSCnEWdhWHiYrqqYlDVeooaGa0i+j6ks1e foZdEK3HgW5xNdLI6It8LSNCvtdTxFThDaLUTOaERKjATCqfLaV+ZkinRxexRrJEIzKw 5YlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kv4l2PeD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a636a08000000b00431588a5120si13086952pgc.183.2022.09.06.08.37.06; Tue, 06 Sep 2022 08:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kv4l2PeD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239693AbiIFOGX (ORCPT + 99 others); Tue, 6 Sep 2022 10:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241600AbiIFOE6 (ORCPT ); Tue, 6 Sep 2022 10:04:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A084083F01; Tue, 6 Sep 2022 06:45:15 -0700 (PDT) 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 613BEB818D0; Tue, 6 Sep 2022 13:44:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB744C433D6; Tue, 6 Sep 2022 13:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471842; bh=3vLOcgOQRoKDbqVzILQZO5iKskhLWHAaoJxUpBy/VaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kv4l2PeDuRPGqYeVyG7AfgyDzGdXZMrZxs8SysL4lSIw/SfXpyJB7OXJ+ULEBSDjr GJSWKJLFPP/N4BFO187+31l6J4OtPYuwmh1d2v93sGPFGxGfVo3SObGjAWuQCDr0ie McLw4zVO8m9CU1yFrdk7uHU/Sxg3n4v88xtjRS1Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Sergiu Moga Subject: [PATCH 5.19 057/155] tty: serial: atmel: Preserve previous USART mode if RS485 disabled Date: Tue, 6 Sep 2022 15:30:05 +0200 Message-Id: <20220906132831.833358405@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergiu Moga commit 692a8ebcfc24f4a5bea0eb2967e450f584193da6 upstream. Whenever the atmel_rs485_config() driver method would be called, the USART mode is reset to normal mode before even checking if RS485 flag is set, thus resulting in losing the previous USART mode in the case where the checking fails. Some tools, such as `linux-serial-test`, lead to the driver calling this method when doing the setup of the serial port: after setting the port mode (Hardware Flow Control, Normal Mode, RS485 Mode, etc.), `linux-serial-test` tries to enable/disable RS485 depending on the commandline arguments that were passed. Example of how this issue could reveal itself: When doing a serial communication with Hardware Flow Control through `linux-serial-test`, the tool would lead to the driver roughly doing the following: - set the corresponding bit to 1 (ATMEL_US_USMODE_HWHS bit in the ATMEL_US_MR register) through the atmel_set_termios() to enable Hardware Flow Control - disable RS485 through the atmel_config_rs485() method Thus, when the latter is called, the mode will be reset and the previously set bit is unset, leaving USART in normal mode instead of the expected Hardware Flow Control mode. This fix ensures that this reset is only done if the checking for RS485 succeeds and that the previous mode is preserved otherwise. Fixes: e8faff7330a35 ("ARM: 6092/1: atmel_serial: support for RS485 communications") Cc: stable Reviewed-by: Ilpo Järvinen Signed-off-by: Sergiu Moga Link: https://lore.kernel.org/r/20220824142902.502596-1-sergiu.moga@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/atmel_serial.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -296,9 +296,6 @@ static int atmel_config_rs485(struct uar mode = atmel_uart_readl(port, ATMEL_US_MR); - /* Resetting serial mode to RS232 (0x0) */ - mode &= ~ATMEL_US_USMODE; - if (rs485conf->flags & SER_RS485_ENABLED) { dev_dbg(port->dev, "Setting UART to RS485\n"); if (rs485conf->flags & SER_RS485_RX_DURING_TX) @@ -308,6 +305,7 @@ static int atmel_config_rs485(struct uar atmel_uart_writel(port, ATMEL_US_TTGR, rs485conf->delay_rts_after_send); + mode &= ~ATMEL_US_USMODE; mode |= ATMEL_US_USMODE_RS485; } else { dev_dbg(port->dev, "Setting UART to RS232\n");