Skip to content

Commit 34e69f5

Browse files
committed
fix unexpected abort
label `cleanup` redirect to adc_continuous_deinit() -> -> adc_apb_periph_free() -- and call unexpected decrement and abort. but the increment of s_adc_digi_ctrlr_cnt was not made. also abort does not allow us to understand what the error was (return is not provided)
1 parent b6e2de0 commit 34e69f5

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

components/esp_adc/adc_continuous.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,32 @@ static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask)
160160
return ret;
161161
}
162162

163+
static void adc_continuous_deinit_light(adc_continuous_handle_t handle)
164+
{
165+
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_STATE, ADC_TAG, "The driver isn't initialised");
166+
ESP_RETURN_ON_FALSE(handle->fsm == ADC_FSM_INIT, ESP_ERR_INVALID_STATE, ADC_TAG, "The driver is still running");
167+
168+
if (handle->ringbuf_hdl) {
169+
vRingbufferDelete(handle->ringbuf_hdl);
170+
handle->ringbuf_hdl = NULL;
171+
free(handle->ringbuf_storage);
172+
free(handle->ringbuf_struct);
173+
}
174+
175+
#if CONFIG_PM_ENABLE
176+
if (handle->pm_lock) {
177+
esp_pm_lock_delete(handle->pm_lock);
178+
}
179+
#endif
180+
181+
free(handle->rx_dma_buf);
182+
free(handle->hal.rx_desc);
183+
free(handle->hal_digi_ctrlr_cfg.adc_pattern);
184+
adc_dma_deinit(handle->adc_dma);
185+
free(handle);
186+
handle = NULL;
187+
}
188+
163189
esp_err_t adc_continuous_new_handle(const adc_continuous_handle_cfg_t *hdl_config, adc_continuous_handle_t *ret_handle)
164190
{
165191
#if CONFIG_ADC_ENABLE_DEBUG_LOG
@@ -250,7 +276,7 @@ esp_err_t adc_continuous_new_handle(const adc_continuous_handle_cfg_t *hdl_confi
250276
return ret;
251277

252278
cleanup:
253-
adc_continuous_deinit(adc_ctx);
279+
adc_continuous_deinit_light(adc_ctx);
254280
return ret;
255281
}
256282

@@ -422,28 +448,7 @@ esp_err_t adc_continuous_read(adc_continuous_handle_t handle, uint8_t *buf, uint
422448

423449
esp_err_t adc_continuous_deinit(adc_continuous_handle_t handle)
424450
{
425-
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_STATE, ADC_TAG, "The driver isn't initialised");
426-
ESP_RETURN_ON_FALSE(handle->fsm == ADC_FSM_INIT, ESP_ERR_INVALID_STATE, ADC_TAG, "The driver is still running");
427-
428-
if (handle->ringbuf_hdl) {
429-
vRingbufferDelete(handle->ringbuf_hdl);
430-
handle->ringbuf_hdl = NULL;
431-
free(handle->ringbuf_storage);
432-
free(handle->ringbuf_struct);
433-
}
434-
435-
#if CONFIG_PM_ENABLE
436-
if (handle->pm_lock) {
437-
esp_pm_lock_delete(handle->pm_lock);
438-
}
439-
#endif
440-
441-
free(handle->rx_dma_buf);
442-
free(handle->hal.rx_desc);
443-
free(handle->hal_digi_ctrlr_cfg.adc_pattern);
444-
adc_dma_deinit(handle->adc_dma);
445-
free(handle);
446-
handle = NULL;
451+
adc_continuous_deinit_light(handle);
447452

448453
adc_apb_periph_free();
449454

0 commit comments

Comments
 (0)