linux-stable/drivers/tty/serial
Douglas Anderson ed56f3cfbe Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()"
commit 3d9319c27c upstream.

This reverts commit 5c7e105cd1.

As identified by KASAN, the simplification done by the cleanup patch
was not legal.

>From tracing through the code, it can be seen that we're transmitting
from a 4096-byte circular buffer. We copy anywhere from 1-4 bytes from
it each time. The simplification runs into trouble when we get near
the end of the circular buffer. For instance, we might start out with
xmit->tail = 4094 and we want to transfer 4 bytes. With the code
before simplification this was no problem. We'd read buf[4094],
buf[4095], buf[0], and buf[1]. With the new code we'll do a
memcpy(&buf[4094], 4) which reads 2 bytes past the end of the buffer
and then skips transmitting what's at buf[0] and buf[1].

KASAN isn't 100% consistent at reporting this for me, but to be extra
confident in the analysis, I added traces of the tail and tx_bytes and
then wrote a test program:

  while true; do
    echo -n "abcdefghijklmnopqrstuvwxyz0" > /dev/ttyMSM0
    sleep .1
  done

I watched the traces over SSH and saw:
  qcom_geni_serial_send_chunk_fifo: 4093 4
  qcom_geni_serial_send_chunk_fifo: 1 3

Which indicated that one byte should be missing. Sure enough the
output that should have been:

  abcdefghijklmnopqrstuvwxyz0

In one case was actually missing a byte:

  abcdefghijklmnopqrstuvwyz0

Running "ls -al" on large directories also made the missing bytes
obvious since columns didn't line up.

While the original code may not be the most elegant, we only talking
about copying up to 4 bytes here. Let's just go back to the code that
worked.

