]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/i915/gt: Protect against overflow in active_engine()
authorKrzysztof Karas <krzysztof.karas@intel.com>
Tue, 5 Aug 2025 11:41:42 +0000 (11:41 +0000)
committerAndi Shyti <andi.shyti@kernel.org>
Sat, 9 Aug 2025 11:44:53 +0000 (10:44 -0100)
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>
Reviewed-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://lore.kernel.org/r/pogr74jktdqehrfap4tjky23ees4x7erh5dwgg5jb2n522cfkw@kpnxe4qzx4pj
drivers/gpu/drm/i915/gt/selftest_hangcheck.c

index f057c16410e772f43a243fcea8f2a7ace1cd3e1a..619c70c54ef9dce9df8637b01e4af3d0e7c1e1bb 100644 (file)
@@ -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;