Skip to content

Commit a828ba9

Browse files
philmdalistair23
authored andcommitted
hw/riscv/opentitan: Correct OpenTitanState parent type/size
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(). Fixes: fe0fe47 ("riscv: Initial commit of OpenTitan machine") Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent 8696b74 commit a828ba9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

hw/riscv/opentitan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {
7878
static void opentitan_machine_init(MachineState *machine)
7979
{
8080
MachineClass *mc = MACHINE_GET_CLASS(machine);
81+
OpenTitanState *s = OPENTITAN_MACHINE(machine);
8182
const MemMapEntry *memmap = ibex_memmap;
82-
OpenTitanState *s = g_new0(OpenTitanState, 1);
8383
MemoryRegion *sys_mem = get_system_memory();
8484

8585
if (machine->ram_size != mc->default_ram_size) {
@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = {
330330
}, {
331331
.name = TYPE_OPENTITAN_MACHINE,
332332
.parent = TYPE_MACHINE,
333+
.instance_size = sizeof(OpenTitanState),
333334
.class_init = opentitan_machine_class_init,
334335
}
335336
};

include/hw/riscv/opentitan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState {
5555
};
5656

5757
#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
58+
OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE)
5859

5960
typedef struct OpenTitanState {
6061
/*< private >*/
61-
SysBusDevice parent_obj;
62+
MachineState parent_obj;
6263

6364
/*< public >*/
6465
LowRISCIbexSoCState soc;

0 commit comments

Comments
 (0)