Skip to content

Commit

Permalink
hw/riscv/opentitan: Correct OpenTitanState parent type/size
Browse files Browse the repository at this point in the history
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é <philmd@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Message-Id: <20230520054510.68822-6-philmd@linaro.org>
  • Loading branch information
philmd authored and alistair23 committed Jun 2, 2023
1 parent ea3e579 commit 218eda3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hw/riscv/opentitan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
}
};
Expand Down
3 changes: 2 additions & 1 deletion include/hw/riscv/opentitan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 218eda3

Please sign in to comment.