Skip to content

Commit b39610c

Browse files
drobson-imgtecmripard
authored andcommitted
drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
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 <[email protected]> Signed-off-by: Donald Robson <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent b1a2aa9 commit b39610c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/gpu/drm/imagination/pvr_vm_mips.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
152152
u64 end;
153153
u32 cache_policy;
154154
u32 pte_flags;
155-
u32 start_pfn;
156-
u32 end_pfn;
155+
s32 start_pfn;
156+
s32 end_pfn;
157157
s32 pfn;
158158
int err;
159159

@@ -201,7 +201,7 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
201201
return 0;
202202

203203
err_unmap_pages:
204-
for (; pfn >= start_pfn; pfn--)
204+
while (--pfn >= start_pfn)
205205
WRITE_ONCE(mips_data->pt[pfn], 0);
206206

207207
pvr_mmu_flush_request_all(pvr_dev);

0 commit comments

Comments
 (0)