From: Jani Nikula <jani.nikula@linux.intel.com>
To: Krzysztof Karas <krzysztof.karas@intel.com>,
intel-gfx@lists.freedesktop.org
Cc: Andi Shyti <andi.shyti@linux.intel.com>,
Sebastian Brzezinka <sebastian.brzezinka@intel.com>,
Chris Wilson <chris.p.wilson@linux.intel.com>
Subject: Re: [PATCH v2] drm/i915/gt: Protect against overflow in active_engine()
Date: Mon, 04 Aug 2025 18:04:18 +0300 [thread overview]
Message-ID: <ff2314572908e95cebef2edc3473f3a6862681d0@intel.com> (raw)
In-Reply-To: <ifjlp3lvgfd47mkhzg2jnsyiwfofzqj5liuj7u34r5uel7d66e@d3mar5w3hhp3>
On Mon, 04 Aug 2025, Krzysztof Karas <krzysztof.karas@intel.com> wrote:
> 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 replacing "while" with
> "do while" and using decrement as postfix to make sure
> intel_context_put() fires at least once.
>
> Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
> ---
>
> v2:
> * remove unlikely() - Jani
> * replace "while" with "do while" - Andi
>
> drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c
> index f057c16410e7..4ec97024665a 100644
> --- a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c
> +++ b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c
> @@ -904,8 +904,9 @@ 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);
> - while (--count)
> + do {
> intel_context_put(ce[count]);
This passes an error pointer to intel_context_put().
BR,
Jani.
> + } while (count--);
> return;
> }
> }
> --
> 2.34.1
--
Jani Nikula, Intel
next prev parent reply other threads:[~2025-08-04 15:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-04 14:55 [PATCH v2] drm/i915/gt: Protect against overflow in active_engine() Krzysztof Karas
2025-08-04 15:04 ` Jani Nikula [this message]
2025-08-04 15:34 ` Andi Shyti
2025-08-04 17:21 ` ✓ i915.CI.BAT: success for drm/i915/gt: Protect against overflow in active_engine() (rev2) Patchwork
2025-08-05 5:13 ` ✓ i915.CI.Full: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ff2314572908e95cebef2edc3473f3a6862681d0@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=andi.shyti@linux.intel.com \
--cc=chris.p.wilson@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=krzysztof.karas@intel.com \
--cc=sebastian.brzezinka@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.