fix(esp_hal_gpspi): narrow freq_limit scope to its consumer in spi_hal_cal_clock_conf

freq_limit was declared at the top of the #if SPI_LL_SUPPORT_TIME_TUNING
block and only consumed by HAL_EARLY_LOGE inside an inner if(). When the
log macro expands to nothing (e.g. log component absent from the build
closure, as in g0_components, or log level set below ERROR), the
variable became unused and tripped -Wunused-variable, failing builds
under --check-warnings.

Move the declaration into the inner if() that calls HAL_EARLY_LOGE so
it shares the same scope and lifetime as its consumer.
This commit is contained in:
Sudeep Mohanty
2026-05-21 10:05:48 +02:00
parent c105ea3af8
commit 8e720e36c3
+6 -4
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -50,10 +50,12 @@ esp_err_t spi_hal_cal_clock_conf(const spi_hal_timing_param_t *timing_param, spi
spi_hal_cal_timing(timing_param->clk_src_hz, eff_clk_n, timing_param->use_gpio, timing_param->input_delay_ns, &dummy, &miso_delay);
#if SPI_LL_SUPPORT_TIME_TUNING
const int freq_limit = spi_hal_get_freq_limit(timing_param->use_gpio, timing_param->input_delay_ns);
if (!(timing_param->half_duplex || dummy == 0 || timing_param->no_compensate)) {
// This only a short log used as a "key" of the idf hint system, see `hints.yml`
// Short log used as a "key" by the idf hint system (see `hints.yml`).
// freq_limit is consumed only by HAL_EARLY_LOGE; mark unused so
// -Wunused-variable stays quiet when the macro expands to empty.
const int freq_limit __attribute__((unused)) =
spi_hal_get_freq_limit(timing_param->use_gpio, timing_param->input_delay_ns);
HAL_EARLY_LOGE(SPI_HAL_TAG, "The clock_speed_hz should less than %d", freq_limit);
return ESP_ERR_NOT_SUPPORTED;
}