mirror of
https://github.com/apache/nuttx.git
synced 2026-10-11 16:20:21 +00:00
arch/arm/gd32f4: fix NULL pointer dereference in arm_earlyserialinit.
Add NULL check for g_uart_devs[i] before accessing ->priv in arm_earlyserialinit() loop. When a USART is not enabled in defconfig, g_uart_devs[i] is NULL, causing a HardFault crash during early boot. The bug occurs because the original code only checked g_uart_devs[i]->priv without first verifying g_uart_devs[i] is not NULL. On Cortex-M4, NULL pointer dereference reads from Flash vector table (0x00000000 maps to 0x08000000), returning a function pointer that causes BusFault when written to. This fix matches the existing NULL check pattern used in arm_serialinit() at line 2835 of the same file. Tested on mplant-gd32f450 board with only USART5 enabled in defconfig. Before fix: HardFault at boot (IPSR=3, PC=0x080003e0) After fix: System boots normally to NSH Shell Signed-off-by: lccosy <1191294205@qq.com>
This commit is contained in:
parent
53513986cf
commit
186d1ca80f
1 changed files with 1 additions and 1 deletions
|
|
@ -2763,7 +2763,7 @@ void arm_earlyserialinit(void)
|
|||
|
||||
for (i = 0; i < GD32_NUSART; i++)
|
||||
{
|
||||
if (g_uart_devs[i]->priv)
|
||||
if (g_uart_devs[i] && g_uart_devs[i]->priv)
|
||||
{
|
||||
up_disableusartint(g_uart_devs[i]->priv, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue