Inside function stm32_pwm_config(), variable "psc" and " arr" could be uninitialized if regmap_read() returns -EINVALs. However, they are used later in the if statement to decide the return value which is potentially unsafe.
The same case happens in function stm32_pwm_detect_channels() with variable "ccer", but we cannot just return -EINVAL because the error code is not acceptable by the caller. Aslo, the variable "ccer" in functionstm32_pwm_detect_complementary() could also be uninitialized, since stm32_pwm_detect_complementary() returns void, the patch is not easy. Signed-off-by: Yizhuo <yzhai...@ucr.edu> --- drivers/pwm/pwm-stm32.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index 359b08596d9e..22c54df52977 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -346,9 +346,15 @@ static int stm32_pwm_config(struct stm32_pwm *priv, int ch, */ if (active_channels(priv) & ~(1 << ch * 4)) { u32 psc, arr; + int ret; - regmap_read(priv->regmap, TIM_PSC, &psc); - regmap_read(priv->regmap, TIM_ARR, &arr); + ret = regmap_read(priv->regmap, TIM_PSC, &psc); + if (ret) + return ret; + + ret = regmap_read(priv->regmap, TIM_ARR, &arr); + if (ret) + return ret; if ((psc != prescaler) || (arr != prd - 1)) return -EBUSY; -- 2.17.1