hw/riscv/opentitan: Correct QOM type/size of OpenTitanState
cover hw/riscv/opentitan: Correct QOM type/size of OpenTitanState
Hi,
This series fix a QOM issue with the OpenTitanState structure, noticed while auditing QOM relations globally.
All patches are trivial to review.
Regards,
Phil.
Philippe Mathieu-Daudé (5):
hw/riscv/opentitan: Rename machine_[class]_init() functions hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition hw/riscv/opentitan: Explicit machine type definition hw/riscv/opentitan: Correct OpenTitanState parent type/size
include/hw/riscv/opentitan.h | 6 +++++- hw/riscv/opentitan.c | 38 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/5 hw/riscv/opentitan: Rename machine_[class]_init() functions
Follow QOM style which declares FOO_init() as instance initializer and FOO_class_init() as class initializer:
rename the OpenTitan machine class/instance init() accordingly.
--- hw/riscv/opentitan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/opentitan.c +4 -4
@@ -75,7 +75,7 @@ static const MemMapEntry ibex_memmap[] = { [IBEX_DEV_FLASH_VIRTUAL] = { 0x80000000, 0x80000 }, }; -static void opentitan_board_init (MachineState *machine) +static void opentitan_machine_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);const MemMapEntry *memmap = ibex_memmap;
@@ -108,17 +108,17 @@ static void opentitan_board_init(MachineState *machine) } } -static void opentitan_machine_init (MachineClass *mc) +static void opentitan_machine_class_init (MachineClass *mc) { mc->desc ="RISC-V Board compatible with OpenTitan" ; - mc->init = opentitan_board_init; + mc->init = opentitan_machine_init; mc->max_cpus =1 ; mc->default_cpu_type =TYPE_RISCV_CPU_IBEX ; mc->default_ram_id ="riscv.lowrisc.ibex.ram" ; mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE("opentitan", opentitan_machine_init) +DEFINE_MACHINE("opentitan", opentitan_machine_class_init)static void lowrisc_ibex_soc_init (Object *obj) {
Signature · 1 line
2.38.1
Re: [PATCH 1/5] hw/riscv/opentitan: Rename machine_[class]_init() functions
Quoted 7 lines · Philippe Mathieu-Daudé
Follow QOM style which declares
FOO_init()as instance initializer andFOO_class_init()as class initializer:
rename the OpenTitan machine class/instanceinit()accordingly.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 37 lines
hw/riscv/opentitan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/riscv/opentitan.c +4
-4@@ -75,7 +75,7 @@ static const MemMapEntry ibex_memmap[] = { [IBEX_DEV_FLASH_VIRTUAL] = { 0x80000000, 0x80000 }, }; -static void opentitan_board_init (MachineState *machine) +static void opentitan_machine_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);const MemMapEntry *memmap = ibex_memmap;@@ -108,17 +108,17 @@ static void opentitan_board_init(MachineState *machine) } } -static void opentitan_machine_init (MachineClass *mc) +static void opentitan_machine_class_init (MachineClass *mc) { mc->desc ="RISC-V Board compatible with OpenTitan" ; - mc->init = opentitan_board_init; + mc->init = opentitan_machine_init; mc->max_cpus =1 ; mc->default_cpu_type =TYPE_RISCV_CPU_IBEX ; mc->default_ram_id ="riscv.lowrisc.ibex.ram" ; mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE("opentitan", opentitan_machine_init) +DEFINE_MACHINE("opentitan", opentitan_machine_class_init)static void lowrisc_ibex_soc_init (Object *obj) {
Re: [PATCH 1/5] hw/riscv/opentitan: Rename machine_[class]_init() functions
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
Follow QOM style which declares
FOO_init()as instance initializer andFOO_class_init()as class initializer:
rename the OpenTitan machine class/instanceinit()accordingly.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 42 lines
--- hw/riscv/opentitan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/riscv/opentitan.c +4
-5@@ -75,7 +75,7 @@ static const MemMapEntry ibex_memmap[] = { [IBEX_DEV_FLASH_VIRTUAL] = { 0x80000000, 0x80000 }, }; -static void opentitan_board_init (MachineState *machine) +static void opentitan_machine_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine);const MemMapEntry *memmap = ibex_memmap;@@ -108,17 +108,17 @@ static void opentitan_board_init(MachineState *machine) } } -static void opentitan_machine_init (MachineClass *mc) +static void opentitan_machine_class_init (MachineClass *mc) { mc->desc ="RISC-V Board compatible with OpenTitan" ; - mc->init = opentitan_board_init; + mc->init = opentitan_machine_init; mc->max_cpus =1 ; mc->default_cpu_type =TYPE_RISCV_CPU_IBEX ; mc->default_ram_id ="riscv.lowrisc.ibex.ram" ; mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE("opentitan", opentitan_machine_init) +DEFINE_MACHINE("opentitan", opentitan_machine_class_init)static void lowrisc_ibex_soc_init (Object *obj) { --2.38.1
PATCH 2/5 hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro
In reply to Philippe Mathieu-DaudéWhen multiple QOM types are registered in the same file, it is simpler to use the the DEFINE_TYPES() macro. Replace the type_init() / type_register_static() combination. This is in preparation of adding the OpenTitan machine type to this array in a pair of commits.
--- hw/riscv/opentitan.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
hw/riscv/opentitan.c +9 -12
@@ -320,17 +320,14 @@ static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data) dc->user_creatable = false; } -static const TypeInfo lowrisc_ibex_soc_type_info = { - .name =TYPE_RISCV_IBEX_SOC , - .parent =TYPE_DEVICE , - .instance_size =sizeof (LowRISCIbexSoCState), - .instance_init = lowrisc_ibex_soc_init, - .class_init = lowrisc_ibex_soc_class_init, +static const TypeInfo open_titan_types[] = { + { + .name =TYPE_RISCV_IBEX_SOC , + .parent =TYPE_DEVICE , + .instance_size =sizeof (LowRISCIbexSoCState), + .instance_init = lowrisc_ibex_soc_init, + .class_init = lowrisc_ibex_soc_class_init, + } }; -static void lowrisc_ibex_soc_register_types (void ) -{ -type_register_static (&lowrisc_ibex_soc_type_info); -} - -type_init (lowrisc_ibex_soc_register_types) +DEFINE_TYPES (open_titan_types)
Signature · 1 line
2.38.1
Re: [PATCH 2/5] hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro
Quoted 5 lines · Philippe Mathieu-Daudé
When multiple QOM types are registered in the same file, it is simpler to use the the
DEFINE_TYPES()macro. Replace thetype_init()/type_register_static()combination. This is in preparation of adding the OpenTitan machine type to this array in a pair of commits.
I wonder whether we should forbid type_init()/type_register_static() and force everyone to use DEFINE_TYPES(). We need less options when dealing with QOM.
Quoted 37 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/riscv/opentitan.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)hw/riscv/opentitan.c +9
-12@@ -320,17 +320,14 @@ static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data) dc->user_creatable = false; } -static const TypeInfo lowrisc_ibex_soc_type_info = { - .name =TYPE_RISCV_IBEX_SOC , - .parent =TYPE_DEVICE , - .instance_size =sizeof (LowRISCIbexSoCState), - .instance_init = lowrisc_ibex_soc_init, - .class_init = lowrisc_ibex_soc_class_init, +static const TypeInfo open_titan_types[] = { + { + .name =TYPE_RISCV_IBEX_SOC , + .parent =TYPE_DEVICE , + .instance_size =sizeof (LowRISCIbexSoCState), + .instance_init = lowrisc_ibex_soc_init, + .class_init = lowrisc_ibex_soc_class_init, + } }; -static void lowrisc_ibex_soc_register_types (void ) -{ -type_register_static (&lowrisc_ibex_soc_type_info); -} - -type_init (lowrisc_ibex_soc_register_types) +DEFINE_TYPES (open_titan_types)
Re: [PATCH 2/5] hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
When multiple QOM types are registered in the same file, it is simpler to use the the
DEFINE_TYPES()macro. Replace thetype_init()/type_register_static()combination. This is in preparation of adding the OpenTitan machine type to this array in a pair of commits.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 39 lines
--- hw/riscv/opentitan.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)hw/riscv/opentitan.c +9
-13@@ -320,17 +320,14 @@ static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data) dc->user_creatable = false; } -static const TypeInfo lowrisc_ibex_soc_type_info = { - .name =TYPE_RISCV_IBEX_SOC , - .parent =TYPE_DEVICE , - .instance_size =sizeof (LowRISCIbexSoCState), - .instance_init = lowrisc_ibex_soc_init, - .class_init = lowrisc_ibex_soc_class_init, +static const TypeInfo open_titan_types[] = { + { + .name =TYPE_RISCV_IBEX_SOC , + .parent =TYPE_DEVICE , + .instance_size =sizeof (LowRISCIbexSoCState), + .instance_init = lowrisc_ibex_soc_init, + .class_init = lowrisc_ibex_soc_class_init, + } }; -static void lowrisc_ibex_soc_register_types (void ) -{ -type_register_static (&lowrisc_ibex_soc_type_info); -} - -type_init (lowrisc_ibex_soc_register_types) +DEFINE_TYPES (open_titan_types) --2.38.1
PATCH 3/5 hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition
In reply to Philippe Mathieu-DaudéQOM type names are usually defined as TYPE_FOO.
--- include/hw/riscv/opentitan.h | 2 ++ hw/riscv/opentitan.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/hw/riscv/opentitan.h +2 -0
@@ -53,6 +53,8 @@ struct LowRISCIbexSoCState {MemoryRegion flash_alias; }; +#define TYPE_OPENTITAN_MACHINE "opentitan" + typedef struct OpenTitanState { /*< private >*/ SysBusDevice parent_obj;
hw/riscv/opentitan.c +1 -1
@@ -118,7 +118,7 @@ static void opentitan_machine_class_init(MachineClass *mc) mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE("opentitan", opentitan_machine_class_init) +DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)static void lowrisc_ibex_soc_init (Object *obj) {
Signature · 1 line
2.38.1
Re: [PATCH 3/5] hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition
Quoted 4 lines · Philippe Mathieu-Daudé
QOM type names are usually defined as
TYPE_FOO.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 30 lines
include/hw/riscv/opentitan.h | 2 ++ hw/riscv/opentitan.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/hw/riscv/opentitan.h +2
-0@@ -53,6 +53,8 @@ struct LowRISCIbexSoCState {MemoryRegion flash_alias; }; +#define TYPE_OPENTITAN_MACHINE "opentitan" + typedef struct OpenTitanState { /*< private >*/ SysBusDevice parent_obj;hw/riscv/opentitan.c +1
-1@@ -118,7 +118,7 @@ static void opentitan_machine_class_init(MachineClass *mc) mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE("opentitan", opentitan_machine_class_init) +DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)static void lowrisc_ibex_soc_init (Object *obj) {
Re: [PATCH 3/5] hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
QOM type names are usually defined as
TYPE_FOO.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 35 lines
--- include/hw/riscv/opentitan.h | 2 ++ hw/riscv/opentitan.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/hw/riscv/opentitan.h +2
-0@@ -53,6 +53,8 @@ struct LowRISCIbexSoCState {MemoryRegion flash_alias; }; +#define TYPE_OPENTITAN_MACHINE "opentitan" + typedef struct OpenTitanState { /*< private >*/ SysBusDevice parent_obj;hw/riscv/opentitan.c +1
-2@@ -118,7 +118,7 @@ static void opentitan_machine_class_init(MachineClass *mc) mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE("opentitan", opentitan_machine_class_init) +DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)static void lowrisc_ibex_soc_init (Object *obj) { --2.38.1
PATCH 4/5 hw/riscv/opentitan: Explicit machine type definition
In reply to Philippe Mathieu-DaudéExpand the DEFINE_MACHINE() macro, converting the class_init() handler.
--- include/hw/riscv/opentitan.h | 3 ++- hw/riscv/opentitan.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
include/hw/riscv/opentitan.h +2 -1
@@ -24,6 +24,7 @@#include "hw/char/ibex_uart.h" #include "hw/timer/ibex_timer.h" #include "hw/ssi/ibex_spi_host.h" +#include "hw/boards.h" #include "qom/object.h" #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"
@@ -53,7 +54,7 @@ struct LowRISCIbexSoCState {MemoryRegion flash_alias; }; -#define TYPE_OPENTITAN_MACHINE "opentitan" +#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan") typedef struct OpenTitanState { /*< private >*/
hw/riscv/opentitan.c +7 -3
@@ -108,8 +108,10 @@ static void opentitan_machine_init(MachineState *machine) } } -static void opentitan_machine_class_init (MachineClass *mc) +static void opentitan_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="RISC-V Board compatible with OpenTitan" ; mc->init = opentitan_machine_init; mc->max_cpus =1 ;
@@ -118,8 +120,6 @@ static void opentitan_machine_class_init(MachineClass *mc) mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init) -static void lowrisc_ibex_soc_init (Object *obj) {LowRISCIbexSoCState *s =RISCV_IBEX_SOC (obj);
@@ -327,6 +327,10 @@ static const TypeInfo open_titan_types[] = { .instance_size = sizeof(LowRISCIbexSoCState), .instance_init = lowrisc_ibex_soc_init, .class_init = lowrisc_ibex_soc_class_init, + }, { + .name = TYPE_OPENTITAN_MACHINE, + .parent = TYPE_MACHINE, + .class_init = opentitan_machine_class_init, } };
Signature · 1 line
2.38.1
Re: [PATCH 4/5] hw/riscv/opentitan: Explicit machine type definition
Quoted 5 lines · Philippe Mathieu-Daudé
Expand the
DEFINE_MACHINE()macro, converting theclass_init()handler.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 61 lines
include/hw/riscv/opentitan.h | 3 ++- hw/riscv/opentitan.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)include/hw/riscv/opentitan.h +2
-1@@ -24,6 +24,7 @@#include "hw/char/ibex_uart.h" #include "hw/timer/ibex_timer.h" #include "hw/ssi/ibex_spi_host.h" +#include "hw/boards.h" #include "qom/object.h" #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"@@ -53,7 +54,7 @@ struct LowRISCIbexSoCState {MemoryRegion flash_alias; }; -#define TYPE_OPENTITAN_MACHINE "opentitan" +#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan") typedef struct OpenTitanState { /*< private >*/hw/riscv/opentitan.c +7
-3@@ -108,8 +108,10 @@ static void opentitan_machine_init(MachineState *machine) } } -static void opentitan_machine_class_init (MachineClass *mc) +static void opentitan_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="RISC-V Board compatible with OpenTitan" ; mc->init = opentitan_machine_init; mc->max_cpus =1 ;@@ -118,8 +120,6 @@ static void opentitan_machine_class_init(MachineClass *mc) mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init) -static void lowrisc_ibex_soc_init (Object *obj) {LowRISCIbexSoCState *s =RISCV_IBEX_SOC (obj);@@ -327,6 +327,10 @@ static const TypeInfo open_titan_types[] = { .instance_size = sizeof(LowRISCIbexSoCState), .instance_init = lowrisc_ibex_soc_init, .class_init = lowrisc_ibex_soc_class_init, + }, { + .name = TYPE_OPENTITAN_MACHINE, + .parent = TYPE_MACHINE, + .class_init = opentitan_machine_class_init, } };
Re: [PATCH 4/5] hw/riscv/opentitan: Explicit machine type definition
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Expand the
DEFINE_MACHINE()macro, converting theclass_init()handler.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 66 lines
--- include/hw/riscv/opentitan.h | 3 ++- hw/riscv/opentitan.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)include/hw/riscv/opentitan.h +2
-1@@ -24,6 +24,7 @@#include "hw/char/ibex_uart.h" #include "hw/timer/ibex_timer.h" #include "hw/ssi/ibex_spi_host.h" +#include "hw/boards.h" #include "qom/object.h" #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"@@ -53,7 +54,7 @@ struct LowRISCIbexSoCState {MemoryRegion flash_alias; }; -#define TYPE_OPENTITAN_MACHINE "opentitan" +#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan") typedef struct OpenTitanState { /*< private >*/hw/riscv/opentitan.c +7
-4@@ -108,8 +108,10 @@ static void opentitan_machine_init(MachineState *machine) } } -static void opentitan_machine_class_init (MachineClass *mc) +static void opentitan_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="RISC-V Board compatible with OpenTitan" ; mc->init = opentitan_machine_init; mc->max_cpus =1 ;@@ -118,8 +120,6 @@ static void opentitan_machine_class_init(MachineClass *mc) mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM ].size; } -DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init) -static void lowrisc_ibex_soc_init (Object *obj) {LowRISCIbexSoCState *s =RISCV_IBEX_SOC (obj);@@ -327,6 +327,10 @@ static const TypeInfo open_titan_types[] = { .instance_size = sizeof(LowRISCIbexSoCState), .instance_init = lowrisc_ibex_soc_init, .class_init = lowrisc_ibex_soc_class_init, + }, { + .name = TYPE_OPENTITAN_MACHINE, + .parent = TYPE_MACHINE, + .class_init = opentitan_machine_class_init, } }; --2.38.1
PATCH 5/5 hw/riscv/opentitan: Correct OpenTitanState parent type/size
In reply to Philippe Mathieu-DaudéOpenTitanState is the 'machine' (or 'board') state: it isn't a SysBus device, but inherits from the MachineState type. Correct the instance size.
Doing so we avoid leaking an OpenTitanState pointer in opentitan_machine_init().
--- include/hw/riscv/opentitan.h | 3 ++- hw/riscv/opentitan.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
include/hw/riscv/opentitan.h +2 -1
@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState { };#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan") +OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE) typedef struct OpenTitanState { /*< private >*/ - SysBusDevice parent_obj; + MachineState parent_obj; /*< public >*/ LowRISCIbexSoCState soc;
hw/riscv/opentitan.c +2 -1
@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {static void opentitan_machine_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine); +OpenTitanState *s =OPENTITAN_MACHINE (machine);const MemMapEntry *memmap = ibex_memmap; -OpenTitanState *s =g_new0 (OpenTitanState,1 );MemoryRegion *sys_mem =get_system_memory ();if (machine->ram_size != mc->default_ram_size) {
@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = { }, { .name = TYPE_OPENTITAN_MACHINE, .parent = TYPE_MACHINE, + .instance_size = sizeof(OpenTitanState), .class_init = opentitan_machine_class_init, } };
Signature · 1 line
2.38.1
Re: [PATCH 5/5] hw/riscv/opentitan: Correct OpenTitanState parent type/size
Quoted 9 lines · Philippe Mathieu-Daudé
OpenTitanState is the 'machine' (or 'board') state: it isn't a SysBus device, but inherits from the MachineState type. Correct the instance size.
Doing so we avoid leaking an OpenTitanState pointer inopentitan_machine_init().Fixes fe0fe4735e ("riscv: Initial commit of OpenTitan machine")Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 43 lines
include/hw/riscv/opentitan.h | 3 ++- hw/riscv/opentitan.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)include/hw/riscv/opentitan.h +2
-1@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState { };#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan") +OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE) typedef struct OpenTitanState { /*< private >*/ - SysBusDevice parent_obj; + MachineState parent_obj; /*< public >*/ LowRISCIbexSoCState soc;hw/riscv/opentitan.c +2
-1@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {static void opentitan_machine_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine); +OpenTitanState *s =OPENTITAN_MACHINE (machine);const MemMapEntry *memmap = ibex_memmap; -OpenTitanState *s =g_new0 (OpenTitanState,1 );MemoryRegion *sys_mem =get_system_memory ();if (machine->ram_size != mc->default_ram_size) {@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = { }, { .name = TYPE_OPENTITAN_MACHINE, .parent = TYPE_MACHINE, + .instance_size = sizeof(OpenTitanState), .class_init = opentitan_machine_class_init, } };
Re: [PATCH 5/5] hw/riscv/opentitan: Correct OpenTitanState parent type/size
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
OpenTitanState is the 'machine' (or 'board') state: it isn't a SysBus device, but inherits from the MachineState type. Correct the instance size.
Doing so we avoid leaking an OpenTitanState pointer inopentitan_machine_init().Fixes fe0fe4735e ("riscv: Initial commit of OpenTitan machine")Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 48 lines
--- include/hw/riscv/opentitan.h | 3 ++- hw/riscv/opentitan.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)include/hw/riscv/opentitan.h +2
-1@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState { };#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan") +OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE) typedef struct OpenTitanState { /*< private >*/ - SysBusDevice parent_obj; + MachineState parent_obj; /*< public >*/ LowRISCIbexSoCState soc;hw/riscv/opentitan.c +2
-2@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {static void opentitan_machine_init (MachineState *machine) {MachineClass *mc =MACHINE_GET_CLASS (machine); +OpenTitanState *s =OPENTITAN_MACHINE (machine);const MemMapEntry *memmap = ibex_memmap; -OpenTitanState *s =g_new0 (OpenTitanState,1 );MemoryRegion *sys_mem =get_system_memory ();if (machine->ram_size != mc->default_ram_size) {@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = { }, { .name = TYPE_OPENTITAN_MACHINE, .parent = TYPE_MACHINE, + .instance_size = sizeof(OpenTitanState), .class_init = opentitan_machine_class_init, } }; --2.38.1
Alistair Francis
AppliedQuoted 10 lines · Philippe Mathieu-Daudé
Hi,
This series fix a QOM issue with the OpenTitanState structure, noticed while auditing QOM relations globally.
All patches are trivial to review.
Regards,
Quoted 8 lines
Phil.
Philippe Mathieu-Daudé (5):
hw/riscv/opentitan: Rename machine_[class]_init() functions hw/riscv/opentitan: Declare QOM types usingDEFINE_TYPES()macro hw/riscv/opentitan: AddTYPE_OPENTITAN_MACHINEdefinition hw/riscv/opentitan: Explicit machine type definition hw/riscv/opentitan: Correct OpenTitanState parent type/size
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 9 lines
include/hw/riscv/opentitan.h | 6 +++++- hw/riscv/opentitan.c | 38 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-)--
2.38.1