From 372f13ccced85d42fdf8d2d4d723922c407516be Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 4 Oct 2026 18:50:42 -0500 Subject: [PATCH] [libretiny] Trim the LN882x zero-size allocation comments --- esphome/components/libretiny/__init__.py | 4 +--- .../components/libretiny/ln882x_zero_malloc.c | 18 +++++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/esphome/components/libretiny/__init__.py b/esphome/components/libretiny/__init__.py index b6c41e9e5c9..5d87dee07a3 100644 --- a/esphome/components/libretiny/__init__.py +++ b/esphome/components/libretiny/__init__.py @@ -491,9 +491,7 @@ async def component_to_code(config): # Not enabled on RTL87xx/LN882x — costs more heap than it saves there. cg.add_build_flag("-DconfigSUPPORT_STATIC_ALLOCATION=1") - # LN882x: route FreeRTOS allocations through ln882x_zero_malloc.c, which - # turns a zero-size request into one byte so it cannot trip the SDK's - # malloc-failed hook (an LN_ASSERT spin until the watchdog resets). + # LN882x: a zero-size allocation must not trip the SDK's assert (see ln882x_zero_malloc.c). if config[CONF_COMPONENT_ID] == COMPONENT_LN882X: cg.add_build_flag("-Wl,--wrap=pvPortMalloc") diff --git a/esphome/components/libretiny/ln882x_zero_malloc.c b/esphome/components/libretiny/ln882x_zero_malloc.c index 9e6a1b00902..77e30b3a7dd 100644 --- a/esphome/components/libretiny/ln882x_zero_malloc.c +++ b/esphome/components/libretiny/ln882x_zero_malloc.c @@ -1,17 +1,9 @@ /* - * LN882x: never ask the FreeRTOS heap for zero bytes. - * - * The LN882H SDK builds FreeRTOS with configUSE_MALLOC_FAILED_HOOK, and its - * hook (components/kernel/FreeRTOS/hooks.c) ends in LN_ASSERT(0), which spins - * until the watchdog resets the chip. heap_5 returns NULL for a zero-size - * request, so a harmless malloc(0) runs that hook. LibreTiny's scan handler - * makes exactly that request when a scan finds no networks, which is what - * happens right after an access point drops the device: the chip hangs and - * resets about ten seconds later. - * - * Linked with -Wl,--wrap=pvPortMalloc for LN882x only, so every caller, - * LibreTiny's malloc wrappers included, goes through here. Drop this once - * LibreTiny stops allocating zero entries in its LN882H scan handler. + * LN882x: heap_5 returns NULL for a zero-size request, and the SDK's + * malloc-failed hook ends in LN_ASSERT(0), which spins until the watchdog + * resets the chip. LibreTiny's scan handler asks for zero entries when a scan + * finds no networks. Linked with -Wl,--wrap=pvPortMalloc so every allocation + * comes through here; drop it once LibreTiny no longer allocates zero entries. */ #ifdef USE_LN882X