From patchwork Thu Mar 26 20:49:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 184933 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp514026ilr; Thu, 26 Mar 2020 13:49:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvlf7TTxBkJxJs03YBqvpvtq0+fvYkBY6kPc9jByscKW8dPgTTx8ObGEPK6LjsOryyOWCYC X-Received: by 2002:a37:a70e:: with SMTP id q14mr10536475qke.41.1585255775924; Thu, 26 Mar 2020 13:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585255775; cv=none; d=google.com; s=arc-20160816; b=Y/Zdcy3JX7XzJQkcYLSzsYdYb1wzAg1aJuqM+0FKixVFrKLoJuV9SmJzyADquCs4gi OM93F1sGUT2XheRR/JVNxt6VNP47hXyrGGJMgLXKCC41E4eEosexFJb77Bz+IRl7RnD/ aBTSHaxr8KpK3djhESy8mt9HEwQYR85228TOM2+EDAye5kENHwYlF9DeQhnUCKGjwcfK QSxcTJW129AYyvSz+AZYg5pOU2oJmkPb6/NGr2juV1h0VK1jR81hStpNPDa+Jp92DUHf 2AS4VWgSq3eVKRRD8odpSmEt2R5ca+SGBZE39gaovpNZrcUk2BHqe1A272pqHpMEkmLa gWiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=bAQfFYBSPpibKiPXxyi44d7P7+tA6VEgfXGXzLkCrIs=; b=hG1SzSb121/6Pk4eku+tVvNx3It8FFRsWuLGDhPdcLxw3y2+ABPxh2KIsRVhvMQ+ZD husvTFngR5ngwCrcAnb+ctnxvFtbk7f7LmUT34KAadW71QIO1hfX6CP7dokMSrv+WjP1 xUgmZgJmU9jXYUz7plUlDq+jdDCy/mJcM9zLmBDvJ1MdK0CVohan0v4hg0gxE1X5u/BR ibTmcV+zaIIRRNmBB9Cch6Sz2yJOgvmU66i8eQxrDzSw+p7WxxhCkZMGmqhf10IDI6iH 66r+Hmg1rQGbb6/jIXt1ZjaTOcUe7M5HGsO8cFlsgsgAt7plG4lhTTNyBvVP9ua+cg8J TokQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kHPAtvm4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m3si2117093qke.131.2020.03.26.13.49.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Mar 2020 13:49:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kHPAtvm4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHZRX-0004p2-El for patch@linaro.org; Thu, 26 Mar 2020 16:49:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39722) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHZRM-0004mb-JZ for qemu-devel@nongnu.org; Thu, 26 Mar 2020 16:49:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHZRL-0005HT-F9 for qemu-devel@nongnu.org; Thu, 26 Mar 2020 16:49:24 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:39185) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHZRL-0005G0-8G for qemu-devel@nongnu.org; Thu, 26 Mar 2020 16:49:23 -0400 Received: by mail-wm1-x341.google.com with SMTP id a9so9210576wmj.4 for ; Thu, 26 Mar 2020 13:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=bAQfFYBSPpibKiPXxyi44d7P7+tA6VEgfXGXzLkCrIs=; b=kHPAtvm4hEHla5vZLv2326STOa51pQHpfycFSTrcV5j8Qo+vzKEzKEoUUh4OeZlQ2S ABGaxlF2xuoJj63YYPy8tNURAZFZQnHeAga6Aey4PfXyOINhKKxgZN8vdKGP2vGKhuMI LzxD0VgQw6uA8NLaZuJdeRLc3dAvhAuIt7pMS1+F1osB7G+tR+kpLfEEdVwaIaSXHIGv 8krbTwKoJOXYHLNeWlejFELHA3h0V/bAWqmXZ03a6CUEBRfmQeASoElpP47KXG1nW6Yf nGB3udNhrhiNe/X4b3ywjyQj9OD3HGmXGeEqwiDnVFMq1a39DOIzTc/HrkzwkWn3pGiR hYLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=bAQfFYBSPpibKiPXxyi44d7P7+tA6VEgfXGXzLkCrIs=; b=kp/eFowMqkRpHmSEGJQFXm/3NIAn6JqC9RLJeiv7Dcyry0/kIx9ny9ZGpL1x4bQzSR BRrKZUgaCdQ/wSRiX2El6RQequP0hGUMC6dNUadxIw7h/4+Pm6kbFgdVXyqnoDbPu5ix CU5+2Mgqew80XItuqJ3VB02nkXfVzLpZzRmpPlmMA97cjH3OZBje/XGbRvzLBCB5itxn M/Yx5L2rVCjH/R4fjgi6XYhmOg/UsFVCoAxAKm/0wR0oKs8jAhY+iPoHleR93P7U+KbV yLSl/VUUCIQWXlAQ1e32BsIUrr9FMbKNdEa/h8Pf84rMWqX1MprymEEl5uC5ASJxAXyF Tuow== X-Gm-Message-State: ANhLgQ15rktcXzUsfekO04o1IImiVOjBVyRE0IF3fX6wXgrIQbxKpw4r Z4X0EFOlt5+yjGB0W3AGW9tvoQ== X-Received: by 2002:adf:fc08:: with SMTP id i8mr4027024wrr.109.1585255761608; Thu, 26 Mar 2020 13:49:21 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id 9sm4864561wmm.6.2020.03.26.13.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 13:49:21 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2] hw/arm/collie: Put StrongARMState* into a CollieMachineState struct Date: Thu, 26 Mar 2020 20:49:19 +0000 Message-Id: <20200326204919.22006-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- v1->v2: folded in the uncommitted change that fixes the arm_load_kernel() first argument. hw/arm/collie.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé 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);