* [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr
@ 2023-11-23 10:13 Daniel Henrique Barboza
2023-11-23 10:23 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Henrique Barboza @ 2023-11-23 10:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
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;
| ^~~
../target/riscv/kvm/kvm-cpu.c: In function 'kvm_riscv_put_regs_csr':
../target/riscv/kvm/kvm-cpu.c:98:13: error: declaration of 'ret' shadows a previous local [-Werror=shadow=compatible-local]
98 | int ret = kvm_set_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \
| ^~~
../target/riscv/kvm/kvm-cpu.c:556:5: note: in expansion of macro 'KVM_RISCV_SET_CSR'
556 | KVM_RISCV_SET_CSR(cs, env, sstatus, env->mstatus);
| ^~~~~~~~~~~~~~~~~
../target/riscv/kvm/kvm-cpu.c:553:9: note: shadowed declaration is here
553 | 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(-)
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 78fa1fa162..45b6cf1cfa 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -87,17 +87,17 @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type,
#define KVM_RISCV_GET_CSR(cs, env, csr, reg) \
do { \
- int ret = kvm_get_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \
- if (ret) { \
- return ret; \
+ int _ret = kvm_get_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \
+ if (_ret) { \
+ return _ret; \
} \
} while (0)
#define KVM_RISCV_SET_CSR(cs, env, csr, reg) \
do { \
- int ret = kvm_set_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \
- if (ret) { \
- return ret; \
+ int _ret = kvm_set_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \
+ if (_ret) { \
+ return _ret; \
} \
} while (0)
@@ -533,7 +533,6 @@ static int kvm_riscv_put_regs_core(CPUState *cs)
static int kvm_riscv_get_regs_csr(CPUState *cs)
{
- int ret = 0;
CPURISCVState *env = &RISCV_CPU(cs)->env;
KVM_RISCV_GET_CSR(cs, env, sstatus, env->mstatus);
@@ -545,12 +544,12 @@ static int kvm_riscv_get_regs_csr(CPUState *cs)
KVM_RISCV_GET_CSR(cs, env, stval, env->stval);
KVM_RISCV_GET_CSR(cs, env, sip, env->mip);
KVM_RISCV_GET_CSR(cs, env, satp, env->satp);
- return ret;
+
+ return 0;
}
static int kvm_riscv_put_regs_csr(CPUState *cs)
{
- int ret = 0;
CPURISCVState *env = &RISCV_CPU(cs)->env;
KVM_RISCV_SET_CSR(cs, env, sstatus, env->mstatus);
@@ -563,7 +562,7 @@ static int kvm_riscv_put_regs_csr(CPUState *cs)
KVM_RISCV_SET_CSR(cs, env, sip, env->mip);
KVM_RISCV_SET_CSR(cs, env, satp, env->satp);
- return ret;
+ return 0;
}
static int kvm_riscv_get_regs_fp(CPUState *cs)
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr
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é
0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-23 10:23 UTC (permalink / raw)
To: Daniel Henrique Barboza, qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr
2023-11-23 10:23 ` Philippe Mathieu-Daudé
@ 2023-12-03 16:59 ` Philippe Mathieu-Daudé
2023-12-04 1:48 ` Alistair Francis
0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-12-03 16:59 UTC (permalink / raw)
To: Daniel Henrique Barboza, qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, Markus Armbruster,
zhiwei_liu, Alex Bennée, palmer, ajones, Stefan Hajnoczi
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).
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-8.2] target/riscv/kvm: fix shadowing in kvm_riscv_(get|put)_regs_csr
2023-12-03 16:59 ` Philippe Mathieu-Daudé
@ 2023-12-04 1:48 ` Alistair Francis
0 siblings, 0 replies; 4+ messages in thread
From: Alistair Francis @ 2023-12-04 1:48 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Daniel Henrique Barboza, qemu-devel, qemu-riscv, alistair.francis,
bmeng, liwei1518, Markus Armbruster, zhiwei_liu, Alex Bennée,
palmer, ajones, Stefan Hajnoczi
On Mon, Dec 4, 2023 at 3:00 AM Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> 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>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
>
> 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).
Go for it! That would be really helpful
Alistair
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-12-04 1:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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é
2023-12-04 1:48 ` Alistair Francis
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).