ledc: Fix -Werror=maybe-uninitialized warning on glb_clk variable on specific kconfig options selected

Closes https://github.com/espressif/esp-idf/pull/9025
Closes https://github.com/espressif/esp-idf/issues/10322
This commit is contained in:
Song Ruo Jing 2023-01-04 12:06:41 +08:00
parent 21c5c50924
commit 46f67092d0

View File

@ -28,6 +28,7 @@ static __attribute__((unused)) const char *LEDC_TAG = "ledc";
#define LEDC_ARG_CHECK(a, param) ESP_RETURN_ON_FALSE(a, ESP_ERR_INVALID_ARG, LEDC_TAG, param " argument is invalid")
#define LEDC_CLK_NOT_FOUND 0
#define LEDC_SLOW_CLK_UNINIT -1
typedef enum {
LEDC_FSM_IDLE,
@ -497,7 +498,7 @@ static esp_err_t ledc_set_timer_div(ledc_mode_t speed_mode, ledc_timer_t timer_n
/* Timer-specific mux. Set to timer-specific clock or LEDC_SCLK if a global clock is used. */
ledc_clk_src_t timer_clk_src;
/* Global clock mux. Should be set when LEDC_SCLK is used in LOW_SPEED_MODE. Otherwise left uninitialized. */
ledc_slow_clk_sel_t glb_clk;
ledc_slow_clk_sel_t glb_clk = LEDC_SLOW_CLK_UNINIT;
if (clk_cfg == LEDC_AUTO_CLK) {
/* User hasn't specified the speed, we should try to guess it. */
@ -570,6 +571,8 @@ static esp_err_t ledc_set_timer_div(ledc_mode_t speed_mode, ledc_timer_t timer_n
*/
assert(timer_clk_src == LEDC_SCLK);
#endif
// Arriving here, variable glb_clk must have been assigned to one of the ledc_slow_clk_sel_t enum values
assert(glb_clk != LEDC_SLOW_CLK_UNINIT);
ESP_LOGD(LEDC_TAG, "In slow speed mode, global clk set: %d", glb_clk);
/* keep ESP_PD_DOMAIN_RC_FAST on during light sleep */