Commit 8d8e1659 authored by Patrick Rudolph's avatar Patrick Rudolph Committed by Mark Brown

regulator: core: Prevent integer underflow

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: default avatarPatrick Rudolph <patrick.rudolph@9elements.com>
Link: https://lore.kernel.org/r/20220909125954.577669-1-patrick.rudolph@9elements.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 08865c21
...@@ -2699,7 +2699,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev) ...@@ -2699,7 +2699,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
* return -ETIMEDOUT. * return -ETIMEDOUT.
*/ */
if (rdev->desc->poll_enabled_time) { if (rdev->desc->poll_enabled_time) {
unsigned int time_remaining = delay; int time_remaining = delay;
while (time_remaining > 0) { while (time_remaining > 0) {
_regulator_delay_helper(rdev->desc->poll_enabled_time); _regulator_delay_helper(rdev->desc->poll_enabled_time);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment