All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] drm/i915/gt: Protect against overflow in active_engine()
@ 2025-08-05 11:41 Krzysztof Karas
  2025-08-05 11:46 ` Andi Shyti
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Krzysztof Karas @ 2025-08-05 11:41 UTC (permalink / raw)
  To: intel-gfx; +Cc: Jani Nikula, Andi Shyti, Sebastian Brzezinka, Chris Wilson

It is unlikely, but possible for the first call to
intel_context_create() to fail with -ENOMEM, which would result
in entering the following code block and decrementing "count",
when it is set to 0 (initial condition in the for loop).

Protect from overflowing the variable by checking for 0 value
of "count" before entering the loop.

Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
---

v2:
 * remove unlikely() - Jani
 * replace "while" with "do while" - Andi

v3:
 * use additional check for 0 value instead of changes to the
   "while" loop - Andi

 drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c
index f057c16410e7..619c70c54ef9 100644
--- a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c
+++ b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c
@@ -904,6 +904,8 @@ static void active_engine(struct kthread_work *work)
 			arg->result = PTR_ERR(ce[count]);
 			pr_err("[%s] Create context #%ld failed: %d!\n",
 			       engine->name, count, arg->result);
+			if (!count)
+				return;
 			while (--count)
 				intel_context_put(ce[count]);
 			return;
-- 
2.34.1

-- 
Best Regards,
Krzysztof

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-09 13:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 11:41 [PATCH v3] drm/i915/gt: Protect against overflow in active_engine() Krzysztof Karas
2025-08-05 11:46 ` Andi Shyti
2025-08-05 11:55 ` Sebastian Brzezinka
2025-08-05 12:33 ` ✓ i915.CI.BAT: success for drm/i915/gt: Protect against overflow in active_engine() (rev3) Patchwork
2025-08-05 15:38 ` ✗ i915.CI.Full: failure " Patchwork
2025-08-09  0:51 ` ✓ i915.CI.BAT: success for drm/i915/gt: Protect against overflow in active_engine() (rev4) Patchwork
2025-08-09  2:17 ` ✓ i915.CI.Full: " Patchwork
2025-08-09 13:57 ` [PATCH v3] drm/i915/gt: Protect against overflow in active_engine() Andi Shyti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.