Takashi Iwai 2f1f2e
From 2ea2e019c190ee3973ef7bcaf829d8762e56e635 Mon Sep 17 00:00:00 2001
Takashi Iwai 2f1f2e
From: Geert Uytterhoeven <geert+renesas@glider.be>
Takashi Iwai 2f1f2e
Date: Mon, 10 May 2021 14:07:55 +0200
Takashi Iwai 2f1f2e
Subject: [PATCH] serial: sh-sci: Fix off-by-one error in FIFO threshold register setting
Takashi Iwai 2f1f2e
Git-commit: 2ea2e019c190ee3973ef7bcaf829d8762e56e635
Takashi Iwai 2f1f2e
Patch-mainline: v5.13-rc4
Takashi Iwai 2f1f2e
References: git-fixes
Takashi Iwai 2f1f2e
Takashi Iwai 2f1f2e
The Receive FIFO Data Count Trigger field (RTRG[6:0]) in the Receive
Takashi Iwai 2f1f2e
FIFO Data Count Trigger Register (HSRTRGR) of HSCIF can only hold values
Takashi Iwai 2f1f2e
ranging from 0-127.  As the FIFO size is equal to 128 on HSCIF, the user
Takashi Iwai 2f1f2e
can write an out-of-range value, touching reserved bits.
Takashi Iwai 2f1f2e
Takashi Iwai 2f1f2e
Fix this by limiting the trigger value to the FIFO size minus one.
Takashi Iwai 2f1f2e
Reverse the order of the checks, to avoid rx_trig becoming zero if the
Takashi Iwai 2f1f2e
FIFO size is one.
Takashi Iwai 2f1f2e
Takashi Iwai 2f1f2e
Note that this change has no impact on other SCIF variants, as their
Takashi Iwai 2f1f2e
maximum supported trigger value is lower than the FIFO size anyway, and
Takashi Iwai 2f1f2e
the code below takes care of enforcing these limits.
Takashi Iwai 2f1f2e
Takashi Iwai 2f1f2e
Fixes: a380ed461f66d1b8 ("serial: sh-sci: implement FIFO threshold register setting")
Takashi Iwai 2f1f2e
Reported-by: Linh Phung <linh.phung.jy@renesas.com>
Takashi Iwai 2f1f2e
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Takashi Iwai 2f1f2e
Reviewed-by: Ulrich Hecht <uli+renesas@fpond.eu>
Takashi Iwai 2f1f2e
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Takashi Iwai 2f1f2e
Cc: stable <stable@vger.kernel.org>
Takashi Iwai 2f1f2e
Link: https://lore.kernel.org/r/5eff320aef92ffb33d00e57979fd3603bbb4a70f.1620648218.git.geert+renesas@glider.be
Takashi Iwai 2f1f2e
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Takashi Iwai 2f1f2e
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai 2f1f2e
Takashi Iwai 2f1f2e
---
Takashi Iwai 2f1f2e
 drivers/tty/serial/sh-sci.c | 4 ++--
Takashi Iwai 2f1f2e
 1 file changed, 2 insertions(+), 2 deletions(-)
Takashi Iwai 2f1f2e
Takashi Iwai 2f1f2e
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
Takashi Iwai 2f1f2e
index ef37fdf37612..4baf1316ea72 100644
Takashi Iwai 2f1f2e
--- a/drivers/tty/serial/sh-sci.c
Takashi Iwai 2f1f2e
+++ b/drivers/tty/serial/sh-sci.c
Takashi Iwai 2f1f2e
@@ -1023,10 +1023,10 @@ static int scif_set_rtrg(struct uart_port *port, int rx_trig)
Takashi Iwai 2f1f2e
 {
Takashi Iwai 2f1f2e
 	unsigned int bits;
Takashi Iwai 2f1f2e
 
Takashi Iwai 2f1f2e
+	if (rx_trig >= port->fifosize)
Takashi Iwai 2f1f2e
+		rx_trig = port->fifosize - 1;
Takashi Iwai 2f1f2e
 	if (rx_trig < 1)
Takashi Iwai 2f1f2e
 		rx_trig = 1;
Takashi Iwai 2f1f2e
-	if (rx_trig >= port->fifosize)
Takashi Iwai 2f1f2e
-		rx_trig = port->fifosize;
Takashi Iwai 2f1f2e
 
Takashi Iwai 2f1f2e
 	/* HSCIF can be set to an arbitrary level. */
Takashi Iwai 2f1f2e
 	if (sci_getreg(port, HSRTRGR)->size) {
Takashi Iwai 2f1f2e
-- 
Takashi Iwai 2f1f2e
2.26.2
Takashi Iwai 2f1f2e