diff mbox series

[7/7] sparc: Use FIELD_PTR at nwindows getter/setter

Message ID 20201104172512.2381656-8-ehabkost@redhat.com
State New
Headers show
Series qom: Field properties type safety | expand

Commit Message

Eduardo Habkost Nov. 4, 2020, 5:25 p.m. UTC
This makes the nwindows getter and setter more consistent with
the other field getters and setters (which work with any struct
field).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: Artyom Tarasenko <atar4qemu@gmail.com>
Cc: qemu-devel@nongnu.org
---
 target/sparc/cpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Mark Cave-Ayland Nov. 10, 2020, 1:04 p.m. UTC | #1
On 04/11/2020 17:25, Eduardo Habkost wrote:

> This makes the nwindows getter and setter more consistent with
> the other field getters and setters (which work with any struct
> field).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Cc: Artyom Tarasenko <atar4qemu@gmail.com>
> Cc: qemu-devel@nongnu.org
> ---
>   target/sparc/cpu.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index 3acc99c29c..8bf02a4fe0 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -789,8 +789,8 @@ static void sparc_cpu_initfn(Object *obj)
>   static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
>                                  Property *prop, Error **errp)
>   {
> -    SPARCCPU *cpu = SPARC_CPU(obj);
> -    int64_t value = cpu->env.def.nwindows;
> +    uint32_t *ptr = FIELD_PTR(obj, prop, uint32_t);
> +    int64_t value = *ptr;
>   
>       visit_type_int(v, name, &value, errp);
>   }
> @@ -798,9 +798,9 @@ static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
>   static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
>                                  Property *prop, Error **errp)
>   {
> +    uint32_t *ptr = FIELD_PTR(obj, prop, uint32_t);
>       const int64_t min = MIN_NWINDOWS;
>       const int64_t max = MAX_NWINDOWS;
> -    SPARCCPU *cpu = SPARC_CPU(obj);
>       int64_t value;
>   
>       if (!visit_type_int(v, name, &value, errp)) {
> @@ -814,7 +814,7 @@ static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
>                      value, min, max);
>           return;
>       }
> -    cpu->env.def.nwindows = value;
> +    *ptr = value;
>   }
>   
>   static PropertyInfo qdev_prop_nwindows = {

This looks correct to me:

Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.
diff mbox series

Patch

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 3acc99c29c..8bf02a4fe0 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -789,8 +789,8 @@  static void sparc_cpu_initfn(Object *obj)
 static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
                                Property *prop, Error **errp)
 {
-    SPARCCPU *cpu = SPARC_CPU(obj);
-    int64_t value = cpu->env.def.nwindows;
+    uint32_t *ptr = FIELD_PTR(obj, prop, uint32_t);
+    int64_t value = *ptr;
 
     visit_type_int(v, name, &value, errp);
 }
@@ -798,9 +798,9 @@  static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
 static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
                                Property *prop, Error **errp)
 {
+    uint32_t *ptr = FIELD_PTR(obj, prop, uint32_t);
     const int64_t min = MIN_NWINDOWS;
     const int64_t max = MAX_NWINDOWS;
-    SPARCCPU *cpu = SPARC_CPU(obj);
     int64_t value;
 
     if (!visit_type_int(v, name, &value, errp)) {
@@ -814,7 +814,7 @@  static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
                    value, min, max);
         return;
     }
-    cpu->env.def.nwindows = value;
+    *ptr = value;
 }
 
 static PropertyInfo qdev_prop_nwindows = {