From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
The code inside riscv_cpu_add_user_properties() became quite repetitive
after recent changes. Add a helper to hide the repetition away.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20230901194627.1214811-8-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 86d536f242..d484d63bcd 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1951,6 +1951,15 @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
}
#endif
+static void riscv_cpu_add_qdev_prop_array(DeviceState *dev, Property *array)
+{
+ g_assert(array);
+
+ for (Property *prop = array; prop && prop->name; prop++) {
+ qdev_property_add_static(dev, prop);
+ }
+}
+
#ifndef CONFIG_USER_ONLY
static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name)
{
@@ -2007,7 +2016,6 @@ static void riscv_cpu_add_kvm_properties(Object *obj)
*/
static void riscv_cpu_add_user_properties(Object *obj)
{
- Property *prop;
DeviceState *dev = DEVICE(obj);
#ifndef CONFIG_USER_ONLY
@@ -2021,21 +2029,10 @@ static void riscv_cpu_add_user_properties(Object *obj)
riscv_cpu_add_misa_properties(obj);
- for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
- qdev_property_add_static(dev, prop);
- }
-
- for (prop = riscv_cpu_options; prop && prop->name; prop++) {
- qdev_property_add_static(dev, prop);
- }
-
- for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) {
- qdev_property_add_static(dev, prop);
- }
-
- for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
- qdev_property_add_static(dev, prop);
- }
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_extensions);
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_options);
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_vendor_exts);
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_experimental_exts);
}
static Property riscv_cpu_properties[] = {
--
2.41.0