fix(i2c): Add bus handle check so that it will not be panic when there is no free bus,

Closes https://github.com/espressif/esp-idf/issues/14819
This commit is contained in:
C.S.M
2024-11-06 13:52:45 +08:00
parent 4c6cda734d
commit 0a098f49d4

View File

@@ -784,8 +784,12 @@ static esp_err_t i2c_master_bus_destroy(i2c_master_bus_handle_t bus_handle)
{
ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "no memory for i2c master bus");
i2c_master_bus_handle_t i2c_master = bus_handle;
i2c_common_deinit_pins(i2c_master->base);
if (i2c_release_bus_handle(i2c_master->base) == ESP_OK) {
esp_err_t err = ESP_OK;
if (i2c_master->base) {
i2c_common_deinit_pins(i2c_master->base);
err = i2c_release_bus_handle(i2c_master->base);
}
if (err == ESP_OK) {
if (i2c_master) {
if (i2c_master->bus_lock_mux) {
vSemaphoreDeleteWithCaps(i2c_master->bus_lock_mux);