On Wed, Sep 20, 2023 at 10:46 PM Daniel Henrique Barboza <dbarb...@ventanamicro.com> wrote: > > The array isn't marked as 'const' because we're initializing their > elements in riscv_cpu_add_misa_properties(), 'name' and 'description' > fields. > > In a closer look we can see that we're not using these 2 fields after > creating the MISA properties. And we can create the properties by using > riscv_get_misa_ext_name() and riscv_get_misa_ext_description() > directly. > > Remove the 'name' and 'description' fields from RISCVCPUMisaExtConfig > and make misa_ext_cfgs[] a const array. > > Signed-off-by: Daniel Henrique Barboza <dbarb...@ventanamicro.com> > Reviewed-by: Andrew Jones <ajo...@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.fran...@wdc.com> Alistair > --- > target/riscv/cpu.c | 21 ++++++++------------- > 1 file changed, 8 insertions(+), 13 deletions(-) > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c > index 8616c9e2f5..4875feded7 100644 > --- a/target/riscv/cpu.c > +++ b/target/riscv/cpu.c > @@ -1212,8 +1212,6 @@ static void riscv_cpu_init(Object *obj) > } > > typedef struct RISCVCPUMisaExtConfig { > - const char *name; > - const char *description; > target_ulong misa_bit; > bool enabled; > } RISCVCPUMisaExtConfig; > @@ -1317,7 +1315,7 @@ const char *riscv_get_misa_ext_description(uint32_t bit) > #define MISA_CFG(_bit, _enabled) \ > {.misa_bit = _bit, .enabled = _enabled} > > -static RISCVCPUMisaExtConfig misa_ext_cfgs[] = { > +static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { > MISA_CFG(RVA, true), > MISA_CFG(RVC, true), > MISA_CFG(RVD, true), > @@ -1344,25 +1342,22 @@ void riscv_cpu_add_misa_properties(Object *cpu_obj) > int i; > > for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { > - RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; > + const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; > int bit = misa_cfg->misa_bit; > - > - misa_cfg->name = riscv_get_misa_ext_name(bit); > - misa_cfg->description = riscv_get_misa_ext_description(bit); > + const char *name = riscv_get_misa_ext_name(bit); > + const char *desc = riscv_get_misa_ext_description(bit); > > /* Check if KVM already created the property */ > - if (object_property_find(cpu_obj, misa_cfg->name)) { > + if (object_property_find(cpu_obj, name)) { > continue; > } > > - object_property_add(cpu_obj, misa_cfg->name, "bool", > + object_property_add(cpu_obj, name, "bool", > cpu_get_misa_ext_cfg, > cpu_set_misa_ext_cfg, > NULL, (void *)misa_cfg); > - object_property_set_description(cpu_obj, misa_cfg->name, > - misa_cfg->description); > - object_property_set_bool(cpu_obj, misa_cfg->name, > - misa_cfg->enabled, NULL); > + object_property_set_description(cpu_obj, name, desc); > + object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL); > } > } > > -- > 2.41.0 > >