[lvc-project] [PATCH] regulator: palmas: Check return value of palmas_smps_write()

Fedor Pchelkin pchelkin at ispras.ru
Thu Jul 16 11:53:19 MSK 2026


On Thu, 18. Jun 14:03, Aleksandrova Alyona wrote:
> palmas_set_mode_smps() updates the SMPS mode register when the rail is
> enabled, but it ignores a possible error from palmas_smps_write().
> 
> Since enable_val is updated after the write, ignoring the error may leave
> the cached enable value inconsistent with the hardware state.
> 
> Return the error if the register write fails to avoid reporting success
> when the mode has not been updated.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 51d3a0c999e1 ("regulator: palmas: preserve modes of rails during enable/disable")
> Signed-off-by: Aleksandrova Alyona <aga at itb.spb.ru>
> ---
>  drivers/regulator/palmas-regulator.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
> index 337dd614695e..fa6dd240015e 100644
> --- a/drivers/regulator/palmas-regulator.c
> +++ b/drivers/regulator/palmas-regulator.c
> @@ -469,8 +469,11 @@ static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
>  	}
>  
>  	pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
> -	if (rail_enable)
> -		palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg);
> +	if (rail_enable) {
> +		ret = palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg);
> +		if (ret)
> +			return ret;
> +	}

К патчу возник вопрос, требующий анализа

  Does this early return introduce a regression that leaves the cached
  current_reg_mode out of sync with the hardware state? 
  We update pmic->current_reg_mode[id] just before the write. If the write
  fails and we return early, the cached mode reflects the new mode but the
  hardware and pmic->desc[id].enable_val remain unchanged. Subsequent calls
  to palmas_get_mode_smps() might incorrectly report the failed mode.

https://sashiko.dev/#/patchset/20260618110338.53004-1-aga%40itb.spb.ru


Также всё ещё не вижу в исходжном предупреждении Major влияния на
безопасность.

>  
>  	/* Switch the enable value to ensure this is used for enable */
>  	pmic->desc[id].enable_val = pmic->current_reg_mode[id];
> -- 
> 2.26.2



More information about the lvc-project mailing list