diff mbox series

[2/2] hw/riscv/sifive_u: Resolve redundant property accessors

Message ID 20220217225351.140095-4-shentey@gmail.com (mailing list archive)
State New, archived
Headers show
Series Resolve some redundant property accessors | expand

Commit Message

Bernhard Beschow Feb. 17, 2022, 10:53 p.m. UTC
The QOM API already provides accessors for uint32 values, so reuse them.

Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 hw/riscv/sifive_u.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

Comments

Alistair Francis Feb. 21, 2022, 9:45 p.m. UTC | #1
On Fri, Feb 18, 2022 at 8:54 AM Bernhard Beschow <shentey@gmail.com> wrote:
>
> The QOM API already provides accessors for uint32 values, so reuse them.
>
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/riscv/sifive_u.c | 24 ++++--------------------
>  1 file changed, 4 insertions(+), 20 deletions(-)
>
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index 7fbc7dea42..747eb4ee89 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -713,36 +713,20 @@ static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error *
>      s->start_in_flash = value;
>  }
>
> -static void sifive_u_machine_get_uint32_prop(Object *obj, Visitor *v,
> -                                             const char *name, void *opaque,
> -                                             Error **errp)
> -{
> -    visit_type_uint32(v, name, (uint32_t *)opaque, errp);
> -}
> -
> -static void sifive_u_machine_set_uint32_prop(Object *obj, Visitor *v,
> -                                             const char *name, void *opaque,
> -                                             Error **errp)
> -{
> -    visit_type_uint32(v, name, (uint32_t *)opaque, errp);
> -}
> -
>  static void sifive_u_machine_instance_init(Object *obj)
>  {
>      SiFiveUState *s = RISCV_U_MACHINE(obj);
>
>      s->start_in_flash = false;
>      s->msel = 0;
> -    object_property_add(obj, "msel", "uint32",
> -                        sifive_u_machine_get_uint32_prop,
> -                        sifive_u_machine_set_uint32_prop, NULL, &s->msel);
> +    object_property_add_uint32_ptr(obj, "msel", &s->msel,
> +                                   OBJ_PROP_FLAG_READWRITE);
>      object_property_set_description(obj, "msel",
>                                      "Mode Select (MSEL[3:0]) pin state");
>
>      s->serial = OTP_SERIAL;
> -    object_property_add(obj, "serial", "uint32",
> -                        sifive_u_machine_get_uint32_prop,
> -                        sifive_u_machine_set_uint32_prop, NULL, &s->serial);
> +    object_property_add_uint32_ptr(obj, "serial", &s->serial,
> +                                   OBJ_PROP_FLAG_READWRITE);
>      object_property_set_description(obj, "serial", "Board serial number");
>  }
>
> --
> 2.35.1
>
>
Philippe Mathieu-Daudé Feb. 21, 2022, 10:26 p.m. UTC | #2
On 17/2/22 23:53, Bernhard Beschow wrote:
> The QOM API already provides accessors for uint32 values, so reuse them.
> 
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
>   hw/riscv/sifive_u.c | 24 ++++--------------------
>   1 file changed, 4 insertions(+), 20 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff mbox series

Patch

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 7fbc7dea42..747eb4ee89 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -713,36 +713,20 @@  static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error *
     s->start_in_flash = value;
 }
 
-static void sifive_u_machine_get_uint32_prop(Object *obj, Visitor *v,
-                                             const char *name, void *opaque,
-                                             Error **errp)
-{
-    visit_type_uint32(v, name, (uint32_t *)opaque, errp);
-}
-
-static void sifive_u_machine_set_uint32_prop(Object *obj, Visitor *v,
-                                             const char *name, void *opaque,
-                                             Error **errp)
-{
-    visit_type_uint32(v, name, (uint32_t *)opaque, errp);
-}
-
 static void sifive_u_machine_instance_init(Object *obj)
 {
     SiFiveUState *s = RISCV_U_MACHINE(obj);
 
     s->start_in_flash = false;
     s->msel = 0;
-    object_property_add(obj, "msel", "uint32",
-                        sifive_u_machine_get_uint32_prop,
-                        sifive_u_machine_set_uint32_prop, NULL, &s->msel);
+    object_property_add_uint32_ptr(obj, "msel", &s->msel,
+                                   OBJ_PROP_FLAG_READWRITE);
     object_property_set_description(obj, "msel",
                                     "Mode Select (MSEL[3:0]) pin state");
 
     s->serial = OTP_SERIAL;
-    object_property_add(obj, "serial", "uint32",
-                        sifive_u_machine_get_uint32_prop,
-                        sifive_u_machine_set_uint32_prop, NULL, &s->serial);
+    object_property_add_uint32_ptr(obj, "serial", &s->serial,
+                                   OBJ_PROP_FLAG_READWRITE);
     object_property_set_description(obj, "serial", "Board serial number");
 }