[PATCH] drm/xe: Explicitly cast to u64 to avoid overflow
Matthew Brost
matthew.brost at intel.com
Fri Jun 14 06:20:39 UTC 2024
On Fri, Jun 14, 2024 at 07:15:56AM +0200, Zbigniew Kempczyński wrote:
> Without casting whole expression will be calculated on u32 what
> means adding U32_MAX effectively decreases the result by one due to
> overflow. Fix this and use explicit cast to u64.
>
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Matthew Brost <matthew.brost at intel.com>
> ---
> drivers/gpu/drm/xe/xe_guc_submit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
> index 74552391dc5a..347773f003f3 100644
> --- a/drivers/gpu/drm/xe/xe_guc_submit.c
> +++ b/drivers/gpu/drm/xe/xe_guc_submit.c
> @@ -967,7 +967,7 @@ static bool check_timeout(struct xe_exec_queue *q, struct xe_sched_job *job)
> xe_gt_assert(gt, timeout_ms < 100 * MSEC_PER_SEC);
>
> if (ctx_timestamp < ctx_job_timestamp)
> - diff = ctx_timestamp + U32_MAX - ctx_job_timestamp;
> + diff = (u64) ctx_timestamp + U32_MAX - ctx_job_timestamp;
I think the existing logic is correct, it dealing with the wrap of a u32
counter. There be a better way to code this though but this patch
doesn't look correct to me.
Matt
> else
> diff = ctx_timestamp - ctx_job_timestamp;
>
> --
> 2.34.1
>
More information about the Intel-xe
mailing list