From a88bd155cd2bcf2e48ed26bddee16e0cb399a41a Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Fri, 14 Feb 2025 16:42:36 +0800 Subject: [PATCH] fix(ledc): overflowed integer argument in ledc_hal_clear_left_off_fade_param --- components/hal/esp32c5/include/hal/ledc_ll.h | 2 ++ components/hal/esp32c6/include/hal/ledc_ll.h | 2 ++ components/hal/esp32c61/include/hal/ledc_ll.h | 2 ++ components/hal/esp32h2/include/hal/ledc_ll.h | 2 ++ components/hal/esp32p4/include/hal/ledc_ll.h | 2 ++ components/hal/ledc_hal_iram.c | 1 - 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/hal/esp32c5/include/hal/ledc_ll.h b/components/hal/esp32c5/include/hal/ledc_ll.h index e6fd636379..184ba2355d 100644 --- a/components/hal/esp32c5/include/hal/ledc_ll.h +++ b/components/hal/esp32c5/include/hal/ledc_ll.h @@ -15,6 +15,7 @@ #include "soc/ledc_reg.h" #include "soc/clk_tree_defs.h" #include "soc/pcr_struct.h" +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -369,6 +370,7 @@ static inline void ledc_ll_get_duty(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc */ static inline void ledc_ll_set_fade_param_range(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint8_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step) { + HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX); ledc_channel_gamma_fade_param_t range_param = { .duty_inc = dir, .duty_cycle = cycle, diff --git a/components/hal/esp32c6/include/hal/ledc_ll.h b/components/hal/esp32c6/include/hal/ledc_ll.h index b73e0214af..a7f1374c4b 100644 --- a/components/hal/esp32c6/include/hal/ledc_ll.h +++ b/components/hal/esp32c6/include/hal/ledc_ll.h @@ -16,6 +16,7 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" #include "esp_rom_sys.h" //for sync issue workaround +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -452,6 +453,7 @@ static inline void ledc_ll_set_duty_range_wr_addr(ledc_dev_t *hw, ledc_mode_t sp */ static inline void ledc_ll_set_fade_param_range(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint8_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step) { + HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX); // To workaround sync issue // This is to ensure the fade param write to the gamma_wr register would not mess up the last wr_addr ledc_ll_set_duty_range_wr_addr(hw, speed_mode, channel_num, range); diff --git a/components/hal/esp32c61/include/hal/ledc_ll.h b/components/hal/esp32c61/include/hal/ledc_ll.h index d5870636aa..38da76b0f5 100644 --- a/components/hal/esp32c61/include/hal/ledc_ll.h +++ b/components/hal/esp32c61/include/hal/ledc_ll.h @@ -15,6 +15,7 @@ #include "soc/ledc_reg.h" #include "soc/clk_tree_defs.h" #include "soc/pcr_struct.h" +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -369,6 +370,7 @@ static inline void ledc_ll_get_duty(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc */ static inline void ledc_ll_set_fade_param_range(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint8_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step) { + HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX); ledc_channel_gamma_fade_param_t range_param = { .duty_inc = dir, .duty_cycle = cycle, diff --git a/components/hal/esp32h2/include/hal/ledc_ll.h b/components/hal/esp32h2/include/hal/ledc_ll.h index 731ee3f3ea..56ae897e13 100644 --- a/components/hal/esp32h2/include/hal/ledc_ll.h +++ b/components/hal/esp32h2/include/hal/ledc_ll.h @@ -16,6 +16,7 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" #include "esp_rom_sys.h" //for sync issue workaround +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -450,6 +451,7 @@ static inline void ledc_ll_set_duty_range_wr_addr(ledc_dev_t *hw, ledc_mode_t sp */ static inline void ledc_ll_set_fade_param_range(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint8_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step) { + HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX); // To workaround sync issue // This is to ensure the fade param write to the gamma_wr register would not mess up the last wr_addr ledc_ll_set_duty_range_wr_addr(hw, speed_mode, channel_num, range); diff --git a/components/hal/esp32p4/include/hal/ledc_ll.h b/components/hal/esp32p4/include/hal/ledc_ll.h index dea593b889..8871c64623 100644 --- a/components/hal/esp32p4/include/hal/ledc_ll.h +++ b/components/hal/esp32p4/include/hal/ledc_ll.h @@ -15,6 +15,7 @@ #include "soc/ledc_reg.h" #include "soc/clk_tree_defs.h" #include "soc/hp_sys_clkrst_struct.h" +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -383,6 +384,7 @@ static inline void ledc_ll_get_duty(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc */ static inline void ledc_ll_set_fade_param_range(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint8_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step) { + HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX); ledc_channel_gamma_fade_param_t range_param = { .duty_inc = dir, .duty_cycle = cycle, diff --git a/components/hal/ledc_hal_iram.c b/components/hal/ledc_hal_iram.c index be3e876567..ac3112caa8 100644 --- a/components/hal/ledc_hal_iram.c +++ b/components/hal/ledc_hal_iram.c @@ -39,7 +39,6 @@ void ledc_hal_get_duty(ledc_hal_context_t *hal, ledc_channel_t channel_num, uint void ledc_hal_set_fade_param(const ledc_hal_context_t *hal, ledc_channel_t channel_num, uint32_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step) { #if SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED - HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX); ledc_ll_set_fade_param_range(hal->dev, hal->speed_mode, channel_num, range, dir, cycle, scale, step); #else // !SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED HAL_ASSERT(range == 0);