Skip to contentSkip to conversation

hvf: Determine slot count from struct layout

PATCH Applied Alexander Graf 3 participants 3 messages Oct 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hvf: Determine slot count from struct layout

We can handle up to a static amount of memory slots, capped by the size of an internal array.

Let's make sure that array size is the only source of truth for the number of elements in that array.

---
 accel/hvf/hvf-accel-ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel/hvf/hvf-accel-ops.c +1 -1
index 6cbd2c3f97..2b2c411076 100644
@@ -321,7 +321,7 @@ static int hvf_accel_init(MachineState *ms)
 
     s = g_new0(HVFState, 1);
 
-    s->num_slots = 32;
+    s->num_slots = ARRAY_SIZE(s->slots);
     for (x = 0; x < s->num_slots; ++x) {
         s->slots[x].size = 0;
         s->slots[x].slot_id = x;
Signature · 1 line
2.30.1 (Apple Git-130)
#2 lore raw
In reply to Alexander Graf
Quoted 17 lines · Alexander Graf

We can handle up to a static amount of memory slots, capped by the size of an internal array.

Let's make sure that array size is the only source of truth for the number of elements in that array.

---
  accel/hvf/hvf-accel-ops.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
accel/hvf/hvf-accel-ops.c +0 -0
index 6cbd2c3f97..2b2c411076 100644

accel/hvf/hvf-accel-ops.c static int hvf_accel_init(MachineState *ms) · line 327

Quoted 8 lines
accel/hvf/hvf-accel-ops.c +1 -1
@@ -321,7 +321,7 @@ static int hvf_accel_init(MachineState *ms)
 
      s = g_new0(HVFState, 1);
 
-    s->num_slots = 32;
+    s->num_slots = ARRAY_SIZE(s->slots);
      for (x = 0; x < s->num_slots; ++x) {
          s->slots[x].size = 0;
          s->slots[x].slot_id = x;

Queued, thanks.

Paolo