From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 02/11] hw/arm/collie: Put StrongARMState* into a CollieMachineState struct
Date: Mon, 6 Apr 2020 11:11:56 +0100 [thread overview]
Message-ID: <20200406101205.23027-3-peter.maydell@linaro.org> (raw)
In-Reply-To: <20200406101205.23027-1-peter.maydell@linaro.org>
Coverity complains that the collie_init() function leaks the memory
allocated in sa1110_init(). This is true but not significant since
the function is called only once on machine init and the memory must
remain in existence until QEMU exits anyway.
Still, we can avoid the technical memory leak by keeping the pointer
to the StrongARMState inside the machine state struct. Switch from
the simple DEFINE_MACHINE() style to defining a subclass of
TYPE_MACHINE which extends the MachineState struct, and keep the
pointer there.
Fixes: CID 1421921
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200326204919.22006-1-peter.maydell@linaro.org
---
hw/arm/collie.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/hw/arm/collie.c b/hw/arm/collie.c
index 4992084a3f6..4b35ef4bed6 100644
--- a/hw/arm/collie.c
+++ b/hw/arm/collie.c
@@ -19,6 +19,16 @@
#include "exec/address-spaces.h"
#include "cpu.h"
+typedef struct {
+ MachineState parent;
+
+ StrongARMState *sa1110;
+} CollieMachineState;
+
+#define TYPE_COLLIE_MACHINE MACHINE_TYPE_NAME("collie")
+#define COLLIE_MACHINE(obj) \
+ OBJECT_CHECK(CollieMachineState, obj, TYPE_COLLIE_MACHINE)
+
static struct arm_boot_info collie_binfo = {
.loader_start = SA_SDCS0,
.ram_size = 0x20000000,
@@ -26,9 +36,9 @@ static struct arm_boot_info collie_binfo = {
static void collie_init(MachineState *machine)
{
- StrongARMState *s;
DriveInfo *dinfo;
MachineClass *mc = MACHINE_GET_CLASS(machine);
+ CollieMachineState *cms = COLLIE_MACHINE(machine);
if (machine->ram_size != mc->default_ram_size) {
char *sz = size_to_str(mc->default_ram_size);
@@ -37,7 +47,7 @@ static void collie_init(MachineState *machine)
exit(EXIT_FAILURE);
}
- s = sa1110_init(machine->cpu_type);
+ cms->sa1110 = sa1110_init(machine->cpu_type);
memory_region_add_subregion(get_system_memory(), SA_SDCS0, machine->ram);
@@ -54,11 +64,13 @@ static void collie_init(MachineState *machine)
sysbus_create_simple("scoop", 0x40800000, NULL);
collie_binfo.board_id = 0x208;
- arm_load_kernel(s->cpu, machine, &collie_binfo);
+ arm_load_kernel(cms->sa1110->cpu, machine, &collie_binfo);
}
-static void collie_machine_init(MachineClass *mc)
+static void collie_machine_class_init(ObjectClass *oc, void *data)
{
+ MachineClass *mc = MACHINE_CLASS(oc);
+
mc->desc = "Sharp SL-5500 (Collie) PDA (SA-1110)";
mc->init = collie_init;
mc->ignore_memory_transaction_failures = true;
@@ -67,4 +79,15 @@ static void collie_machine_init(MachineClass *mc)
mc->default_ram_id = "strongarm.sdram";
}
-DEFINE_MACHINE("collie", collie_machine_init)
+static const TypeInfo collie_machine_typeinfo = {
+ .name = TYPE_COLLIE_MACHINE,
+ .parent = TYPE_MACHINE,
+ .class_init = collie_machine_class_init,
+ .instance_size = sizeof(CollieMachineState),
+};
+
+static void collie_machine_register_types(void)
+{
+ type_register_static(&collie_machine_typeinfo);
+}
+type_init(collie_machine_register_types);
--
2.20.1
next prev parent reply other threads:[~2020-04-06 10:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-06 10:11 [PULL 00/11] target-arm queue Peter Maydell
2020-04-06 10:11 ` [PULL 01/11] target/arm: don't expose "ieee_half" via gdbstub Peter Maydell
2020-04-06 10:11 ` Peter Maydell [this message]
2020-04-06 10:11 ` [PULL 03/11] target/arm: PSTATE.PAN should not clear exec bits Peter Maydell
2020-04-06 10:11 ` [PULL 04/11] target/arm: Remove obsolete TODO note from get_phys_addr_lpae() Peter Maydell
2020-04-06 10:11 ` [PULL 05/11] hw/gpio/aspeed_gpio.c: Don't directly include assert.h Peter Maydell
2020-04-06 10:12 ` [PULL 06/11] dump: Fix writing of ELF section Peter Maydell
2020-04-06 10:12 ` [PULL 07/11] dma/xlnx-zdma: Remove comment Peter Maydell
2020-04-06 10:12 ` [PULL 08/11] dma/xlnx-zdma: Populate DBG0.CMN_BUF_FREE Peter Maydell
2020-04-06 10:12 ` [PULL 09/11] dma/xlnx-zdma: Clear DMA_DONE when halting Peter Maydell
2020-04-06 10:12 ` [PULL 10/11] dma/xlnx-zdma: Advance the descriptor address when stopping Peter Maydell
2020-04-06 10:12 ` [PULL 11/11] dma/xlnx-zdma: Reorg to fix CUR_DSCR Peter Maydell
2020-04-06 12:52 ` [PULL 00/11] target-arm queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200406101205.23027-3-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).