Fixes: 5c7e105cd1 ("tty: serial: simplify qcom_geni_serial_send_chunk_fifo()")
Cc: stable <stable@kernel.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20240304174952.1.I920a314049b345efd1f69d708e7f74d2213d0b49@changeid
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-03 15:28:43 +02:00
..
8250 serial: Lock console when calling into driver before registration 2024-04-03 15:28:26 +02:00
jsm drivers: serial: jsm: fix some leaks in probe 2022-09-22 16:11:43 +02:00
21285.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
altera_jtaguart.c serial: altera_jtaguart: switch status to u32 2023-07-31 17:16:05 +02:00
altera_uart.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
amba-pl010.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
amba-pl011.c serial: amba-pl011: Fix DMA transmission in RS485 mode 2024-03-01 13:35:02 +01:00
apbuart.c serial: apbuart: fix console prompt on qemu 2024-01-25 15:35:55 -08:00
apbuart.h
ar933x_uart.c serial: ar933x: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:25:52 +02:00
arc_uart.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
atmel_serial.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
atmel_serial.h tty: serial: atmel: Use FIELD_PREP/FIELD_GET 2022-09-22 16:32:25 +02:00
bcm63xx_uart.c serial: bcm63xx-uart: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:25:52 +02:00
clps711x.c serial: clps711x: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:25:52 +02:00
cpm_uart.c serial: cpm_uart: Remove cpm_uart/ subdirectory 2023-08-04 15:08:30 +02:00
cpm_uart.h serial: cpm_uart: Remove cpm_uart/ subdirectory 2023-08-04 15:08:30 +02:00
digicolor-usart.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
dz.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
dz.h
earlycon-riscv-sbi.c
earlycon-semihost.c serial: Rename earlycon semihost driver 2023-01-19 14:58:19 +01:00
earlycon.c earlycon: Let users set the clock frequency 2023-01-19 14:56:44 +01:00
fsl_linflexuart.c serial: linflexuart: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:25:52 +02:00
fsl_lpuart.c tty: serial: fsl_lpuart: avoid idle preamble pending if CTS is enabled 2024-04-03 15:28:43 +02:00
icom.c
imx.c tty: serial: imx: Fix broken RS485 2024-04-03 15:28:42 +02:00
imx_earlycon.c
ip22zilog.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
ip22zilog.h
Kconfig TTY/Serial driver updates for 6.5-rc1. 2023-07-03 13:14:58 -07:00
kgdb_nmi.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
kgdboc.c tty: serial: kgdboc: fix mutex locking order for configure_kgdboc() 2023-01-16 16:44:53 +01:00
lantiq.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
liteuart.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
lpc32xx_hs.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
ma35d1_serial.c serial: ma35d1: Validate console index before assignment 2023-12-13 18:45:31 +01:00
Makefile serial: cpm_uart: Remove cpm_uart/ subdirectory 2023-08-04 15:08:30 +02:00
max310x.c serial: max310x: fix NULL pointer dereference in I2C instantiation 2024-04-03 15:28:16 +02:00
max3100.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
mcf.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
men_z135_uart.c serial: men_z135_uart: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
meson_uart.c tty: serial: meson: fix hard LOCKUP on crtscts mode 2023-11-28 17:19:57 +00:00
milbeaut_usio.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
mpc52xx_uart.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
mps2-uart.c serial: mps2-uart: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:26:06 +02:00
msm_serial.c serial: msm: add lock annotation to msm_set_baud_rate() 2023-01-19 15:53:09 +01:00
mux.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
mvebu-uart.c serial: mvebu-uart: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:26:07 +02:00
mxs-auart.c serial: mxs-auart: fix tx 2024-02-23 09:25:10 +01:00
omap-serial.c serial: omap: do not override settings for RS485 support 2024-01-25 15:35:44 -08:00
owl-uart.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
pch_uart.c tty: pcn_uart: fix memory leak with using debugfs_lookup() 2023-02-08 13:09:55 +01:00
pic32_uart.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
pmac_zilog.c serial: pmac_zilog: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
pmac_zilog.h
pxa.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
qcom_geni_serial.c Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()" 2024-04-03 15:28:43 +02:00
rda-uart.c serial: rda: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
rp2.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
sa1100.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
samsung_tty.c tty: serial: samsung: fix tx_empty() to return TIOCSER_TEMT 2024-03-26 18:20:05 -04:00
sb1250-duart.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
sc16is7xx.c serial: sc16is7xx: fix unconditional activation of THRI interrupt 2024-01-31 16:19:10 -08:00
sccnxp.c serial: sccnxp: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:26:07 +02:00
serial-tegra.c serial: tegra: handle clk prepare error in tegra_uart_hw_init() 2023-08-22 15:29:18 +02:00
serial_base.h serial: core: Fix serial core port id, including multiport devices 2023-08-11 21:19:22 +02:00
serial_base_bus.c serial: core: Fix serial core port id, including multiport devices 2023-08-11 21:19:22 +02:00
serial_core.c serial: Lock console when calling into driver before registration 2024-04-03 15:28:26 +02:00
serial_ctrl.c serial: core: Start managing serial controllers to enable runtime PM 2023-05-31 10:46:59 +01:00
serial_mctrl_gpio.c
serial_mctrl_gpio.h
serial_port.c serial: port: Don't suspend if the port is still busy 2024-04-03 15:28:43 +02:00
serial_txx9.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
sh-sci.c Merge 6.5-rc4 into tty-next 2023-07-31 09:39:56 +02:00
sh-sci.h tty: serial: sh-sci: Add support for tx end interrupt handling 2023-04-20 13:47:33 +02:00
sifive.c serial: sifive: Add suspend and resume operations 2023-08-22 15:29:10 +02:00
sprd_serial.c serial: sprd: Fix DMA buffer leak issue 2023-07-30 13:53:55 +02:00
st-asc.c drivers:tty: fix return value check in asc_init_port 2023-07-30 13:53:19 +02:00
stm32-usart.c serial: stm32: do not always set SER_RS485_RX_DURING_TX if RS485 is enabled 2024-03-01 13:35:02 +01:00
stm32-usart.h serial: stm32: group dma pause/resume error handling into single function 2023-08-22 15:28:51 +02:00
suncore.c
sunhv.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
sunplus-uart.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
sunsab.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
sunsab.h
sunsu.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
sunzilog.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
sunzilog.h
tegra-tcu.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
timbuart.c serial: timbuart: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
timbuart.h
uartlite.c tty: Explicitly include correct DT includes 2023-07-25 20:19:05 +02:00
ucc_uart.c serial: cpm_uart: Don't include fs_uart_pd.h when not needed 2023-08-04 15:08:55 +02:00
vt8500_serial.c serial: vt8500: Use devm_platform_get_and_ioremap_resource() 2023-07-25 20:26:06 +02:00
xilinx_uartps.c tty: serial: xilinx_uartps: Do not check for 0 return after calling platform_get_irq() 2023-08-04 15:06:01 +02:00
zs.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
zs.h