regulator: core: Prevent integer underflow
authorPatrick Rudolph <patrick.rudolph@9elements.com>
Fri, 9 Sep 2022 12:59:53 +0000 (14:59 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 9 Sep 2022 21:27:10 +0000 (22:27 +0100)
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>
drivers/regulator/core.c

index a8dab5a936070455ee7fb3996c3583e0e9243eee..28879f8974d9c94db65ecf63e832a02ec294e823 100644 (file)
@@ -2699,7 +2699,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);