From 4c2ff6dc2fe3a7800e5f48e3e87a4223b9df77fc Mon Sep 17 00:00:00 2001 From: Andriy Gelman Date: Sun, 15 May 2022 14:34:59 -0400 Subject: [PATCH] drivers: uart_xmc4xxx: Don't recast to uint16_t* when returning value Casting to uint16_t* can cause an unaligned usage fault when c is not aligned to 2 bytes and can unintentionally overwrite data when c has a 1 byte memory size. Also there's no need to cast to uint16_t* because returned words are 8-bit characaters as setup in the configuration. Fixes the following usage fault error in tests/drivers/uart/uart_basic_api: START - test_uart_poll_in Please send characters to serial console E: ***** USAGE FAULT ***** E: Unaligned memory access E: r0/a1: 0x00000000 r1/a2: 0x2000078f r2/a3: 0x0c00453c E: r3/a4: 0x00000000 r12/ip: 0x00000000 r14/lr: 0x0c003de5 E: xpsr: 0x41000000 E: Faulting instruction address (r15/pc): 0x0c003de4 E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0 E: Current thread: 0x20000118 (unknown) E: Halting system Signed-off-by: Andriy Gelman --- drivers/serial/uart_xmc4xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/uart_xmc4xxx.c b/drivers/serial/uart_xmc4xxx.c index 51690fe6494..22efc67ac61 100644 --- a/drivers/serial/uart_xmc4xxx.c +++ b/drivers/serial/uart_xmc4xxx.c @@ -23,7 +23,7 @@ static int uart_xmc4xxx_poll_in(const struct device *dev, unsigned char *c) { const struct uart_xmc4xx_config *config = dev->config; - *(uint16_t *)c = XMC_UART_CH_GetReceivedData(config->uart); + *c = (unsigned char)XMC_UART_CH_GetReceivedData(config->uart); return 0; }