Skip to content

Commit 33f1c3b

Browse files
committed
(tidy)driver_buses: fix unused variable error
Previously, the `cppcheck` tool reported an error in the `start_buses` function of `buses.c` due to the structure of its macro definitions. The goal was to initialize a value to capture the return state when initializing various buses on the host. If a bus (FOO) was exposed through a macro set by Kconfig, an attempt would be made to initialize the FOO bus. If the attempt failed, the `start_buses` function would immediately return the ESP32 error status from FOO. If the attempts succeeded, `start_buses` would return a static definition of "ESP_OK." However, the use of macros by the compiler's preprocessor introduced non-determinism for static analysis tools, leading to ambiguity regarding the use of `res`. This commit slightly changes the behavior by initializing `res` to the desired resulting value, "ESP_OK," and returning `res` instead of "ESP_OK." If any of the buses fail to initialize, the value of `res` will be overwritten, after which the behavior will remain the same.
1 parent 4bf1b7c commit 33f1c3b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

components/buses/buses.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static xSemaphoreHandle i2c1_mux = NULL;
2727

2828
esp_err_t start_buses() {
2929
// This function initializes the VSPI, HSPI and I2C buses of the ESP32
30-
esp_err_t res;
30+
esp_err_t res = ESP_OK;
3131

3232
#ifdef CONFIG_BUS_VSPI_ENABLE
3333
spi_bus_config_t vspiBusConfiguration = {0};
@@ -109,7 +109,7 @@ esp_err_t start_buses() {
109109
if (i2c1_mux == NULL) return ESP_ERR_NO_MEM;
110110
#endif
111111

112-
return ESP_OK;
112+
return res;
113113
}
114114

115115
/* I2C helper functions */

0 commit comments

Comments
 (0)