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,
"Markus Armbruster" <armbru@redhat.com>,
zhiwei_liu@linux.alibaba.com,
"Alex Bennée" <alex.bennee@linaro.org>,
palmer@rivosinc.com, ajones@ventanamicro.com,
"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: Re: [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr
Date: Sun, 3 Dec 2023 17:59:03 +0100 [thread overview]
Message-ID: <94455c2c-dba0-454e-b9b6-3413f272e13f@linaro.org> (raw)
In-Reply-To: <5cb07d83-934d-4db0-8fee-3146f3751743@linaro.org>
On 23/11/23 11:23, Philippe Mathieu-Daudé wrote:
> 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), ®); \
>> | ^~~
>> ../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>
Also:
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Alistair, if you don't have any pending riscv pull request
I can take this patch with the one I plan to post tomorrow
(this is the last fix missing to get our CI green again).
next prev parent reply other threads:[~2023-12-03 16:59 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é
2023-12-03 16:59 ` Philippe Mathieu-Daudé [this message]
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=94455c2c-dba0-454e-b9b6-3413f272e13f@linaro.org \
--to=philmd@linaro.org \
--cc=ajones@ventanamicro.com \
--cc=alex.bennee@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=armbru@redhat.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=stefanha@redhat.com \
--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).