From nobody Sat May 4 17:01:34 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 1508247817808383.508645148499; Tue, 17 Oct 2017 06:43:37 -0700 (PDT) Received: from localhost ([::1]:39448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4S9h-0006Od-3e for importer@patchew.org; Tue, 17 Oct 2017 09:43:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4S7e-0004rV-EP for qemu-devel@nongnu.org; Tue, 17 Oct 2017 09:41:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4S7a-0007z5-JO for qemu-devel@nongnu.org; Tue, 17 Oct 2017 09:41:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4S7a-0007yg-DE for qemu-devel@nongnu.org; Tue, 17 Oct 2017 09:41:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A504EC0C9; Tue, 17 Oct 2017 13:41:25 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F50E60852; Tue, 17 Oct 2017 13:41:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6A504EC0C9 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 17 Oct 2017 15:41:19 +0200 Message-Id: <1508247680-98800-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1508247680-98800-1-git-send-email-imammedo@redhat.com> References: <1508247680-98800-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 17 Oct 2017 13:41:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] s390x: fix cpu object referrence leak in s390x_new_cpu() 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: Christian Borntraeger , Cornelia Huck , Alexander Graf , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" object_new() returns cpu with refcnt =3D=3D 1 and after realize refcnt =3D=3D 2*. s390x_new_cpu() as an owner of the first refcnt should have released it on exit in both cases (on error and success) to avoid it leaking. Do so for both cases. Signed-off-by: Igor Mammedov --- target/s390x/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/helper.c b/target/s390x/helper.c index 97adbcc..64d4c48 100644 --- a/target/s390x/helper.c +++ b/target/s390x/helper.c @@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t cor= e_id, Error **errp) object_property_set_bool(OBJECT(cpu), true, "realized", &err); =20 out: + object_unref(OBJECT(cpu)); if (err) { error_propagate(errp, err); - object_unref(OBJECT(cpu)); cpu =3D NULL; } return cpu; --=20 2.7.4 From nobody Sat May 4 17:01:34 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508249152014416.64081038630536; Tue, 17 Oct 2017 07:05:52 -0700 (PDT) Received: from localhost ([::1]:39685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4SV8-0006ae-1V for importer@patchew.org; Tue, 17 Oct 2017 10:05:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4S7i-0004wO-1B for qemu-devel@nongnu.org; Tue, 17 Oct 2017 09:41:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4S7c-00080G-45 for qemu-devel@nongnu.org; Tue, 17 Oct 2017 09:41:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4S7b-0007zf-SK for qemu-devel@nongnu.org; Tue, 17 Oct 2017 09:41:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D49B71487F0; Tue, 17 Oct 2017 13:41:26 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1EDA60852; Tue, 17 Oct 2017 13:41:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D49B71487F0 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 17 Oct 2017 15:41:20 +0200 Message-Id: <1508247680-98800-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1508247680-98800-1-git-send-email-imammedo@redhat.com> References: <1508247680-98800-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 17 Oct 2017 13:41:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] s390x: move s390x_new_cpu() into board code 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: Christian Borntraeger , Cornelia Huck , Alexander Graf , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" s390-virtio-ccw.c is the sole user of s390x_new_cpu(), so move this helper there. Signed-off-by: Igor Mammedov --- target/s390x/cpu.h | 1 - hw/s390x/s390-virtio-ccw.c | 21 +++++++++++++++++++++ target/s390x/helper.c | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 7e864c8..b177be9 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -695,7 +695,6 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprint= f); =20 /* helper.c */ #define cpu_init(cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model) -S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **err= p); =20 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 32d3f11..f64db51 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -52,6 +52,27 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu); } =20 +static +S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **err= p) +{ + S390CPU *cpu =3D S390_CPU(object_new(typename)); + Error *err =3D NULL; + + object_property_set_int(OBJECT(cpu), core_id, "core-id", &err); + if (err !=3D NULL) { + goto out; + } + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + +out: + object_unref(OBJECT(cpu)); + if (err) { + error_propagate(errp, err); + cpu =3D NULL; + } + return cpu; +} + static void s390_init_cpus(MachineState *machine) { MachineClass *mc =3D MACHINE_GET_CLASS(machine); diff --git a/target/s390x/helper.c b/target/s390x/helper.c index 64d4c48..52aa64b 100644 --- a/target/s390x/helper.c +++ b/target/s390x/helper.c @@ -68,26 +68,6 @@ void s390x_cpu_timer(void *opaque) } #endif =20 -S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **err= p) -{ - S390CPU *cpu =3D S390_CPU(object_new(typename)); - Error *err =3D NULL; - - object_property_set_int(OBJECT(cpu), core_id, "core-id", &err); - if (err !=3D NULL) { - goto out; - } - object_property_set_bool(OBJECT(cpu), true, "realized", &err); - -out: - object_unref(OBJECT(cpu)); - if (err) { - error_propagate(errp, err); - cpu =3D NULL; - } - return cpu; -} - #ifndef CONFIG_USER_ONLY =20 hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr) --=20 2.7.4