From 16d7351cbc564f17560bd5c5e06b2665b6d45b8d Mon Sep 17 00:00:00 2001 From: Abhinav Kudnar Date: Fri, 21 Jun 2024 17:41:30 +0530 Subject: [PATCH] fix(nimble): Nimble Error logs in case of memory overflow/failure --- components/bt/host/nimble/nimble | 2 +- components/bt/porting/mem/bt_osi_mem.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index ca6c6173fc..da900069fb 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit ca6c6173fca923cfa1966891fc6623fd9f9cb323 +Subproject commit da900069fb087c5f4e2da54a39490e3c4a59d159 diff --git a/components/bt/porting/mem/bt_osi_mem.c b/components/bt/porting/mem/bt_osi_mem.c index 69c656dd6a..b5173fba79 100644 --- a/components/bt/porting/mem/bt_osi_mem.c +++ b/components/bt/porting/mem/bt_osi_mem.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,18 +7,26 @@ #include "esp_attr.h" #include "esp_heap_caps.h" #include "sdkconfig.h" +#include "esp_log.h" +#include IRAM_ATTR void *bt_osi_mem_malloc(size_t size) { + void *mem = NULL; #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL - return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + mem = heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL - return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); + mem = heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT - return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + mem = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #else - return malloc(size); + mem = malloc(size); #endif + if(!mem){ + ESP_LOGI("ESP_LOG_INFO","malloc failed (size %zu)",size); + assert(mem != NULL); + } + return mem; } IRAM_ATTR void *bt_osi_mem_calloc(size_t n, size_t size)