walnux/include/nuttx/serial
Kerogit a3f8b55143 drivers/serial/serial: prevent race conditions on 8-bit architectures
Some code paths in drivers/serial/serial.c load head and tail values
of receive and transmit circular buffers with interrupts enabled,
making it possible that the interrupt handler changes the value.
As noted in the code, this is safe as long as the load itself is atomic.

That is not true for 8bit architectures which fetch the 16-bit values
using two load instructions. If interrupt handler runs between those
two instructions and changes the value, the read returns corrupted data.

This patch introduces CONFIG_ARCH_LDST_16BIT_NOT_ATOMIC configuration
option which is automatically selected for AVR architecture. Based
on this option, head and tail values are reduced to 8-bit length
so the read remains atomic.

Patch was tested by building on rv-virt:nsh - disassembly of functions
from serial.c showed no difference which is correct as Risc-V does
not need to protect reads of these values. There should be no impact
for architectures that do not set the new configuration option.

It was also tested by by custom echo application running on AVR128DA28.

Signed-off-by: Kerogit <kr.git@kerogit.eu>
2025-06-19 10:01:24 -03:00
..
mxser.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
pty.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
serial.h drivers/serial/serial: prevent race conditions on 8-bit architectures 2025-06-19 10:01:24 -03:00
tioctl.h serial: remove 'TIOCSLINID' 2024-10-17 09:08:58 +08:00
uart_16550.h style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
uart_bth4.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
uart_bth5.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
uart_cmsdk.h style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
uart_hostfs.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
uart_pci_16550.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
uart_pl011.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
uart_ram.h arch_atomic: only support atomic_xx and atomic64_xx function 2024-12-04 14:03:14 +01:00
uart_rpmsg.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00