Просмотр исходного кода

Merge branch 'bugfix/spi_free_crash_uninitialized' into 'master'

spi: fixed crash when calling spi_bus_free when not initialized

Closes IDFGH-7024

See merge request espressif/esp-idf!17573
Michael (XIAO Xufeng) 3 лет назад
Родитель
Сommit
80904a5815
2 измененных файлов с 5 добавлено и 1 удалено
  1. 1 1
      components/driver/include/driver/spi_common.h
  2. 4 0
      components/driver/spi_common.c

+ 1 - 1
components/driver/include/driver/spi_common.h

@@ -159,7 +159,7 @@ esp_err_t spi_bus_initialize(spi_host_device_t host_id, const spi_bus_config_t *
  * @param host_id SPI peripheral to free
  * @return
  *         - ESP_ERR_INVALID_ARG   if parameter is invalid
- *         - ESP_ERR_INVALID_STATE if not all devices on the bus are freed
+ *         - ESP_ERR_INVALID_STATE if bus hasn't been initialized before, or not all devices on the bus are freed
  *         - ESP_OK                on success
  */
 esp_err_t spi_bus_free(spi_host_device_t host_id);

+ 4 - 0
components/driver/spi_common.c

@@ -864,6 +864,10 @@ const spi_bus_attr_t* spi_bus_get_attr(spi_host_device_t host_id)
 
 esp_err_t spi_bus_free(spi_host_device_t host_id)
 {
+    if (bus_ctx[host_id] == NULL) {
+        return ESP_ERR_INVALID_STATE;
+    }
+
     esp_err_t err = ESP_OK;
     spicommon_bus_context_t* ctx = bus_ctx[host_id];
     spi_bus_attr_t* bus_attr = &ctx->bus_attr;