[PATCH] hvf: Determine slot count from struct layout

Alexander Graf posted 1 patch 2 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20211008054616.43828-1-agraf@csgraf.de
Maintainers: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <r.bolshakov@yadro.com>
accel/hvf/hvf-accel-ops.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] hvf: Determine slot count from struct layout
Posted by Alexander Graf 2 years, 6 months ago
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.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 accel/hvf/hvf-accel-ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 6cbd2c3f97..2b2c411076 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -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;
-- 
2.30.1 (Apple Git-130)


Re: [PATCH] hvf: Determine slot count from struct layout
Posted by Richard Henderson 2 years, 6 months ago
On 10/7/21 10:46 PM, Alexander Graf wrote:
> 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.
> 
> Signed-off-by: Alexander Graf<agraf@csgraf.de>
> ---
>   accel/hvf/hvf-accel-ops.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

Re: [PATCH] hvf: Determine slot count from struct layout
Posted by Paolo Bonzini 2 years, 6 months ago
On 08/10/21 07:46, Alexander Graf wrote:
> 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.
> 
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> ---
>   accel/hvf/hvf-accel-ops.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
> index 6cbd2c3f97..2b2c411076 100644
> --- a/accel/hvf/hvf-accel-ops.c
> +++ b/accel/hvf/hvf-accel-ops.c
> @@ -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