mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-20 18:54:09 +08:00
regulator: s5m8767: Use DIV_ROUND_UP to calculate selector
Integer division may truncate the result. Use DIV_ROUND_UP to ensure new voltage setting falls within specified range. Also properly handle the case min_vol < desc->min to ensure we don't return negative value for selector. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
parent
b9b49af5ef
commit
94e85a3c5d
@ -347,7 +347,10 @@ static int s5m8767_convert_voltage_to_sel(
|
||||
if (max_vol < desc->min || min_vol > desc->max)
|
||||
return -EINVAL;
|
||||
|
||||
selector = (min_vol - desc->min) / desc->step;
|
||||
if (min_vol < desc->min)
|
||||
min_vol = desc->min;
|
||||
|
||||
selector = DIV_ROUND_UP(min_vol - desc->min, desc->step);
|
||||
|
||||
if (desc->min + desc->step * selector > max_vol)
|
||||
return -EINVAL;
|
||||
|
Loading…
Reference in New Issue
Block a user