drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
Subsystems (3)
PATCH 1/1 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.
--- drivers/gpu/drm/imagination/pvr_vm_mips.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/imagination/pvr_vm_mips.c +3 -3
@@ -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;
@@ -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);
Signature · 1 line
2.25.1
Re: (subset) [PATCH] drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
Quoted 10 lines · Donald Robson
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_pfncan 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.[...]
Applied to drm/drm-misc (drm-misc-next-fixes).
Thanks!
Maxime