From nobody Mon Apr 29 11:33:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499853030346599.6296598088968; Wed, 12 Jul 2017 02:50:30 -0700 (PDT) Received: from localhost ([::1]:51398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVEHt-0003rD-70 for importer@patchew.org; Wed, 12 Jul 2017 05:50:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVEGR-00033p-EO for qemu-devel@nongnu.org; Wed, 12 Jul 2017 05:49:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVEGM-0005Tl-KR for qemu-devel@nongnu.org; Wed, 12 Jul 2017 05:48:59 -0400 Received: from 5.mo68.mail-out.ovh.net ([46.105.62.179]:49111) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVEGM-0005TL-EG for qemu-devel@nongnu.org; Wed, 12 Jul 2017 05:48:54 -0400 Received: from player750.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo68.mail-out.ovh.net (Postfix) with ESMTP id C01E96C0F0 for ; Wed, 12 Jul 2017 11:48:52 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player750.ha.ovh.net (Postfix) with ESMTPA id 5166518007A; Wed, 12 Jul 2017 11:48:45 +0200 (CEST) From: Greg Kurz To: qemu-ppc@nongnu.org Date: Wed, 12 Jul 2017 11:48:39 +0200 Message-ID: <149985291912.20899.12562819149683053534.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 17330977268411505126 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelkedrvdelgdduheduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.62.179 Subject: [Qemu-devel] [PATCH] spapr: fix potential memory leak in spapr_core_plug() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Gibson , qemu-devel@nongnu.org, Bharata B Rao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Since commit 5c1da81215c7 ("spapr: Remove unnecessary differences between hotplug and coldplug paths"), the CPU DT for the DRC is always allocated. This causes a memory leak for pseries-2.6 and older machine types, that don't support CPU hotplug and don't allocate DRCs for CPUs. Reported-by: Bharata B Rao Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 12b3f099d4c9..4a480e1c1dd9 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2993,8 +2993,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, CPUState *cs =3D CPU(core->threads); sPAPRDRConnector *drc; Error *local_err =3D NULL; - void *fdt =3D NULL; - int fdt_offset =3D 0; int smt =3D kvmppc_smt_threads(); CPUArchId *core_slot; int index; @@ -3009,9 +3007,12 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, =20 g_assert(drc || !mc->has_hotpluggable_cpus); =20 - fdt =3D spapr_populate_hotplug_cpu_dt(cs, &fdt_offset, spapr); - if (drc) { + void *fdt; + int fdt_offset; + + fdt =3D spapr_populate_hotplug_cpu_dt(cs, &fdt_offset, spapr); + spapr_drc_attach(drc, dev, fdt, fdt_offset, &local_err); if (local_err) { g_free(fdt);