fix: fix unused value in esp uart driver

This commit is contained in:
Ashish Sharma
2025-10-27 11:02:48 +08:00
parent c83ea47012
commit 5b8cd3f626
+24 -10
View File
@@ -443,18 +443,32 @@ static esp_err_t unregister_select(uart_select_args_t *args)
for (int i = 0; i < s_registered_select_num; ++i) {
if (s_registered_selects[i] == args) {
const int new_size = s_registered_select_num - 1;
// The item is removed by overwriting it with the last item. The subsequent rellocation will drop the
// last item.
s_registered_selects[i] = s_registered_selects[new_size];
uart_select_args_t **new_selects = heap_caps_realloc(s_registered_selects, new_size * sizeof(uart_select_args_t *), UART_VFS_MALLOC_FLAGS);
if (new_selects == NULL && new_size > 0) {
ret = ESP_ERR_NO_MEM;
// Move last element to fill gap (only if not removing the last element)
if (i < new_size) {
s_registered_selects[i] = s_registered_selects[new_size];
}
if (new_size == 0) {
// Free the entire array
free(s_registered_selects);
s_registered_selects = NULL;
s_registered_select_num = 0;
ret = ESP_OK;
} else {
s_registered_selects = new_selects;
// Shrink the array
uart_select_args_t **new_selects = heap_caps_realloc(s_registered_selects, new_size * sizeof(uart_select_args_t *), UART_VFS_MALLOC_FLAGS);
if (new_selects == NULL) {
// Realloc failed - restore moved element
if (i < new_size) {
s_registered_selects[new_size] = s_registered_selects[i];
}
ret = ESP_ERR_NO_MEM;
} else {
// Success - update pointer
s_registered_selects = new_selects;
s_registered_select_num = new_size;
ret = ESP_OK;
}
}
// Shrinking a buffer with realloc is guaranteed to succeed.
s_registered_select_num = new_size;
ret = ESP_OK;
break;
}
}