[PATCH] regulator: mt6358: use regmap helper to read fixed LDO calibration

Daniel Golle posted 1 patch 1 week ago
drivers/regulator/mt6358-regulator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] regulator: mt6358: use regmap helper to read fixed LDO calibration
Posted by Daniel Golle 1 week ago
The "fixed" LDOs with output voltage calibration use
mt6358_get_buck_voltage_sel as their get_voltage_sel op, but the
MT6358_REG_FIXED and MT6366_REG_FIXED entries do not populate
da_vsel_reg/da_vsel_mask. The op therefore reads register 0x0 with a
zero mask and shifts the result by ffs(0) - 1 = -1, which is undefined
behaviour and gets flagged by UBSAN on every boot on MT6366 boards:

  UBSAN: shift-out-of-bounds in drivers/regulator/mt6358-regulator.c:384:38
  shift exponent -1 is negative
  Call trace:
   mt6358_get_buck_voltage_sel+0xc8/0x120
   regulator_get_voltage_rdev+0x70/0x170
   set_machine_constraints+0x504/0xc38
   regulator_register+0x324/0xc68

Besides the undefined shift, the returned selector is always 0, so the
actual calibration offset programmed in <reg>_ANA_CON0 is never
reported.

The descriptor already carries the correct vsel_reg/vsel_mask (the
ANA_CON0 calibration field), matching the regulator_set_voltage_sel_regmap
op already in use. Read the selector back through
regulator_get_voltage_sel_regmap instead.

Fixes: cf08fa74c716 ("regulator: mt6358: Add output voltage fine tuning to fixed regulators")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/regulator/mt6358-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt6358-regulator.c
index f2bb3c1523ca..d6a0ec406b07 100644
--- a/drivers/regulator/mt6358-regulator.c
+++ b/drivers/regulator/mt6358-regulator.c
@@ -492,7 +492,7 @@ static const struct regulator_ops mt6358_volt_fixed_ops = {
 	.list_voltage = regulator_list_voltage_linear,
 	.map_voltage = regulator_map_voltage_linear,
 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
-	.get_voltage_sel = mt6358_get_buck_voltage_sel,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
 	.enable = regulator_enable_regmap,
 	.disable = regulator_disable_regmap,
-- 
2.55.0
Re: [PATCH] regulator: mt6358: use regmap helper to read fixed LDO calibration
Posted by Mark Brown 4 days, 11 hours ago
On Sat, 18 Jul 2026 02:05:59 +0100, Daniel Golle wrote:
> regulator: mt6358: use regmap helper to read fixed LDO calibration

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-7.2

Thanks!

[1/1] regulator: mt6358: use regmap helper to read fixed LDO calibration
      https://git.kernel.org/broonie/regulator/c/1d26f125501f

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Re: [PATCH] regulator: mt6358: use regmap helper to read fixed LDO calibration
Posted by Chen-Yu Tsai 4 days, 20 hours ago
On Sat, Jul 18, 2026 at 9:06 AM Daniel Golle <daniel@makrotopia.org> wrote:
>
> The "fixed" LDOs with output voltage calibration use
> mt6358_get_buck_voltage_sel as their get_voltage_sel op, but the
> MT6358_REG_FIXED and MT6366_REG_FIXED entries do not populate
> da_vsel_reg/da_vsel_mask. The op therefore reads register 0x0 with a
> zero mask and shifts the result by ffs(0) - 1 = -1, which is undefined
> behaviour and gets flagged by UBSAN on every boot on MT6366 boards:
>
>   UBSAN: shift-out-of-bounds in drivers/regulator/mt6358-regulator.c:384:38
>   shift exponent -1 is negative
>   Call trace:
>    mt6358_get_buck_voltage_sel+0xc8/0x120
>    regulator_get_voltage_rdev+0x70/0x170
>    set_machine_constraints+0x504/0xc38
>    regulator_register+0x324/0xc68
>
> Besides the undefined shift, the returned selector is always 0, so the
> actual calibration offset programmed in <reg>_ANA_CON0 is never
> reported.
>
> The descriptor already carries the correct vsel_reg/vsel_mask (the
> ANA_CON0 calibration field), matching the regulator_set_voltage_sel_regmap
> op already in use. Read the selector back through
> regulator_get_voltage_sel_regmap instead.
>
> Fixes: cf08fa74c716 ("regulator: mt6358: Add output voltage fine tuning to fixed regulators")
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Reviewed-by: Chen-Yu Tsai <wens@kernel.org>
Tested-by: Chen-Yu Tsai <wens@kernel.org>

I guess I wasn't looking hard enough when I did the original patch.
I can confirm that after this patch, the fixed LDOs like vxo22 on
Juniper reads out as 2.24V instead of 2.2V (and then gets corrected
down to 2.2V by the kernel).

> ---
>  drivers/regulator/mt6358-regulator.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt6358-regulator.c
> index f2bb3c1523ca..d6a0ec406b07 100644
> --- a/drivers/regulator/mt6358-regulator.c
> +++ b/drivers/regulator/mt6358-regulator.c
> @@ -492,7 +492,7 @@ static const struct regulator_ops mt6358_volt_fixed_ops = {
>         .list_voltage = regulator_list_voltage_linear,
>         .map_voltage = regulator_map_voltage_linear,
>         .set_voltage_sel = regulator_set_voltage_sel_regmap,
> -       .get_voltage_sel = mt6358_get_buck_voltage_sel,
> +       .get_voltage_sel = regulator_get_voltage_sel_regmap,
>         .set_voltage_time_sel = regulator_set_voltage_time_sel,
>         .enable = regulator_enable_regmap,
>         .disable = regulator_disable_regmap,
> --
> 2.55.0