From 30de0c17abe522dbff783c439605fe9985ebf11c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 11 Apr 2026 08:21:11 -1000 Subject: [PATCH] [esphome.ota] Trim verbose comments from simplification --- esphome/components/esphome/ota/__init__.py | 4 +--- esphome/components/esphome/ota/ota_esphome.cpp | 9 ++------- esphome/components/socket/lwip_raw_tcp_impl.cpp | 6 +----- esphome/core/lwip_fast_select.c | 5 +---- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/esphome/components/esphome/ota/__init__.py b/esphome/components/esphome/ota/__init__.py index de2e1e4aad..5d35910fbd 100644 --- a/esphome/components/esphome/ota/__init__.py +++ b/esphome/components/esphome/ota/__init__.py @@ -155,9 +155,7 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_auth_password(config[CONF_PASSWORD])) cg.add_define("USE_OTA_PASSWORD") cg.add_define("USE_OTA_VERSION", config[CONF_VERSION]) - # Build flag (not a define in defines.h) so lwip_fast_select.c — a .c file that - # can't include defines.h — can still gate its wake hook on the esphome OTA - # platform being compiled in. + # Build flag so lwip_fast_select.c (a .c file that can't include defines.h) sees it. cg.add_build_flag("-DUSE_OTA_PLATFORM_ESPHOME") await cg.register_component(var, config) diff --git a/esphome/components/esphome/ota/ota_esphome.cpp b/esphome/components/esphome/ota/ota_esphome.cpp index 39275d5fcd..47f661a8ea 100644 --- a/esphome/components/esphome/ota/ota_esphome.cpp +++ b/esphome/components/esphome/ota/ota_esphome.cpp @@ -31,16 +31,11 @@ static constexpr size_t OTA_BUFFER_SIZE = 1024; // buffer size static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 20000; // milliseconds for initial handshake static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 90000; // milliseconds for data transfer -// File-scope pointer to the single ESPHomeOTAComponent instance. The final_validate in -// __init__.py rejects multi-port configs, so only one exists. Set in setup() and used -// by the extern "C" wake trampoline below, which is called from socket wake paths -// (lwip_fast_select listener filter, raw-TCP accept_fn_). +// Single-instance pointer — multi-port configs are rejected in final_validate. // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static ESPHomeOTAComponent *global_esphome_ota_component = nullptr; -// Trampoline called from C and C++ socket wake paths. Must be safe from any context -// (LwIP TCP/IP task, user-level IRQ on RP2040). enable_loop_soon_any_context() uses -// volatile flags only — no locks, no allocations. +// Called from any context (LwIP TCP/IP task, RP2040 user-IRQ). extern "C" void esphome_wake_ota_component_any_context() { if (global_esphome_ota_component != nullptr) { global_esphome_ota_component->enable_loop_soon_any_context(); diff --git a/esphome/components/socket/lwip_raw_tcp_impl.cpp b/esphome/components/socket/lwip_raw_tcp_impl.cpp index 0022809dc1..c6692b0165 100644 --- a/esphome/components/socket/lwip_raw_tcp_impl.cpp +++ b/esphome/components/socket/lwip_raw_tcp_impl.cpp @@ -12,8 +12,6 @@ #include "esphome/core/log.h" #ifdef USE_OTA_PLATFORM_ESPHOME -// Defined in components/esphome/ota/ota_esphome.cpp. Marks the ESPHome OTA component -// pending-enable from the raw-TCP accept callback (per-pcb, implicitly filtered). extern "C" void esphome_wake_ota_component_any_context(); #endif @@ -861,9 +859,7 @@ err_t LWIPRawListenImpl::accept_fn_(struct tcp_pcb *newpcb, err_t err) { tcp_recv(newpcb, LWIPRawListenImpl::s_queued_recv_fn); LWIP_LOG("Accepted connection, queue size: %d", this->accepted_socket_count_); #ifdef USE_OTA_PLATFORM_ESPHOME - // Mark OTA pending-enable before the wake below — flags must be visible before the - // main task runs. accept_fn_ is per-pcb, so filtering is implicit here (only fires - // for completed handshakes to whichever listener owns newpcb). + // Must run before wake_loop_any_context() so flags are visible when the main task wakes. esphome_wake_ota_component_any_context(); #endif // Wake the main loop immediately so it can accept the new connection. diff --git a/esphome/core/lwip_fast_select.c b/esphome/core/lwip_fast_select.c index e29ea5684f..36000d4e77 100644 --- a/esphome/core/lwip_fast_select.c +++ b/esphome/core/lwip_fast_select.c @@ -158,11 +158,8 @@ _Static_assert(offsetof(struct lwip_sock, rcvevent) == ESPHOME_LWIP_SOCK_RCVEVEN static netconn_callback s_original_callback = NULL; #ifdef USE_OTA_PLATFORM_ESPHOME -// This .c file can't include defines.h — macros.h → Arduino.h would break the C -// compile. esphome/ota/__init__.py emits -DUSE_OTA_PLATFORM_ESPHOME via -// cg.add_build_flag so both this TU and C++ call sites can see the same name. static struct netconn *s_ota_listener_conn = NULL; -extern void esphome_wake_ota_component_any_context(void); // defined in ota_esphome.cpp +extern void esphome_wake_ota_component_any_context(void); void esphome_fast_select_set_ota_listener_sock(struct lwip_sock *sock) { s_ota_listener_conn = (sock != NULL) ? sock->conn : NULL;