diff mbox series

[09/11] hw/rx/rx62n: Use qdev_prop_set_array()

Message ID 20230908143703.172758-10-kwolf@redhat.com
State New
Headers show
Series qdev: Make array properties user accessible again | expand

Commit Message

Kevin Wolf Sept. 8, 2023, 2:37 p.m. UTC
Instead of manually setting "foo-len" and "foo[i]" properties, build a
QList and use the new qdev_prop_set_array() helper to set the whole
array property with a single call.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 hw/rx/rx62n.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Peter Maydell Sept. 11, 2023, 3:50 p.m. UTC | #1
On Fri, 8 Sept 2023 at 15:37, Kevin Wolf <kwolf@redhat.com> wrote:
>
> Instead of manually setting "foo-len" and "foo[i]" properties, build a
> QList and use the new qdev_prop_set_array() helper to set the whole
> array property with a single call.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  hw/rx/rx62n.c | 19 ++++++++++---------

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Philippe Mathieu-Daudé Sept. 11, 2023, 8:52 p.m. UTC | #2
On 8/9/23 16:37, Kevin Wolf wrote:
> Instead of manually setting "foo-len" and "foo[i]" properties, build a
> QList and use the new qdev_prop_set_array() helper to set the whole
> array property with a single call.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>   hw/rx/rx62n.c | 19 ++++++++++---------
>   1 file changed, 10 insertions(+), 9 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Markus Armbruster Sept. 22, 2023, 1:59 p.m. UTC | #3
Kevin Wolf <kwolf@redhat.com> writes:

> Instead of manually setting "foo-len" and "foo[i]" properties, build a
> QList and use the new qdev_prop_set_array() helper to set the whole
> array property with a single call.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  hw/rx/rx62n.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/hw/rx/rx62n.c b/hw/rx/rx62n.c
> index 3e887a0fc7..6990096642 100644
> --- a/hw/rx/rx62n.c
> +++ b/hw/rx/rx62n.c
> @@ -28,6 +28,7 @@
>  #include "hw/sysbus.h"
>  #include "hw/qdev-properties.h"
>  #include "sysemu/sysemu.h"
> +#include "qapi/qmp/qlist.h"
>  #include "qom/object.h"
>  
>  /*
> @@ -130,22 +131,22 @@ static void register_icu(RX62NState *s)
>  {
>      int i;
>      SysBusDevice *icu;
> +    QList *ipr_map, *trigger_level;
>  
>      object_initialize_child(OBJECT(s), "icu", &s->icu, TYPE_RX_ICU);
>      icu = SYS_BUS_DEVICE(&s->icu);
> -    qdev_prop_set_uint32(DEVICE(icu), "len-ipr-map", NR_IRQS);
> +
> +    ipr_map = qlist_new();
>      for (i = 0; i < NR_IRQS; i++) {
> -        char propname[32];
> -        snprintf(propname, sizeof(propname), "ipr-map[%d]", i);
> -        qdev_prop_set_uint32(DEVICE(icu), propname, ipr_table[i]);
> +        qlist_append_int(ipr_map, ipr_table[i]);
>      }
> -    qdev_prop_set_uint32(DEVICE(icu), "len-trigger-level",
> -                         ARRAY_SIZE(levelirq));
> +    qdev_prop_set_array(sysctl, "ipr-map", ipr_map);

../hw/rx/rx62n.c:143:25: error: ‘sysctl’ undeclared (first use in this function); did you mean ‘syscall’?

Should be DEVICE(icu), I guess.

> +
> +    trigger_level = qlist_new();
>      for (i = 0; i < ARRAY_SIZE(levelirq); i++) {
> -        char propname[32];
> -        snprintf(propname, sizeof(propname), "trigger-level[%d]", i);
> -        qdev_prop_set_uint32(DEVICE(icu), propname, levelirq[i]);
> +        qlist_append_int(trigger_level, levelirq[i]);
>      }
> +    qdev_prop_set_array(sysctl, "trigger-level", trigger_level);

Again.

>  
>      for (i = 0; i < NR_IRQS; i++) {
>          s->irq[i] = qdev_get_gpio_in(DEVICE(icu), i);
diff mbox series

Patch

diff --git a/hw/rx/rx62n.c b/hw/rx/rx62n.c
index 3e887a0fc7..6990096642 100644
--- a/hw/rx/rx62n.c
+++ b/hw/rx/rx62n.c
@@ -28,6 +28,7 @@ 
 #include "hw/sysbus.h"
 #include "hw/qdev-properties.h"
 #include "sysemu/sysemu.h"
+#include "qapi/qmp/qlist.h"
 #include "qom/object.h"
 
 /*
@@ -130,22 +131,22 @@  static void register_icu(RX62NState *s)
 {
     int i;
     SysBusDevice *icu;
+    QList *ipr_map, *trigger_level;
 
     object_initialize_child(OBJECT(s), "icu", &s->icu, TYPE_RX_ICU);
     icu = SYS_BUS_DEVICE(&s->icu);
-    qdev_prop_set_uint32(DEVICE(icu), "len-ipr-map", NR_IRQS);
+
+    ipr_map = qlist_new();
     for (i = 0; i < NR_IRQS; i++) {
-        char propname[32];
-        snprintf(propname, sizeof(propname), "ipr-map[%d]", i);
-        qdev_prop_set_uint32(DEVICE(icu), propname, ipr_table[i]);
+        qlist_append_int(ipr_map, ipr_table[i]);
     }
-    qdev_prop_set_uint32(DEVICE(icu), "len-trigger-level",
-                         ARRAY_SIZE(levelirq));
+    qdev_prop_set_array(sysctl, "ipr-map", ipr_map);
+
+    trigger_level = qlist_new();
     for (i = 0; i < ARRAY_SIZE(levelirq); i++) {
-        char propname[32];
-        snprintf(propname, sizeof(propname), "trigger-level[%d]", i);
-        qdev_prop_set_uint32(DEVICE(icu), propname, levelirq[i]);
+        qlist_append_int(trigger_level, levelirq[i]);
     }
+    qdev_prop_set_array(sysctl, "trigger-level", trigger_level);
 
     for (i = 0; i < NR_IRQS; i++) {
         s->irq[i] = qdev_get_gpio_in(DEVICE(icu), i);