[uart] Report no data available while the bus is not ready

A stale peeked byte was still counted by available() while the read
paths refused to deliver it, so a caller looping on available() would
spin forever.
This commit is contained in:
J. Nick Koston
2026-08-16 18:39:23 -05:00
parent 7f9636b7f2
commit d98484c283
@@ -371,7 +371,10 @@ size_t IDFUARTComponent::available() {
if (!this->is_ready()) {
// The driver is not installed yet (or the bus failed); asking the driver
// would fail and mark the whole bus failed, so report no data instead.
return this->has_peek_ ? 1 : 0;
// A stale peeked byte must not be counted either: the read paths refuse
// to deliver it while the bus is not ready, so advertising it would make
// the common `while (available()) read()` pattern spin forever.
return 0;
}
err = uart_get_buffered_data_len(this->uart_num_, &available);