From cbfda0e23bd50fc0e062843dd2cd07def698811c Mon Sep 17 00:00:00 2001 From: Rami Elkhatib Date: Wed, 11 May 2022 17:27:29 -0400 Subject: [PATCH] MPS2 CM3DS ethernet fix heap bug The function SMSC9220_EMAC::low_level_input should create a heap for the packet equal to the size of the message (most of which are couple hundred bytes). The current code uses maximum frame size (1522 bytes) for each packet. This will cause the heap to quickly fill up. In fact, the default memory size (lwip.mem-size) used for this heap is 1600 bytes. This means that once you have one other packet allocated (extremely common), the heap allocation will always fails. Also, it is recommend to increase the default lwip.mem-size because that amount is very small especially if you send or receive a few large packets in the network. This is NOT done in current commit. --- .../emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp b/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp index 0e33d285b1..87356a3212 100644 --- a/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp +++ b/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp @@ -89,7 +89,7 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input() message_length -= CRC_LENGTH_BYTES; } - p = _memory_manager->alloc_heap(SMSC9220_ETH_MAX_FRAME_SIZE, + p = _memory_manager->alloc_heap(message_length, SMSC9220_BUFF_ALIGNMENT); if (p != NULL) {