Skip to content

Commit

Permalink
regulator: core: Prevent integer underflow
Browse files Browse the repository at this point in the history
[ Upstream commit 8d8e165 ]

By using a ratio of delay to poll_enabled_time that is not integer
time_remaining underflows and does not exit the loop as expected.
As delay could be derived from DT and poll_enabled_time is defined
in the driver this can easily happen.

Use a signed iterator to make sure that the loop exits once
the remaining time is negative.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Link: https://lore.kernel.org/r/20220909125954.577669-1-patrick.rudolph@9elements.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
PatrickRudolph authored and gregkh committed Oct 21, 2022
1 parent adef523 commit bfe602d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
* return -ETIMEDOUT.
*/
if (rdev->desc->poll_enabled_time) {
unsigned int time_remaining = delay;
int time_remaining = delay;

while (time_remaining > 0) {
_regulator_delay_helper(rdev->desc->poll_enabled_time);
Expand Down

0 comments on commit bfe602d

Please sign in to comment.