Skip to content

Commit

Permalink
drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
Browse files Browse the repository at this point in the history
Unwinding loop in error path for this function uses unsigned limit
variable, causing the promotion of the signed counter variable.

--> 204         for (; pfn >= start_pfn; pfn--)
                       ^^^^^^^^^^^^^^^^
If start_pfn can be zero then this is an endless loop.  I've seen this
code in other places as well.  This loop is slightly off as well.  It
should decrement pfn on the first iteration.

Fix by making the loop limit variables signed. Also fix missing
predecrement by modifying to while loop.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Donald Robson <donald.robson@imgtec.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20231208160825.92933-1-donald.robson@imgtec.com
  • Loading branch information
Donald Robson authored and Maxime Ripard committed Dec 15, 2023
1 parent b1a2aa9 commit b39610c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/gpu/drm/imagination/pvr_vm_mips.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
u64 end;
u32 cache_policy;
u32 pte_flags;
u32 start_pfn;
u32 end_pfn;
s32 start_pfn;
s32 end_pfn;
s32 pfn;
int err;

Expand Down Expand Up @@ -201,7 +201,7 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
return 0;

err_unmap_pages:
for (; pfn >= start_pfn; pfn--)
while (--pfn >= start_pfn)
WRITE_ONCE(mips_data->pt[pfn], 0);

pvr_mmu_flush_request_all(pvr_dev);
Expand Down

0 comments on commit b39610c

Please sign in to comment.