mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
usb_host: Fix coverity issues with hcd_install()
- Use single "err_ret" variable for returning errors - Simplify bail out procedure by using more labels
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -1000,42 +1000,42 @@ esp_err_t hcd_install(const hcd_config_t *config)
|
|||||||
HCD_EXIT_CRITICAL();
|
HCD_EXIT_CRITICAL();
|
||||||
|
|
||||||
esp_err_t err_ret;
|
esp_err_t err_ret;
|
||||||
// Allocate memory and resources for driver object and all port objects
|
// Allocate memory for the driver object
|
||||||
hcd_obj_t *p_hcd_obj_dmy = calloc(1, sizeof(hcd_obj_t));
|
hcd_obj_t *p_hcd_obj_dmy = calloc(1, sizeof(hcd_obj_t));
|
||||||
if (p_hcd_obj_dmy == NULL) {
|
if (p_hcd_obj_dmy == NULL) {
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
// Allocate each port object (the hardware currently only has one port)
|
||||||
// Allocate resources for each port (there's only one)
|
|
||||||
p_hcd_obj_dmy->port_obj = port_obj_alloc();
|
p_hcd_obj_dmy->port_obj = port_obj_alloc();
|
||||||
esp_err_t intr_alloc_ret = esp_intr_alloc(ETS_USB_INTR_SOURCE,
|
|
||||||
config->intr_flags | ESP_INTR_FLAG_INTRDISABLED, // The interrupt must be disabled until the port is initialized
|
|
||||||
intr_hdlr_main,
|
|
||||||
(void *)p_hcd_obj_dmy->port_obj,
|
|
||||||
&p_hcd_obj_dmy->isr_hdl);
|
|
||||||
if (p_hcd_obj_dmy->port_obj == NULL) {
|
if (p_hcd_obj_dmy->port_obj == NULL) {
|
||||||
err_ret = ESP_ERR_NO_MEM;
|
err_ret = ESP_ERR_NO_MEM;
|
||||||
|
goto port_alloc_err;
|
||||||
}
|
}
|
||||||
if (intr_alloc_ret != ESP_OK) {
|
// Allocate interrupt
|
||||||
err_ret = intr_alloc_ret;
|
err_ret = esp_intr_alloc(ETS_USB_INTR_SOURCE,
|
||||||
goto err;
|
config->intr_flags | ESP_INTR_FLAG_INTRDISABLED, // The interrupt must be disabled until the port is initialized
|
||||||
|
intr_hdlr_main,
|
||||||
|
(void *)p_hcd_obj_dmy->port_obj,
|
||||||
|
&p_hcd_obj_dmy->isr_hdl);
|
||||||
|
if (err_ret != ESP_OK) {
|
||||||
|
goto intr_alloc_err;
|
||||||
}
|
}
|
||||||
|
// Assign the
|
||||||
HCD_ENTER_CRITICAL();
|
HCD_ENTER_CRITICAL();
|
||||||
if (s_hcd_obj != NULL) {
|
if (s_hcd_obj != NULL) {
|
||||||
HCD_EXIT_CRITICAL();
|
HCD_EXIT_CRITICAL();
|
||||||
err_ret = ESP_ERR_INVALID_STATE;
|
err_ret = ESP_ERR_INVALID_STATE;
|
||||||
goto err;
|
goto assign_err;
|
||||||
}
|
}
|
||||||
s_hcd_obj = p_hcd_obj_dmy;
|
s_hcd_obj = p_hcd_obj_dmy;
|
||||||
HCD_EXIT_CRITICAL();
|
HCD_EXIT_CRITICAL();
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
|
||||||
err:
|
assign_err:
|
||||||
if (intr_alloc_ret == ESP_OK) {
|
esp_intr_free(p_hcd_obj_dmy->isr_hdl);
|
||||||
esp_intr_free(p_hcd_obj_dmy->isr_hdl);
|
intr_alloc_err:
|
||||||
}
|
|
||||||
port_obj_free(p_hcd_obj_dmy->port_obj);
|
port_obj_free(p_hcd_obj_dmy->port_obj);
|
||||||
|
port_alloc_err:
|
||||||
free(p_hcd_obj_dmy);
|
free(p_hcd_obj_dmy);
|
||||||
return err_ret;
|
return err_ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user