Skip to contentSkip to conversation

target/riscv: Fix a uninitialized variable warning

PATCH Applied Akihiko Odaki 3 participants 3 messages Oct 21, 2025 – Oct 23, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

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
index 1150bd14697c..d3968251fad5 100644
@@ -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]>
Reviewed-by on v2 1/1
#1 lore raw
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.

---

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
index 1150bd14697c..d3968251fad5 100644
@@ -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,
--
Akihiko Odaki <[email protected]>

#2 lore raw
In reply to Akihiko Odaki
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.

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
index 1150bd14697c..d3968251fad5 100644
@@ -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,
--
Akihiko Odaki <[email protected]>