qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Icenowy Zheng <uwu@icenowy.me>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] tcg/tci: fix logic error when registering helpers via FFI
Date: Sat, 29 Oct 2022 06:28:17 +1100	[thread overview]
Message-ID: <f28c1d8f-d30d-fc24-ce4e-88aba776abe2@linaro.org> (raw)
In-Reply-To: <20221028072145.1593205-1-uwu@icenowy.me>

On 10/28/22 18:21, Icenowy Zheng wrote:
> When registering helpers via FFI for TCI, the inner loop that iterates
> parameters of the helper reuses (and thus pollutes) the same variable
> used by the outer loop that iterates all helpers, thus made some helpers
> unregistered.
> 
> Fix this logic error by using a dedicated temporary variable for the
> inner loop.
> 
> Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
> ---
>   tcg/tcg.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 612a12f58f..adfaf61a32 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -619,6 +619,7 @@ static void tcg_context_init(unsigned max_cpus)
>           gpointer hash = (gpointer)(uintptr_t)typemask;
>           ffi_status status;
>           int nargs;
> +        int j;
>   
>           if (g_hash_table_lookup(ffi_table, hash)) {
>               continue;
> @@ -634,9 +635,9 @@ static void tcg_context_init(unsigned max_cpus)
>   
>           if (nargs != 0) {
>               ca->cif.arg_types = ca->args;
> -            for (i = 0; i < nargs; ++i) {
> -                int typecode = extract32(typemask, (i + 1) * 3, 3);
> -                ca->args[i] = typecode_to_ffi[typecode];
> +            for (j = 0; j < nargs; ++j) {
> +                int typecode = extract32(typemask, (j + 1) * 3, 3);
> +                ca->args[j] = typecode_to_ffi[typecode];

Oh my.  I'm surprised any test cases at all worked.
Queued to tcg-next, with the declaration of j moved to the loop itself:

	for (int j = 0; j < nargs; ++j)


r~



  parent reply	other threads:[~2022-10-28 19:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28  7:21 [PATCH] tcg/tci: fix logic error when registering helpers via FFI Icenowy Zheng
2022-10-28  9:13 ` Alex Bennée
2022-10-28  9:15   ` Icenowy Zheng
2022-10-28  9:16 ` Philippe Mathieu-Daudé
2022-10-28 19:28 ` Richard Henderson [this message]
2022-10-29  0:44   ` Icenowy Zheng
2022-10-30 10:27     ` Peter Maydell
2022-10-30 23:27     ` Richard Henderson

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=f28c1d8f-d30d-fc24-ce4e-88aba776abe2@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=uwu@icenowy.me \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).