Skip to content

Commit 2ea2e01

Browse files
geertugregkh
authored andcommitted
serial: sh-sci: Fix off-by-one error in FIFO threshold register setting
The Receive FIFO Data Count Trigger field (RTRG[6:0]) in the Receive FIFO Data Count Trigger Register (HSRTRGR) of HSCIF can only hold values ranging from 0-127. As the FIFO size is equal to 128 on HSCIF, the user can write an out-of-range value, touching reserved bits. Fix this by limiting the trigger value to the FIFO size minus one. Reverse the order of the checks, to avoid rx_trig becoming zero if the FIFO size is one. Note that this change has no impact on other SCIF variants, as their maximum supported trigger value is lower than the FIFO size anyway, and the code below takes care of enforcing these limits. Fixes: a380ed4 ("serial: sh-sci: implement FIFO threshold register setting") Reported-by: Linh Phung <[email protected]> Reviewed-by: Wolfram Sang <[email protected]> Reviewed-by: Ulrich Hecht <[email protected]> Signed-off-by: Geert Uytterhoeven <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/5eff320aef92ffb33d00e57979fd3603bbb4a70f.1620648218.git.geert+renesas@glider.be Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5e722b2 commit 2ea2e01

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/tty/serial/sh-sci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,10 @@ static int scif_set_rtrg(struct uart_port *port, int rx_trig)
10231023
{
10241024
unsigned int bits;
10251025

1026+
if (rx_trig >= port->fifosize)
1027+
rx_trig = port->fifosize - 1;
10261028
if (rx_trig < 1)
10271029
rx_trig = 1;
1028-
if (rx_trig >= port->fifosize)
1029-
rx_trig = port->fifosize;
10301030

10311031
/* HSCIF can be set to an arbitrary level. */
10321032
if (sci_getreg(port, HSRTRGR)->size) {

0 commit comments

Comments
 (0)