From: Jonathan Cavitt Date: Thu, 4 Sep 2025 19:30:42 +0000 (+0000) Subject: drm/i915/gt: Fix memory leak in hangcheck selftest X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f8d2c26df98b487d61e582c01804340b96c44e44;p=users%2Fhch%2Fmisc.git drm/i915/gt: Fix memory leak in hangcheck selftest In active_engines, if intel_context_create fails, we need to go backwards through all the created contexts to free/put them. However, the way this is currently performed skips the first created context, as if count == 1, then --count returns 0 and exits the while-loop prematurely without performing the intel_context_put on context 0. Fix this by post-decrementing count in the while-loop, rather than pre-decrementing it. This change makes the prior guard against count underflowing unnecessary, as the while-loop exits when count == 0. Signed-off-by: Jonathan Cavitt Cc: Krzysztof Karas Cc: Andi Shyti Cc: Sebastian Brzezinka Reviewed-by: Krzysztof Karas Reviewed-by: Andi Shyti Signed-off-by: Andi Shyti Link: https://lore.kernel.org/r/20250904193041.12888-2-jonathan.cavitt@intel.com --- diff --git a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c index 619c70c54ef9..4f252f704975 100644 --- a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c +++ b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c @@ -904,9 +904,7 @@ 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) + while (count--) intel_context_put(ce[count]); return; }