regulator: pf1550: fix division by zero in the ramp rate selection
Subsystems (3)
PATCH 1/1 regulator: pf1550: fix division by zero in the ramp rate selection
set_machine_constraints() calls the set_ramp_delay() op when either constraints->ramp_delay or constraints->ramp_disable is set. The regulator binding documents regulator-ramp-delay = <0> as the way to disable ramp control, and of_get_regulation_constraints() turns that into ramp_disable = true while leaving ramp_delay at 0, so the op is called with a ramp_delay of 0. The range check rejects negative values and values above 6250 but not zero, and the value is then used as a divisor.
The mapping is also wrong for the values that do pass the check. The hardware offers two rates, 6250 uV/us and 3125 uV/us, selected by SWx_DVSSPEED in SWx_CTRL1. Dividing 6250 by the requested rate and taking bit 1 of the quotient does not map monotonically onto them: a request for 1500 uV/us selects 6250 uV/us, while a request for the faster 2000 uV/us selects 3125 uV/us.
Replace the division with a direct mapping onto the two supported rates. Requests at or below 3125 uV/us get the slower rate and anything above it gets the faster one. A ramp_delay of 0 asks for ramp control to be disabled, which this hardware cannot do, so it gets the fastest rate; pfuze100 handles the disabled case the same way.
---
Compile-tested only, I do not have PF1550 hardware. The register semantics were checked against the PF1550 data sheet rev 3.0, table 28 (SWx DVS setting selection) and the SW1_CTRL1 register description.
drivers/regulator/pf1550-regulator.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/regulator/pf1550-regulator.c +14 -5
@@ -49,17 +49,26 @@ static const int pf1550_ldo13_volts[] = {static int pf1550_set_ramp_delay (struct regulator_dev *rdev,int ramp_delay) {int id =rdev_get_id (rdev); -unsigned int ramp_bits =0 ; +unsigned int ramp_bits;int ret;if (id >PF1550_VREFDDR )return -EACCES ; -if (ramp_delay <0 || ramp_delay >6250 ) +switch (ramp_delay) { +case 0 : +/* Ramp control is disabled, so use the fastest rate. */ + ramp_bits =0 ; +break ; + case 1 ... 3125: + ramp_bits =1 ; +break ; + case 3126 ... 6250: + ramp_bits =0 ; +break ; +default :return -EINVAL ; - - ramp_delay =6250 / ramp_delay; - ramp_bits = ramp_delay >>1 ; + } ret =regmap_update_bits (rdev->regmap, rdev->desc->vsel_reg +4 ,0x10 , ramp_bits <<4 );
Signature · 1 line
2.53.0
Mark Brown
maintainerQuoted 1 line · Donggeun Yoo
regulator: pf1550: fix division by zero in the ramp rate selection
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-7.4
Thanks!
[1/1] regulator: pf1550: fix division by zero in the ramp rate selection
https://git.kernel.org/broonie/sound/c/f0c54cc56a9a
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