Improved emac rx task code to suppress Coverity false positive memory leak indication

This commit is contained in:
Ondrej 2022-11-24 12:37:09 +00:00
parent df76911671
commit 49f673c52d
4 changed files with 71 additions and 79 deletions

View File

@ -820,8 +820,6 @@ static void emac_dm9051_task(void *arg)
uint32_t frame_len = ETH_MAX_PACKET_SIZE;
uint8_t *buffer;
dm9051_alloc_recv_buf(emac, &buffer, &frame_len);
/* there is a waiting frame */
if (frame_len) {
/* we have memory to receive the frame of maximal size previously defined */
if (buffer != NULL) {
uint32_t buf_len = DM9051_ETH_MAC_RX_BUF_SIZE_AUTO;
@ -842,11 +840,11 @@ static void emac_dm9051_task(void *arg)
dm9051_flush_recv_frame(emac);
free(buffer);
}
} else {
/* if allocation failed and there is a waiting frame */
} else if (frame_len) {
ESP_LOGE(TAG, "no mem for receive buffer");
dm9051_flush_recv_frame(emac);
}
}
} while (emac->packets_remain);
}
}

View File

@ -282,8 +282,6 @@ static void emac_esp32_rx_task(void *arg)
/* set max expected frame len */
uint32_t frame_len = ETH_MAX_PACKET_SIZE;
buffer = emac_hal_alloc_recv_buf(&emac->hal, &frame_len);
/* there is a waiting frame */
if (frame_len) {
/* we have memory to receive the frame of maximal size previously defined */
if (buffer != NULL) {
uint32_t recv_len = emac_hal_receive_frame(&emac->hal, buffer, EMAC_HAL_BUF_SIZE_AUTO, &emac->frames_remain, &emac->free_rx_descriptor);
@ -299,12 +297,12 @@ static void emac_esp32_rx_task(void *arg)
ESP_LOGD(TAG, "receive len= %d", recv_len);
emac->eth->stack_input(emac->eth, buffer, recv_len);
}
} else {
/* if allocation failed and there is a waiting frame */
} else if (frame_len) {
ESP_LOGE(TAG, "no mem for receive buffer");
/* ensure that interface to EMAC does not get stuck with unprocessed frames */
emac_hal_flush_recv_frame(&emac->hal, &emac->frames_remain, &emac->free_rx_descriptor);
}
}
#if CONFIG_ETH_SOFT_FLOW_CONTROL
// we need to do extra checking of remained frames in case there are no unhandled frames left, but pause frame is still undergoing
if ((emac->free_rx_descriptor < emac->flow_control_low_water_mark) && emac->do_flow_ctrl && emac->frames_remain) {

View File

@ -692,8 +692,6 @@ static void emac_ksz8851snl_task(void *arg)
uint32_t frame_len = ETH_MAX_PACKET_SIZE;
uint8_t *buffer;
emac_ksz8851_alloc_recv_buf(emac, &buffer, &frame_len);
/* there is a waiting frame */
if (frame_len) {
/* we have memory to receive the frame of maximal size previously defined */
if (buffer != NULL) {
uint32_t buf_len = KSZ8851_ETH_MAC_RX_BUF_SIZE_AUTO;
@ -714,12 +712,12 @@ static void emac_ksz8851snl_task(void *arg)
emac_ksz8851_flush_recv_queue(emac);
free(buffer);
}
} else {
/* if allocation failed and there is a waiting frame */
} else if (frame_len) {
ESP_LOGE(TAG, "no mem for receive buffer");
emac_ksz8851_flush_recv_queue(emac);
}
}
}
ksz8851_write_reg(emac, KSZ8851_IER, ier);
}
}

View File

@ -656,8 +656,6 @@ static void emac_w5500_task(void *arg)
/* define max expected frame len */
frame_len = ETH_MAX_PACKET_SIZE;
emac_w5500_alloc_recv_buf(emac, &buffer, &frame_len);
/* there is a waiting frame */
if (frame_len) {
/* we have memory to receive the frame of maximal size previously defined */
if (buffer != NULL) {
buf_len = W5500_ETH_MAC_RX_BUF_SIZE_AUTO;
@ -676,11 +674,11 @@ static void emac_w5500_task(void *arg)
ESP_LOGE(TAG, "frame read from module failed");
free(buffer);
}
} else {
/* if allocation failed and there is a waiting frame */
} else if (frame_len) {
ESP_LOGE(TAG, "no mem for receive buffer");
emac_w5500_flush_recv_frame(emac);
}
}
} while (emac->packets_remain);
}
}