target/riscv: Fix a uninitialized variable warning
PATCH v2 1/1 target/riscv: Fix a uninitialized variable warning
riscv_cpu_validate_v() left its variable, min_vlen, uninitialized if no vector extension is available, causing a compiler warning.
Re-define riscv_cpu_validate_v() as no-op when no vector extension is available to prevent the scenario that will read the unintialized variable by construction. It also simplifies its caller as a bonus.
---
Changes in v2:
- De-duplicated zve32f checks as suggested by Daniel Henrique Barboza.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
--- target/riscv/tcg/tcg-cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target/riscv/tcg/tcg-cpu.c +6 -6
@@ -426,6 +426,8 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, min_vlen =64 ; }else if (cfg->ext_zve32x) { min_vlen =32 ; + }else { +return ; }if (vlen >RV_VLEN_MAX || vlen < min_vlen) {
@@ -676,12 +678,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } -if (cpu->cfg.ext_zve32x) { -riscv_cpu_validate_v (env, &cpu->cfg, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return ; - } +riscv_cpu_validate_v (env, &cpu->cfg, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; }/* The Zve64d extension depends on the Zve64f extension */
---
base-commit: c85ba2d7a4056595166689890285105579db446a
change-id: 20251019-vlen-30a57c03bd93
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
Quoted 9 lines · Akihiko Odaki
riscv_cpu_validate_v()left its variable,min_vlen, uninitialized if no vector extension is available, causing a compiler warning.Re-define
riscv_cpu_validate_v()as no-op when no vector extension is available to prevent the scenario that will read the unintialized variable by construction. It also simplifies its caller as a bonus.Signed-off-by Akihiko Odaki <[email protected]>---
Quoted 46 lines
Changes in v2:
- De-duplicated zve32f checks as suggested by Daniel Henrique Barboza.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]--- target/riscv/tcg/tcg-cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)target/riscv/tcg/tcg-cpu.c +6
-7@@ -426,6 +426,8 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, min_vlen =64 ; }else if (cfg->ext_zve32x) { min_vlen =32 ; + }else { +return ; }if (vlen >RV_VLEN_MAX || vlen < min_vlen) {@@ -676,12 +678,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } -if (cpu->cfg.ext_zve32x) { -riscv_cpu_validate_v (env, &cpu->cfg, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return ; - } +riscv_cpu_validate_v (env, &cpu->cfg, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; }/* The Zve64d extension depends on the Zve64f extension */ ---base-commit:
c85ba2d7a4056595166689890285105579db446a
change-id: 20251019-vlen-30a57c03bd93Best regards,
--
Akihiko Odaki <[email protected]>
Alistair Francis
AppliedQuoted 9 lines · Akihiko Odaki
riscv_cpu_validate_v()left its variable,min_vlen, uninitialized if no vector extension is available, causing a compiler warning.Re-define
riscv_cpu_validate_v()as no-op when no vector extension is available to prevent the scenario that will read the unintialized variable by construction. It also simplifies its caller as a bonus.Signed-off-by Akihiko Odaki <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 48 lines
---
Changes in v2:
- De-duplicated zve32f checks as suggested by Daniel Henrique Barboza.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]--- target/riscv/tcg/tcg-cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)target/riscv/tcg/tcg-cpu.c +6
-7@@ -426,6 +426,8 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, min_vlen =64 ; }else if (cfg->ext_zve32x) { min_vlen =32 ; + }else { +return ; }if (vlen >RV_VLEN_MAX || vlen < min_vlen) {@@ -676,12 +678,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } -if (cpu->cfg.ext_zve32x) { -riscv_cpu_validate_v (env, &cpu->cfg, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return ; - } +riscv_cpu_validate_v (env, &cpu->cfg, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; }/* The Zve64d extension depends on the Zve64f extension */ ---base-commit:
c85ba2d7a4056595166689890285105579db446a
change-id: 20251019-vlen-30a57c03bd93Best regards,
--
Akihiko Odaki <[email protected]>