mirror-linux/drivers/tty/serial
Douglas Anderson 3d9319c27c Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()"
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-03-05 13:40:34 +00:00
..
8250 serial: 8250_dw: Do not reclock if already at correct rate 2024-03-02 22:11:03 +01:00
jsm tty: jsm: remove unused struct jsm_board members 2023-11-23 19:16:03 +00:00
21285.c serial: 21285: Use port lock wrappers 2023-09-18 11:18:08 +02:00
Kconfig RISC-V Patches for the 6.8 Merge Window, Part 4 2024-01-20 11:06:04 -08:00
Makefile drivers/tty/serial: add ESP32S3 ACM gadget driver 2023-10-16 20:18:15 +02:00
altera_jtaguart.c serial: altera_jtaguart: Convert to platform remove callback returning void 2023-11-23 19:12:30 +00:00
altera_uart.c tty/serial: altera_uart: use more informative labels in /proc/interrupts 2024-01-04 16:20:51 +01:00
amba-pl010.c serial: amba-pl010: Use port lock wrappers 2023-09-18 11:18:09 +02:00
amba-pl011.c serial: amba-pl011: Fix DMA transmission in RS485 mode 2024-02-19 09:43:37 +01:00
apbuart.c serial: apbuart: fix console prompt on qemu 2024-01-04 16:21:06 +01:00
apbuart.h
ar933x_uart.c serial: ar933x: Convert to platform remove callback returning void 2023-11-23 19:12:30 +00:00
arc_uart.c serial: arc_uart: Use port lock wrappers 2023-09-18 11:18:10 +02:00
atmel_serial.c serial: atmel: convert not to use dma_request_slave_channel() 2023-11-23 19:32:36 +00:00
atmel_serial.h
bcm63xx_uart.c serial: bcm63xx: Convert to platform remove callback returning void 2023-11-23 19:12:30 +00:00
clps711x.c serial: clps711x: Convert to platform remove callback returning void 2023-11-23 19:12:31 +00:00
cpm_uart.c serial: cpm: Convert to platform remove callback returning void 2023-11-23 19:12:31 +00:00
cpm_uart.h serial: cpm_uart: Remove cpm_uart/ subdirectory 2023-08-04 15:08:30 +02:00
digicolor-usart.c serial: digicolor: Convert to platform remove callback returning void 2023-11-23 19:12:31 +00:00
dz.c serial: dz: Use port lock wrappers 2023-09-18 11:18:11 +02:00
dz.h
earlycon-riscv-sbi.c tty/serial: Add RISC-V SBI debug console based earlycon 2024-01-10 07:04:04 -08:00
earlycon-semihost.c
earlycon.c
esp32_acm.c serial: esp32_acm: Add explicit platform_device.h include 2023-12-15 14:20:00 +01:00
esp32_uart.c serial: esp32_uart: Use device_get_match_data() 2023-12-15 14:20:00 +01:00
fsl_linflexuart.c serial: fsl_linflexuart: Convert to platform remove callback returning void 2023-11-23 19:12:31 +00:00
fsl_lpuart.c tty: serial: fsl_lpuart: avoid idle preamble pending if CTS is enabled 2024-03-05 13:40:07 +00:00
icom.c serial: icom: Use port lock wrappers 2023-09-18 11:18:11 +02:00
imx.c tty: serial: imx: Fix broken RS485 2024-03-02 22:10:35 +01:00
imx_earlycon.c
ip22zilog.c serial: ip22zilog: Use port lock wrappers 2023-09-18 11:18:11 +02:00
ip22zilog.h
kgdb_nmi.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
kgdboc.c
lantiq.c serial: lantiq: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
liteuart.c serial: liteuart: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
lpc32xx_hs.c serial: lpc32xx_hs: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
ma35d1_serial.c serial: ma35d1: Fix spelling mistake "ononsole" -> "console" 2023-12-15 14:23:30 +01:00
max310x.c serial: max310x: prevent infinite while() loop in port startup 2024-01-27 19:09:10 -08:00
max3100.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
mcf.c serial: mcf: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
men_z135_uart.c serial: men_z135_uart: Use port lock wrappers 2023-09-18 11:18:12 +02:00
meson_uart.c serial: meson: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
milbeaut_usio.c serial: milbeaut_usio: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
mpc52xx_uart.c serial: mpc52xx: Convert to platform remove callback returning void 2023-11-23 19:12:32 +00:00
mps2-uart.c serial: mps2-uart: Use port lock wrappers 2023-09-18 11:18:12 +02:00
msm_serial.c serial: msm: Use OPP table for DVFS support 2023-12-08 12:02:37 +01:00
mux.c
mvebu-uart.c serial: mvebu-uart: Use port lock wrappers 2023-09-18 11:18:12 +02:00
mxs-auart.c serial: mxs-auart: fix tx 2024-02-06 14:42:11 +00:00
omap-serial.c serial: omap: do not override settings for RS485 support 2024-01-04 16:29:51 +01:00
owl-uart.c serial: owl: Convert to platform remove callback returning void 2023-11-23 19:12:33 +00:00
pch_uart.c serial: pch: Use port lock wrappers 2023-09-18 11:18:13 +02:00
pic32_uart.c serial: pic32: Convert to platform remove callback returning void 2023-11-23 19:12:33 +00:00
pmac_zilog.c serial: pmac_zilog: Use port lock wrappers 2023-09-18 11:18:13 +02:00
pmac_zilog.h
pxa.c serial: pxa: Use port lock wrappers 2023-09-18 11:18:13 +02:00
qcom_geni_serial.c Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()" 2024-03-05 13:40:34 +00:00
rda-uart.c serial: rda: Convert to platform remove callback returning void 2023-11-23 19:12:33 +00:00
rp2.c tty: rp2: remove unused rp2_uart_port::ignore_rx 2023-11-23 19:16:03 +00:00
sa1100.c serial: sa1100: Convert to platform remove callback returning void 2023-11-23 19:12:33 +00:00
samsung_tty.c TTY/Serial changes for 6.8-rc1 2024-01-18 11:37:24 -08:00
sb1250-duart.c serial: sb1250-duart: Use port lock wrappers 2023-09-18 11:18:14 +02:00
sc16is7xx.c serial: sc16is7xx: refactor EFR lock 2024-01-04 16:30:05 +01:00
sccnxp.c serial: sccnxp: Convert to platform remove callback returning void 2023-11-23 19:12:34 +00:00
serial-tegra.c serial: tegra: Convert to platform remove callback returning void 2023-11-23 19:12:34 +00: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: core: Fix atomicity violation in uart_tiocmget 2024-01-27 19:08:30 -08:00
serial_ctrl.c
serial_mctrl_gpio.c serial: mctrl_gpio: Use port lock wrappers 2023-09-18 11:18:14 +02:00
serial_mctrl_gpio.h
serial_port.c serial: port: Don't suspend if the port is still busy 2024-03-02 22:11:58 +01:00
serial_txx9.c serial: txx9: Convert to platform remove callback returning void 2023-11-23 19:12:34 +00:00
sh-sci.c serial: sh-sci: convert not to use dma_request_slave_channel() 2023-11-23 19:33:03 +00:00
sh-sci.h
sifive.c serial: sifive: Declare PM operations as static 2023-11-23 19:31:18 +00:00
sprd_serial.c serial: sprd: Convert to platform remove callback returning void 2023-11-23 19:12:34 +00:00
st-asc.c serial: st-asc: Convert to platform remove callback returning void 2023-11-23 19:12:34 +00:00
stm32-usart.c serial: stm32: do not always set SER_RS485_RX_DURING_TX if RS485 is enabled 2024-02-19 09:43:37 +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 serial: sunhv: Convert to platform remove callback returning void 2023-11-23 19:12:35 +00:00
sunplus-uart.c serial: sunplus: Convert to platform remove callback returning void 2023-11-23 19:12:35 +00:00
sunsab.c serial: sunsab: remove trailing whitespaces 2023-11-23 19:31:25 +00:00
sunsab.h
sunsu.c serial: sunsu: Convert to platform remove callback returning void 2023-11-23 19:12:35 +00:00
sunzilog.c serial: sunzilog: Convert to platform remove callback returning void 2023-11-23 19:12:35 +00:00
sunzilog.h
tegra-tcu.c serial: tegra-tcu: Convert to platform remove callback returning void 2023-11-23 19:12:35 +00:00
timbuart.c serial: timbuart: Convert to platform remove callback returning void 2023-11-23 19:12:35 +00:00
timbuart.h
uartlite.c serial: uartlite: Use dynamic allocation for major number when uart ports > 4 2023-11-25 07:23:16 +00:00
ucc_uart.c serial: ucc_uart: Fix multiple address space type errors 2023-12-08 12:02:37 +01:00
vt8500_serial.c serial: vt8500: Use port lock wrappers 2023-09-18 11:18:16 +02:00
xilinx_uartps.c serial: xilinx_uartps: Fix kernel doc about .remove()'s return code 2023-11-25 07:23:16 +00:00
zs.c serial: drivers: switch ch and flag to u8 2023-07-25 19:21:04 +02:00
zs.h