Skip to content

Commit 0b0dfab

Browse files
authored
Fix race in log_printf (#5523)
Fixes: #5513 Can still race if Serial.begin() is not called in setup()
1 parent 5fd7379 commit 0b0dfab

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cores/esp32/esp32-hal-uart.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -648,17 +648,19 @@ int log_printf(const char *format, ...)
648648
return 0;
649649
}
650650
}
651-
vsnprintf(temp, len+1, format, arg);
652651
#if !CONFIG_DISABLE_HAL_LOCKS
653652
if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
654653
xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY);
655-
ets_printf("%s", temp);
656-
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
657-
} else {
658-
ets_printf("%s", temp);
659654
}
660-
#else
655+
#endif
656+
657+
vsnprintf(temp, len+1, format, arg);
661658
ets_printf("%s", temp);
659+
660+
#if !CONFIG_DISABLE_HAL_LOCKS
661+
if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
662+
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
663+
}
662664
#endif
663665
va_end(arg);
664666
if(len >= sizeof(loc_buf)){

0 commit comments

Comments
 (0)