Skip to content

Commit

Permalink
Fix race in log_printf (#5523)
Browse files Browse the repository at this point in the history
Fixes: #5513

Can still race if Serial.begin() is not called in setup()
  • Loading branch information
me-no-dev committed Aug 11, 2021
1 parent 5fd7379 commit 0b0dfab
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,19 @@ int log_printf(const char *format, ...)
return 0;
}
}
vsnprintf(temp, len+1, format, arg);
#if !CONFIG_DISABLE_HAL_LOCKS
if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY);
ets_printf("%s", temp);
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
} else {
ets_printf("%s", temp);
}
#else
#endif

vsnprintf(temp, len+1, format, arg);
ets_printf("%s", temp);

#if !CONFIG_DISABLE_HAL_LOCKS
if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
}
#endif
va_end(arg);
if(len >= sizeof(loc_buf)){
Expand Down

0 comments on commit 0b0dfab

Please sign in to comment.