qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
	qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com,
	bmeng@tinylab.org, liwei1518@gmail.com,
	zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com,
	ajones@ventanamicro.com
Subject: Re: [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr
Date: Thu, 23 Nov 2023 11:23:33 +0100	[thread overview]
Message-ID: <5cb07d83-934d-4db0-8fee-3146f3751743@linaro.org> (raw)
In-Reply-To: <20231123101338.1040134-1-dbarboza@ventanamicro.com>

On 23/11/23 11:13, Daniel Henrique Barboza wrote:
> KVM_RISCV_GET_CSR() and KVM_RISCV_SET_CSR() use an 'int ret' variable
> that is used to do an early 'return' if ret > 0. Both are being called
> in functions that are also declaring a 'ret' integer, initialized with
> '0', and this integer is used as return of the function.
> 
> The result is that the compiler is less than pleased and is pointing
> shadowing errors:
> 
> ../target/riscv/kvm/kvm-cpu.c: In function 'kvm_riscv_get_regs_csr':
> ../target/riscv/kvm/kvm-cpu.c:90:13: error: declaration of 'ret' shadows a previous local [-Werror=shadow=compatible-local]
>     90 |         int ret = kvm_get_one_reg(cs, RISCV_CSR_REG(env, csr), &reg); \
>        |             ^~~
> ../target/riscv/kvm/kvm-cpu.c:539:5: note: in expansion of macro 'KVM_RISCV_GET_CSR'
>    539 |     KVM_RISCV_GET_CSR(cs, env, sstatus, env->mstatus);
>        |     ^~~~~~~~~~~~~~~~~
> ../target/riscv/kvm/kvm-cpu.c:536:9: note: shadowed declaration is here
>    536 |     int ret = 0;


> The macros are doing early returns for non-zero returns and the local
> 'ret' variable for both functions is used just to do 'return 0', so
> remove them from kvm_riscv_get_regs_csr() and kvm_riscv_put_regs_csr()
> and do a straight 'return 0' in the end.
> 
> For good measure let's also rename the 'ret' variables in
> KVM_RISCV_GET_CSR() and KVM_RISCV_SET_CSR() to '_ret' to make them more
> resilient to these kind of errors.
> 
> Fixes: 937f0b4512 ("target/riscv: Implement kvm_arch_get_registers")
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>   target/riscv/kvm/kvm-cpu.c | 19 +++++++++----------
>   1 file changed, 9 insertions(+), 10 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>




  reply	other threads:[~2023-11-23 10:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 10:13 [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr Daniel Henrique Barboza
2023-11-23 10:23 ` Philippe Mathieu-Daudé [this message]
2023-12-03 16:59   ` Philippe Mathieu-Daudé
2023-12-04  1:48     ` Alistair Francis

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=5cb07d83-934d-4db0-8fee-3146f3751743@linaro.org \
    --to=philmd@linaro.org \
    --cc=ajones@ventanamicro.com \
    --cc=alistair.francis@wdc.com \
    --cc=bmeng@tinylab.org \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@rivosinc.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=zhiwei_liu@linux.alibaba.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 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).