drm/i915/selftests: fix subtraction overflow bug
authorAndrzej Hajda <andrzej.hajda@intel.com>
Fri, 24 Jun 2022 11:35:28 +0000 (13:35 +0200)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 12 Jul 2022 21:57:27 +0000 (17:57 -0400)
On some machines hole_end can be small enough to cause subtraction
overflow. On the other side (addr + 2 * min_alignment) can overflow
in case of mock tests. This patch should handle both cases.

Fixes: e1c5f754067b59 ("drm/i915: Avoid overflow in computing pot_hole loop termination")
Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/3674
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220624113528.2159210-1-andrzej.hajda@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c

index 8633bec18fa75e1efb16407b181a7767234c2b7f..ab9f17fc85bcf2682c094d698540100f8df3a912 100644 (file)
@@ -742,7 +742,7 @@ static int pot_hole(struct i915_address_space *vm,
                u64 addr;
 
                for (addr = round_up(hole_start + min_alignment, step) - min_alignment;
-                    addr <= round_down(hole_end - (2 * min_alignment), step) - min_alignment;
+                    hole_end > addr && hole_end - addr >= 2 * min_alignment;
                     addr += step) {
                        err = i915_vma_pin(vma, 0, 0, addr | flags);
                        if (err) {