[PATCH] drm/i915/gt: Ensure sleep calculations in wait_for_freq() do not use negative value of timeout_ms
Jani Nikula
jani.nikula at linux.intel.com
Tue Aug 5 12:09:46 UTC 2025
On Tue, 05 Aug 2025, Krzysztof Karas <krzysztof.karas at intel.com> wrote:
> wait_for_freq() allows timeout_ms to be negative to pass it down
> to msecs_to_jiffies(). If the argument to the latter function is
> indeed negative, then MAX_JIFFY_OFFSET is returned from it.
>
> However, later in the wait_for_freq()'s "do while" loop,
> "timeout_ms" is used to calculate a new value for "sleep", which
> is a plain integer. While "sleep" being negative does not lead
> to erroneous behavior, as the "sleep" is cast to unsigned type
> in usleep_range(), it does not seem intentional.
>
> Change the type of "sleep" variable to unsigned and ensure it
> does not use "timeout_ms", when it is a negative value in the
> calculations.
That's an elaborate explanation for a case that never
occurs. wait_for_freq() is used in three places with fixed timeout
values.
What's the real reason for the change?
BR,
Jani.
>
> Signed-off-by: Krzysztof Karas <krzysztof.karas at intel.com>
> ---
> drivers/gpu/drm/i915/gt/selftest_rps.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/selftest_rps.c b/drivers/gpu/drm/i915/gt/selftest_rps.c
> index 73bc91c6ea07..20ec7c0c94dc 100644
> --- a/drivers/gpu/drm/i915/gt/selftest_rps.c
> +++ b/drivers/gpu/drm/i915/gt/selftest_rps.c
> @@ -152,7 +152,7 @@ static u8 wait_for_freq(struct intel_rps *rps, u8 freq, int timeout_ms)
> {
> u8 history[64], i;
> unsigned long end;
> - int sleep;
> + unsigned int sleep;
>
> i = 0;
> memset(history, freq, sizeof(history));
> @@ -180,7 +180,7 @@ static u8 wait_for_freq(struct intel_rps *rps, u8 freq, int timeout_ms)
>
> usleep_range(sleep, 2 * sleep);
> sleep *= 2;
> - if (sleep > timeout_ms * 20)
> + if (sleep > timeout_ms * 20 && timeout_ms > 0)
> sleep = timeout_ms * 20;
> } while (1);
> }
> --
> 2.34.1
--
Jani Nikula, Intel
More information about the Intel-gfx
mailing list