From nobody Thu May 2 21:02:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1647355351; cv=none; d=zohomail.com; s=zohoarc; b=CVJCmcAlhBryII9JEZRXIZYsl9/X/U3677pSrUQeYxMWEAQ5Um87LPGfamPvIyQ4p5Jv04hBcPeD05eLVqASWoo394JepOlldw9ToQzP/mEVKVdD8jXjQFHPQFdnalVR2Z25qXWIxiiqrG7vqAlYZSJXHWf0qyVojB4CujbTJA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647355351; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F9p92xVdbAU558Jcfq2dXxSaOx5fAK5gBBxvOK2lDYo=; b=lNZEKWfUvJttD7bv9XqxfIlwdZU7vIdDr/CpSqZYuRcoZBk97oh2L8m+Nflfizel5ka55VUYhM/myFsqFc5hvm+e+cI5OKOQM/oIBkPYPrvua1J7ex2pE1F6zh81SAQCEmN9HVIyJln7uwehQbowSaVBwiPbfvXhQRPn240NzZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1647355351820482.20977065485204; Tue, 15 Mar 2022 07:42:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.290845.493391 (Exim 4.92) (envelope-from ) id 1nU8ND-0007GE-06; Tue, 15 Mar 2022 14:42:07 +0000 Received: by outflank-mailman (output) from mailman id 290845.493391; Tue, 15 Mar 2022 14:42:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8NC-0007G7-TO; Tue, 15 Mar 2022 14:42:06 +0000 Received: by outflank-mailman (input) for mailman id 290845; Tue, 15 Mar 2022 14:42:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8NB-0007Fw-4G for xen-devel@lists.xenproject.org; Tue, 15 Mar 2022 14:42:05 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 13b20ae8-a46e-11ec-853b-5f4723681683; Tue, 15 Mar 2022 15:42:03 +0100 (CET) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-2vIvU3WdPUWYbINmL8lYeg-1; Tue, 15 Mar 2022 10:42:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA3492999B47; Tue, 15 Mar 2022 14:41:58 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E65822EFB0; Tue, 15 Mar 2022 14:41:57 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C2F2121E66FC; Tue, 15 Mar 2022 15:41:56 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 13b20ae8-a46e-11ec-853b-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647355322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F9p92xVdbAU558Jcfq2dXxSaOx5fAK5gBBxvOK2lDYo=; b=At5nnrjDBwjZ1UORLtere9g2Yn5yjcK5zGtosgm7bkYVNe4ZyD+SiDuMgNXLQui7IQ8zt5 uwHWSYnNqFgrYrJdy2P1DoVY00QM67kDMH++gY3a1Wx5CN4y/5SE5/Ud8GfUlpc+DILQDn EJssbVC67n9VXKexP57qQpEh/RZLpeI= X-MC-Unique: 2vIvU3WdPUWYbINmL8lYeg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Laurent Vivier , Amit Shah , Peter Maydell , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Greg Kurz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jean-Christophe Dubois , Keith Busch , Klaus Jensen , Yuval Shaia , Yoshinori Sato , Magnus Damm , Fabien Chouteau , KONRAD Frederic , Mark Cave-Ayland , Artyom Tarasenko , Alex Williamson , Eric Auger , Max Filippov , Juan Quintela , "Dr. David Alan Gilbert" , Konstantin Kostiuk , Michael Roth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Pavel Dovgalyuk , =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Hildenbrand , Wenchao Wang , Kamil Rytarowski , Reinoud Zandijk , Sunil Muthuswamy , Cornelia Huck , Thomas Huth , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , kvm@vger.kernel.org, qemu-arm@nongnu.org, xen-devel@lists.xenproject.org, qemu-ppc@nongnu.org, qemu-block@nongnu.org, haxm-team@intel.com, qemu-s390x@nongnu.org Subject: [PATCH v2 1/3] scripts/coccinelle: New use-g_new-etc.cocci Date: Tue, 15 Mar 2022 15:41:54 +0100 Message-Id: <20220315144156.1595462-2-armbru@redhat.com> In-Reply-To: <20220315144156.1595462-1-armbru@redhat.com> References: <20220315144156.1595462-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1647355354202100003 This is the semantic patch from commit b45c03f585 "arm: Use g_new() & friends where that makes obvious sense". Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Acked-by: Michael S. Tsirkin --- scripts/coccinelle/use-g_new-etc.cocci | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 scripts/coccinelle/use-g_new-etc.cocci diff --git a/scripts/coccinelle/use-g_new-etc.cocci b/scripts/coccinelle/us= e-g_new-etc.cocci new file mode 100644 index 0000000000..e2280e93b3 --- /dev/null +++ b/scripts/coccinelle/use-g_new-etc.cocci @@ -0,0 +1,75 @@ +// Use g_new() & friends where that makes obvious sense +@@ +type T; +@@ +-g_malloc(sizeof(T)) ++g_new(T, 1) +@@ +type T; +@@ +-g_try_malloc(sizeof(T)) ++g_try_new(T, 1) +@@ +type T; +@@ +-g_malloc0(sizeof(T)) ++g_new0(T, 1) +@@ +type T; +@@ +-g_try_malloc0(sizeof(T)) ++g_try_new0(T, 1) +@@ +type T; +expression n; +@@ +-g_malloc(sizeof(T) * (n)) ++g_new(T, n) +@@ +type T; +expression n; +@@ +-g_try_malloc(sizeof(T) * (n)) ++g_try_new(T, n) +@@ +type T; +expression n; +@@ +-g_malloc0(sizeof(T) * (n)) ++g_new0(T, n) +@@ +type T; +expression n; +@@ +-g_try_malloc0(sizeof(T) * (n)) ++g_try_new0(T, n) +@@ +type T; +expression p, n; +@@ +-g_realloc(p, sizeof(T) * (n)) ++g_renew(T, p, n) +@@ +type T; +expression p, n; +@@ +-g_try_realloc(p, sizeof(T) * (n)) ++g_try_renew(T, p, n) +@@ +type T; +expression n; +@@ +-(T *)g_new(T, n) ++g_new(T, n) +@@ +type T; +expression n; +@@ +-(T *)g_new0(T, n) ++g_new0(T, n) +@@ +type T; +expression p, n; +@@ +-(T *)g_renew(T, p, n) ++g_renew(T, p, n) --=20 2.35.1 From nobody Thu May 2 21:02:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1647355351; cv=none; d=zohomail.com; s=zohoarc; b=QopRuaeBS3SzPzfxuf/PKaisRvuhrwdvKhIo+fz+otILXn4vo2rfnEqW98w72W2hEqbP0gtEuXQI0/Zq9VyLzK/neIZTGOj2ppAv8J8mY5pw/FCssRp4nUNucSVMTdnJceS6wu12b48p4CK6oDrjFVxleFPIygulDpFTjofAQ1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647355351; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iLfyluImzysLOPkiTvJo2zm+5FjLUH+6CI5H86s0TvU=; b=H+zzNotdiWTFbDzfR6wwO5JB68Z7b3lqEitIVlXDpnB2sxrNrmLvq/3gYyijUVQ+7OJz2PkIKTYPXSz1DZ9tuqK0HSOP70ME6pbyeMJW2GEktrHQKPP/hi5X9h8SIaRfpoZRXtJyokb1dVFpi1DvP6fAf3Al6AfkFMW7yYuHMsQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1647355351349460.9546784846184; Tue, 15 Mar 2022 07:42:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.290846.493397 (Exim 4.92) (envelope-from ) id 1nU8ND-0007Jl-8r; Tue, 15 Mar 2022 14:42:07 +0000 Received: by outflank-mailman (output) from mailman id 290846.493397; Tue, 15 Mar 2022 14:42:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8ND-0007IP-41; Tue, 15 Mar 2022 14:42:07 +0000 Received: by outflank-mailman (input) for mailman id 290846; Tue, 15 Mar 2022 14:42:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8NB-0007Fw-L8 for xen-devel@lists.xenproject.org; Tue, 15 Mar 2022 14:42:05 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 13e8aac8-a46e-11ec-853b-5f4723681683; Tue, 15 Mar 2022 15:42:03 +0100 (CET) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-539-B7jc6o2xM2CidF8CYWCU4w-1; Tue, 15 Mar 2022 10:42:01 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA65E10184A3; Tue, 15 Mar 2022 14:41:58 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E64E540FF40A; Tue, 15 Mar 2022 14:41:57 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C792F21D1F57; Tue, 15 Mar 2022 15:41:56 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 13e8aac8-a46e-11ec-853b-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647355322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iLfyluImzysLOPkiTvJo2zm+5FjLUH+6CI5H86s0TvU=; b=ERV5yuTHo16lD/0D4SgrNWtldjf+jt812GLaWHU/5niI+mLkOMbmWZ9Ydyont0SSJtrM4c 98rOoKKGnuOshBMY8lz668lmZDjZMTh5S6v6J/h1g951n0DI49wtvk+4YCpcU5gJB7wcGD C4UYt09PSfdnlRxswQBG6MSkOzEKLho= X-MC-Unique: B7jc6o2xM2CidF8CYWCU4w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Laurent Vivier , Amit Shah , Peter Maydell , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Greg Kurz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jean-Christophe Dubois , Keith Busch , Klaus Jensen , Yuval Shaia , Yoshinori Sato , Magnus Damm , Fabien Chouteau , KONRAD Frederic , Mark Cave-Ayland , Artyom Tarasenko , Alex Williamson , Eric Auger , Max Filippov , Juan Quintela , "Dr. David Alan Gilbert" , Konstantin Kostiuk , Michael Roth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Pavel Dovgalyuk , =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Hildenbrand , Wenchao Wang , Kamil Rytarowski , Reinoud Zandijk , Sunil Muthuswamy , Cornelia Huck , Thomas Huth , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , kvm@vger.kernel.org, qemu-arm@nongnu.org, xen-devel@lists.xenproject.org, qemu-ppc@nongnu.org, qemu-block@nongnu.org, haxm-team@intel.com, qemu-s390x@nongnu.org Subject: [PATCH v2 2/3] 9pfs: Use g_new() & friends where that makes obvious sense Date: Tue, 15 Mar 2022 15:41:55 +0100 Message-Id: <20220315144156.1595462-3-armbru@redhat.com> In-Reply-To: <20220315144156.1595462-1-armbru@redhat.com> References: <20220315144156.1595462-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1647355378348100001 g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Initial patch created mechanically with: $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \ --macro-file scripts/cocci-macro-file.h FILES... This uncovers a typing error: ../hw/9pfs/9p.c: In function =E2=80=98qid_path_fullmap=E2=80=99: ../hw/9pfs/9p.c:855:13: error: assignment to =E2=80=98QpfEntry *=E2=80= =99 from incompatible pointer type =E2=80=98QppEntry *=E2=80=99 [-Werror=3D= incompatible-pointer-types] 855 | val =3D g_new0(QppEntry, 1); | ^ Harmless, because QppEntry is larger than QpfEntry. Manually fixed to allocate a QpfEntry instead. Cc: Greg Kurz Cc: Christian Schoenebeck Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Christian Schoenebeck Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Greg Kurz Acked-by: Michael S. Tsirkin --- hw/9pfs/9p-proxy.c | 2 +- hw/9pfs/9p-synth.c | 4 ++-- hw/9pfs/9p.c | 8 ++++---- hw/9pfs/codir.c | 6 +++--- tests/qtest/virtio-9p-test.c | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 8b4b5cf7dc..4c5e0fc217 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -1187,7 +1187,7 @@ static int proxy_parse_opts(QemuOpts *opts, FsDriverE= ntry *fs, Error **errp) =20 static int proxy_init(FsContext *ctx, Error **errp) { - V9fsProxy *proxy =3D g_malloc(sizeof(V9fsProxy)); + V9fsProxy *proxy =3D g_new(V9fsProxy, 1); int sock_id; =20 if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index b3080e415b..d99d263985 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -49,7 +49,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *pa= rent, int mode, =20 /* Add directory type and remove write bits */ mode =3D ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH); - node =3D g_malloc0(sizeof(V9fsSynthNode)); + node =3D g_new0(V9fsSynthNode, 1); if (attr) { /* We are adding .. or . entries */ node->attr =3D attr; @@ -128,7 +128,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int= mode, } /* Add file type and remove write bits */ mode =3D ((mode & 0777) | S_IFREG); - node =3D g_malloc0(sizeof(V9fsSynthNode)); + node =3D g_new0(V9fsSynthNode, 1); node->attr =3D &node->actual_attr; node->attr->inode =3D synth_node_count++; node->attr->nlink =3D 1; diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index a6d6b3f835..8e9d4aea73 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -324,7 +324,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fi= d) return NULL; } } - f =3D g_malloc0(sizeof(V9fsFidState)); + f =3D g_new0(V9fsFidState, 1); f->fid =3D fid; f->fid_type =3D P9_FID_NONE; f->ref =3D 1; @@ -804,7 +804,7 @@ static int qid_inode_prefix_hash_bits(V9fsPDU *pdu, dev= _t dev) =20 val =3D qht_lookup(&pdu->s->qpd_table, &lookup, hash); if (!val) { - val =3D g_malloc0(sizeof(QpdEntry)); + val =3D g_new0(QpdEntry, 1); *val =3D lookup; affix =3D affixForIndex(pdu->s->qp_affix_next); val->prefix_bits =3D affix.bits; @@ -852,7 +852,7 @@ static int qid_path_fullmap(V9fsPDU *pdu, const struct = stat *stbuf, return -ENFILE; } =20 - val =3D g_malloc0(sizeof(QppEntry)); + val =3D g_new0(QpfEntry, 1); *val =3D lookup; =20 /* new unique inode and device combo */ @@ -928,7 +928,7 @@ static int qid_path_suffixmap(V9fsPDU *pdu, const struc= t stat *stbuf, return -ENFILE; } =20 - val =3D g_malloc0(sizeof(QppEntry)); + val =3D g_new0(QppEntry, 1); *val =3D lookup; =20 /* new unique inode affix and device combo */ diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 75148bc985..93ba44fb75 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -141,9 +141,9 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *= fidp, =20 /* append next node to result chain */ if (!e) { - *entries =3D e =3D g_malloc0(sizeof(V9fsDirEnt)); + *entries =3D e =3D g_new0(V9fsDirEnt, 1); } else { - e =3D e->next =3D g_malloc0(sizeof(V9fsDirEnt)); + e =3D e->next =3D g_new0(V9fsDirEnt, 1); } e->dent =3D qemu_dirent_dup(dent); =20 @@ -163,7 +163,7 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *= fidp, break; } =20 - e->st =3D g_malloc0(sizeof(struct stat)); + e->st =3D g_new0(struct stat, 1); memcpy(e->st, &stbuf, sizeof(struct stat)); } =20 diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 01ca076afe..e28c71bd8f 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -468,12 +468,12 @@ static void v9fs_rreaddir(P9Req *req, uint32_t *count= , uint32_t *nentries, togo -=3D 13 + 8 + 1 + 2 + slen, ++n) { if (!e) { - e =3D g_malloc(sizeof(struct V9fsDirent)); + e =3D g_new(struct V9fsDirent, 1); if (entries) { *entries =3D e; } } else { - e =3D e->next =3D g_malloc(sizeof(struct V9fsDirent)); + e =3D e->next =3D g_new(struct V9fsDirent, 1); } e->next =3D NULL; /* qid[13] offset[8] type[1] name[s] */ --=20 2.35.1 From nobody Thu May 2 21:02:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1647355362; cv=none; d=zohomail.com; s=zohoarc; b=ZJsyuAhqEuwp8ayisKwgaahy7ObTsQDKlnkb6tRsS8vMb79AwehRbZDud38yEGUgfN5ERM4Wjni7XTkHUtEavr6MsHFrBYJi4rcbr3D7nSpH5du1ftUOkyT5XINan/L5c62eQXZ+69E2po3UpB8fiwJu+5TDWH/mY7Zm2n/6Nxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647355362; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=66PttAMaDePnZpAaERjhmXYLkWYyqtV8i1H4LCrJWaI=; b=ekPr1TQH1T67NeFgFuacAfwgY1Qotii3nwPR1a5YD70DXYSPxKQqV7KMs92WwrcvCRFlFqeTwXMagdv60QxzUT7wErr+IS1K+9bCMS1la+c1OA0DTzInnQv8aSiDssyVgK7nOsjULzuqaJdouOoUIK93v8rFM5W/NurHRc2JUnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1647355362313605.9569746955777; Tue, 15 Mar 2022 07:42:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.290848.493425 (Exim 4.92) (envelope-from ) id 1nU8NN-0008Bm-Ua; Tue, 15 Mar 2022 14:42:17 +0000 Received: by outflank-mailman (output) from mailman id 290848.493425; Tue, 15 Mar 2022 14:42:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8NN-0008Bd-Qr; Tue, 15 Mar 2022 14:42:17 +0000 Received: by outflank-mailman (input) for mailman id 290848; Tue, 15 Mar 2022 14:42:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8NM-0007nJ-7E for xen-devel@lists.xenproject.org; Tue, 15 Mar 2022 14:42:16 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 16329168-a46e-11ec-8eba-a37418f5ba1a; Tue, 15 Mar 2022 15:42:13 +0100 (CET) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-489-KoLFHDU6ORCzxdociODm7g-1; Tue, 15 Mar 2022 10:42:02 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7F3F2999B4D; Tue, 15 Mar 2022 14:41:59 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 392A640CFD0E; Tue, 15 Mar 2022 14:41:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CCFCA21D1F5A; Tue, 15 Mar 2022 15:41:56 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 16329168-a46e-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647355326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=66PttAMaDePnZpAaERjhmXYLkWYyqtV8i1H4LCrJWaI=; b=OQeeXjVKdDIg126ycOH3r3eoHQFZv1df4YfND2zzVx+UANv//TPBuU24urRH8QFKA7KGmM AZtqLoiMmYwrwEzqFb7rLKnuosssTRQhVWwwByS744w3T1ajiRUnXCSVJ5sYDG9HwwE6Sd eDJDnbSUILusf/S0wwfSGqiPpNHosBs= X-MC-Unique: KoLFHDU6ORCzxdociODm7g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Laurent Vivier , Amit Shah , Peter Maydell , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Greg Kurz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jean-Christophe Dubois , Keith Busch , Klaus Jensen , Yuval Shaia , Yoshinori Sato , Magnus Damm , Fabien Chouteau , KONRAD Frederic , Mark Cave-Ayland , Artyom Tarasenko , Alex Williamson , Eric Auger , Max Filippov , Juan Quintela , "Dr. David Alan Gilbert" , Konstantin Kostiuk , Michael Roth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Pavel Dovgalyuk , =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Hildenbrand , Wenchao Wang , Kamil Rytarowski , Reinoud Zandijk , Sunil Muthuswamy , Cornelia Huck , Thomas Huth , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , kvm@vger.kernel.org, qemu-arm@nongnu.org, xen-devel@lists.xenproject.org, qemu-ppc@nongnu.org, qemu-block@nongnu.org, haxm-team@intel.com, qemu-s390x@nongnu.org Subject: [PATCH v2 3/3] Use g_new() & friends where that makes obvious sense Date: Tue, 15 Mar 2022 15:41:56 +0100 Message-Id: <20220315144156.1595462-4-armbru@redhat.com> In-Reply-To: <20220315144156.1595462-1-armbru@redhat.com> References: <20220315144156.1595462-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1647355364088100003 g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Patch created mechanically with: $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \ --macro-file scripts/cocci-macro-file.h FILES... Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Alex Benn=C3=A9e Acked-by: Dr. David Alan Gilbert Acked-by: Michael S. Tsirkin Reviewed-by: Igor Mammedov Reviewed-by: Pavel Dovgalyuk --- include/qemu/timer.h | 2 +- accel/kvm/kvm-all.c | 6 ++-- accel/tcg/tcg-accel-ops-mttcg.c | 2 +- accel/tcg/tcg-accel-ops-rr.c | 4 +-- audio/audio.c | 4 +-- audio/audio_legacy.c | 6 ++-- audio/dsoundaudio.c | 2 +- audio/jackaudio.c | 6 ++-- audio/paaudio.c | 4 +-- backends/cryptodev.c | 2 +- contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +- cpus-common.c | 4 +-- dump/dump.c | 2 +- hw/acpi/hmat.c | 2 +- hw/audio/intel-hda.c | 2 +- hw/char/parallel.c | 2 +- hw/char/riscv_htif.c | 2 +- hw/char/virtio-serial-bus.c | 6 ++-- hw/core/irq.c | 2 +- hw/core/reset.c | 2 +- hw/display/pxa2xx_lcd.c | 2 +- hw/display/tc6393xb.c | 2 +- hw/display/virtio-gpu.c | 4 +-- hw/display/xenfb.c | 4 +-- hw/dma/rc4030.c | 4 +-- hw/i2c/core.c | 4 +-- hw/i2c/i2c_mux_pca954x.c | 2 +- hw/i386/amd_iommu.c | 4 +-- hw/i386/intel_iommu.c | 2 +- hw/i386/xen/xen-hvm.c | 10 +++--- hw/i386/xen/xen-mapcache.c | 14 ++++---- hw/input/lasips2.c | 2 +- hw/input/pckbd.c | 2 +- hw/input/ps2.c | 4 +-- hw/input/pxa2xx_keypad.c | 2 +- hw/input/tsc2005.c | 3 +- hw/intc/riscv_aclint.c | 6 ++-- hw/intc/xics.c | 2 +- hw/m68k/virt.c | 2 +- hw/mips/mipssim.c | 2 +- hw/misc/applesmc.c | 2 +- hw/misc/imx6_src.c | 2 +- hw/misc/ivshmem.c | 4 +-- hw/net/virtio-net.c | 4 +-- hw/nvme/ns.c | 2 +- hw/pci-host/pnv_phb3.c | 2 +- hw/pci-host/pnv_phb4.c | 2 +- hw/pci/pcie_sriov.c | 2 +- hw/ppc/e500.c | 2 +- hw/ppc/ppc.c | 8 ++--- hw/ppc/ppc405_boards.c | 4 +-- hw/ppc/ppc405_uc.c | 18 +++++----- hw/ppc/ppc4xx_devs.c | 2 +- hw/ppc/ppc_booke.c | 4 +-- hw/ppc/spapr.c | 2 +- hw/ppc/spapr_events.c | 2 +- hw/ppc/spapr_hcall.c | 2 +- hw/ppc/spapr_numa.c | 3 +- hw/rdma/vmw/pvrdma_dev_ring.c | 2 +- hw/rdma/vmw/pvrdma_qp_ops.c | 6 ++-- hw/sh4/r2d.c | 4 +-- hw/sh4/sh7750.c | 2 +- hw/sparc/leon3.c | 2 +- hw/sparc64/sparc64.c | 4 +-- hw/timer/arm_timer.c | 2 +- hw/timer/slavio_timer.c | 2 +- hw/vfio/pci.c | 4 +-- hw/vfio/platform.c | 4 +-- hw/virtio/virtio-crypto.c | 2 +- hw/virtio/virtio-iommu.c | 2 +- hw/virtio/virtio.c | 5 ++- hw/xtensa/xtfpga.c | 2 +- linux-user/syscall.c | 2 +- migration/dirtyrate.c | 4 +-- migration/multifd-zlib.c | 4 +-- migration/ram.c | 2 +- monitor/misc.c | 2 +- monitor/qmp-cmds.c | 2 +- qga/commands-win32.c | 8 ++--- qga/commands.c | 2 +- qom/qom-qmp-cmds.c | 2 +- replay/replay-char.c | 4 +-- replay/replay-events.c | 10 +++--- softmmu/bootdevice.c | 4 +-- softmmu/dma-helpers.c | 4 +-- softmmu/memory_mapping.c | 2 +- target/i386/cpu-sysemu.c | 2 +- target/i386/hax/hax-accel-ops.c | 4 +-- target/i386/nvmm/nvmm-accel-ops.c | 4 +-- target/i386/whpx/whpx-accel-ops.c | 4 +-- target/i386/whpx/whpx-all.c | 2 +- target/s390x/cpu-sysemu.c | 2 +- tests/unit/test-hbitmap.c | 2 +- tests/unit/test-qmp-cmds.c | 14 ++++---- tests/unit/test-qobject-output-visitor.c | 2 +- tests/unit/test-vmstate.c | 42 ++++++++++++------------ ui/vnc-enc-tight.c | 2 +- util/envlist.c | 2 +- util/hbitmap.c | 2 +- util/main-loop.c | 2 +- util/qemu-timer.c | 2 +- util/vfio-helpers.c | 4 +-- 102 files changed, 195 insertions(+), 200 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 88ef114689..ee071e07d1 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -520,7 +520,7 @@ static inline QEMUTimer *timer_new_full(QEMUTimerListGr= oup *timer_list_group, int scale, int attributes, QEMUTimerCB *cb, void *opaque) { - QEMUTimer *ts =3D g_malloc0(sizeof(QEMUTimer)); + QEMUTimer *ts =3D g_new0(QEMUTimer, 1); timer_init_full(ts, timer_list_group, type, scale, attributes, cb, opa= que); return ts; } diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 0e66ebb497..1510856a3b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1646,7 +1646,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMem= oryListener *kml, { int i; =20 - kml->slots =3D g_malloc0(s->nr_slots * sizeof(KVMSlot)); + kml->slots =3D g_new0(KVMSlot, s->nr_slots); kml->as_id =3D as_id; =20 for (i =3D 0; i < s->nr_slots; i++) { @@ -1941,7 +1941,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) return virq; } =20 - route =3D g_malloc0(sizeof(KVMMSIRoute)); + route =3D g_new0(KVMMSIRoute, 1); route->kroute.gsi =3D virq; route->kroute.type =3D KVM_IRQ_ROUTING_MSI; route->kroute.flags =3D 0; @@ -3243,7 +3243,7 @@ int kvm_insert_breakpoint(CPUState *cpu, target_ulong= addr, return 0; } =20 - bp =3D g_malloc(sizeof(struct kvm_sw_breakpoint)); + bp =3D g_new(struct kvm_sw_breakpoint, 1); bp->pc =3D addr; bp->use_count =3D 1; err =3D kvm_arch_insert_sw_breakpoint(cpu, bp); diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttc= g.c index dc421c8fd7..ea2b741deb 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -143,7 +143,7 @@ void mttcg_start_vcpu_thread(CPUState *cpu) g_assert(tcg_enabled()); tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1); =20 - cpu->thread =3D g_malloc0(sizeof(QemuThread)); + cpu->thread =3D g_new0(QemuThread, 1); cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu->halt_cond); =20 diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index a805fb6bdd..b287110766 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -280,8 +280,8 @@ void rr_start_vcpu_thread(CPUState *cpu) tcg_cpu_init_cflags(cpu, false); =20 if (!single_tcg_cpu_thread) { - cpu->thread =3D g_malloc0(sizeof(QemuThread)); - cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); + cpu->thread =3D g_new0(QemuThread, 1); + cpu->halt_cond =3D g_new0(QemuCond, 1); qemu_cond_init(cpu->halt_cond); =20 /* share a single thread for all cpus with TCG */ diff --git a/audio/audio.c b/audio/audio.c index a88572e713..4c20a4bf58 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1734,7 +1734,7 @@ static AudioState *audio_init(Audiodev *dev, const ch= ar *name) audio_validate_opts(dev, &error_abort); } =20 - s =3D g_malloc0(sizeof(AudioState)); + s =3D g_new0(AudioState, 1); s->dev =3D dev; =20 QLIST_INIT (&s->hw_head_out); @@ -2109,7 +2109,7 @@ void audio_parse_option(const char *opt) =20 audio_validate_opts(dev, &error_fatal); =20 - e =3D g_malloc0(sizeof(AudiodevListEntry)); + e =3D g_new0(AudiodevListEntry, 1); e->dev =3D dev; QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next); } diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 0fe827b057..595949f52c 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -328,8 +328,8 @@ static void handle_per_direction( =20 static AudiodevListEntry *legacy_opt(const char *drvname) { - AudiodevListEntry *e =3D g_malloc0(sizeof(AudiodevListEntry)); - e->dev =3D g_malloc0(sizeof(Audiodev)); + AudiodevListEntry *e =3D g_new0(AudiodevListEntry, 1); + e->dev =3D g_new0(Audiodev, 1); e->dev->id =3D g_strdup(drvname); e->dev->driver =3D qapi_enum_parse( &AudiodevDriver_lookup, drvname, -1, &error_abort); @@ -508,7 +508,7 @@ static void lv_free(Visitor *v) =20 static Visitor *legacy_visitor_new(void) { - LegacyPrintVisitor *lv =3D g_malloc0(sizeof(LegacyPrintVisitor)); + LegacyPrintVisitor *lv =3D g_new0(LegacyPrintVisitor, 1); =20 lv->visitor.start_struct =3D lv_start_struct; lv->visitor.end_struct =3D lv_end_struct; diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index 231f3e65b3..2b41db217e 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -623,7 +623,7 @@ static void *dsound_audio_init(Audiodev *dev) { int err; HRESULT hr; - dsound *s =3D g_malloc0(sizeof(dsound)); + dsound *s =3D g_new0(dsound, 1); AudiodevDsoundOptions *dso; =20 assert(dev->driver =3D=3D AUDIODEV_DRIVER_DSOUND); diff --git a/audio/jackaudio.c b/audio/jackaudio.c index bf757250b5..5bdf3d7a78 100644 --- a/audio/jackaudio.c +++ b/audio/jackaudio.c @@ -97,9 +97,9 @@ static void qjack_buffer_create(QJackBuffer *buffer, int = channels, int frames) buffer->used =3D 0; buffer->rptr =3D 0; buffer->wptr =3D 0; - buffer->data =3D g_malloc(channels * sizeof(float *)); + buffer->data =3D g_new(float *, channels); for (int i =3D 0; i < channels; ++i) { - buffer->data[i] =3D g_malloc(frames * sizeof(float)); + buffer->data[i] =3D g_new(float, frames); } } =20 @@ -453,7 +453,7 @@ static int qjack_client_init(QJackClient *c) jack_on_shutdown(c->client, qjack_shutdown, c); =20 /* allocate and register the ports */ - c->port =3D g_malloc(sizeof(jack_port_t *) * c->nchannels); + c->port =3D g_new(jack_port_t *, c->nchannels); for (int i =3D 0; i < c->nchannels; ++i) { =20 char port_name[16]; diff --git a/audio/paaudio.c b/audio/paaudio.c index a53ed85e0b..ed4f4376c4 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -760,7 +760,7 @@ static int qpa_validate_per_direction_opts(Audiodev *de= v, /* common */ static void *qpa_conn_init(const char *server) { - PAConnection *c =3D g_malloc0(sizeof(PAConnection)); + PAConnection *c =3D g_new0(PAConnection, 1); QTAILQ_INSERT_TAIL(&pa_conns, c, list); =20 c->mainloop =3D pa_threaded_mainloop_new(); @@ -849,7 +849,7 @@ static void *qpa_audio_init(Audiodev *dev) return NULL; } =20 - g =3D g_malloc0(sizeof(paaudio)); + g =3D g_new0(paaudio, 1); server =3D popts->has_server ? popts->server : NULL; =20 g->dev =3D dev; diff --git a/backends/cryptodev.c b/backends/cryptodev.c index bf52476166..2b105e433c 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -39,7 +39,7 @@ cryptodev_backend_new_client(const char *model, { CryptoDevBackendClient *cc; =20 - cc =3D g_malloc0(sizeof(CryptoDevBackendClient)); + cc =3D g_new0(CryptoDevBackendClient, 1); cc->model =3D g_strdup(model); if (name) { cc->name =3D g_strdup(name); diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index 611360e6b4..bfb8d93cf8 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -455,7 +455,7 @@ vg_create_mapping_iov(VuGpu *g, return -1; } =20 - *iov =3D g_malloc0(sizeof(struct iovec) * ab->nr_entries); + *iov =3D g_new0(struct iovec, ab->nr_entries); for (i =3D 0; i < ab->nr_entries; i++) { uint64_t len =3D ents[i].length; (*iov)[i].iov_len =3D ents[i].length; diff --git a/cpus-common.c b/cpus-common.c index 6e73d3e58d..db459b41ce 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -160,7 +160,7 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func fu= nc, run_on_cpu_data data) { struct qemu_work_item *wi; =20 - wi =3D g_malloc0(sizeof(struct qemu_work_item)); + wi =3D g_new0(struct qemu_work_item, 1); wi->func =3D func; wi->data =3D data; wi->free =3D true; @@ -305,7 +305,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_fu= nc func, { struct qemu_work_item *wi; =20 - wi =3D g_malloc0(sizeof(struct qemu_work_item)); + wi =3D g_new0(struct qemu_work_item, 1); wi->func =3D func; wi->data =3D data; wi->free =3D true; diff --git a/dump/dump.c b/dump/dump.c index a84d8b1598..f57ed76fa7 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -2041,7 +2041,7 @@ void qmp_dump_guest_memory(bool paging, const char *f= ile, DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **= errp) { DumpGuestMemoryCapability *cap =3D - g_malloc0(sizeof(DumpGuestMemoryCapabili= ty)); + g_new0(DumpGuestMemoryCapability, 1); DumpGuestMemoryFormatList **tail =3D &cap->formats; =20 /* elf is always available */ diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 6913ebf730..3a6d51282a 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -128,7 +128,7 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB_I= nfo *hmat_lb, } =20 /* Latency or Bandwidth Entries */ - entry_list =3D g_malloc0(num_initiator * num_target * sizeof(uint16_t)= ); + entry_list =3D g_new0(uint16_t, num_initiator * num_target); for (i =3D 0; i < hmat_lb->list->len; i++) { lb_data =3D &g_array_index(hmat_lb->list, HMAT_LB_Data, i); index =3D lb_data->initiator * num_target + lb_data->target; diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c index 5f8a878f20..686fb94d5c 100644 --- a/hw/audio/intel-hda.c +++ b/hw/audio/intel-hda.c @@ -473,7 +473,7 @@ static void intel_hda_parse_bdl(IntelHDAState *d, Intel= HDAStream *st) addr =3D intel_hda_addr(st->bdlp_lbase, st->bdlp_ubase); st->bentries =3D st->lvi +1; g_free(st->bpl); - st->bpl =3D g_malloc(sizeof(bpl) * st->bentries); + st->bpl =3D g_new(bpl, st->bentries); for (i =3D 0; i < st->bentries; i++, addr +=3D 16) { pci_dma_read(&d->pci, addr, buf, 16); st->bpl[i].addr =3D le64_to_cpu(*(uint64_t *)buf); diff --git a/hw/char/parallel.c b/hw/char/parallel.c index adb9bd9be3..f735a6cd7f 100644 --- a/hw/char/parallel.c +++ b/hw/char/parallel.c @@ -622,7 +622,7 @@ bool parallel_mm_init(MemoryRegion *address_space, { ParallelState *s; =20 - s =3D g_malloc0(sizeof(ParallelState)); + s =3D g_new0(ParallelState, 1); s->irq =3D irq; qemu_chr_fe_init(&s->chr, chr, &error_abort); s->it_shift =3D it_shift; diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 729edbf968..6577f0e640 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -248,7 +248,7 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, Me= moryRegion *main_mem, tohost_offset =3D tohost_addr - base; fromhost_offset =3D fromhost_addr - base; =20 - HTIFState *s =3D g_malloc0(sizeof(HTIFState)); + HTIFState *s =3D g_new0(HTIFState, 1); s->address_space =3D address_space; s->main_mem =3D main_mem; s->main_mem_ram_ptr =3D memory_region_get_ram_ptr(main_mem); diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index f01ec2137c..6048d408b8 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -1055,10 +1055,8 @@ static void virtio_serial_device_realize(DeviceState= *dev, Error **errp) QTAILQ_INIT(&vser->ports); =20 vser->bus.max_nr_ports =3D vser->serial.max_virtserial_ports; - vser->ivqs =3D g_malloc(vser->serial.max_virtserial_ports - * sizeof(VirtQueue *)); - vser->ovqs =3D g_malloc(vser->serial.max_virtserial_ports - * sizeof(VirtQueue *)); + vser->ivqs =3D g_new(VirtQueue *, vser->serial.max_virtserial_ports); + vser->ovqs =3D g_new(VirtQueue *, vser->serial.max_virtserial_ports); =20 /* Add a queue for host to guest transfers for port 0 (backward compat= ) */ vser->ivqs[0] =3D virtio_add_queue(vdev, 128, handle_input); diff --git a/hw/core/irq.c b/hw/core/irq.c index 8a9cbdd556..741219277b 100644 --- a/hw/core/irq.c +++ b/hw/core/irq.c @@ -115,7 +115,7 @@ static void qemu_splitirq(void *opaque, int line, int l= evel) =20 qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2) { - qemu_irq *s =3D g_malloc0(2 * sizeof(qemu_irq)); + qemu_irq *s =3D g_new0(qemu_irq, 2); s[0] =3D irq1; s[1] =3D irq2; return qemu_allocate_irq(qemu_splitirq, s, 0); diff --git a/hw/core/reset.c b/hw/core/reset.c index 9c477f2bf5..36be82c491 100644 --- a/hw/core/reset.c +++ b/hw/core/reset.c @@ -40,7 +40,7 @@ static QTAILQ_HEAD(, QEMUResetEntry) reset_handlers =3D =20 void qemu_register_reset(QEMUResetHandler *func, void *opaque) { - QEMUResetEntry *re =3D g_malloc0(sizeof(QEMUResetEntry)); + QEMUResetEntry *re =3D g_new0(QEMUResetEntry, 1); =20 re->func =3D func; re->opaque =3D opaque; diff --git a/hw/display/pxa2xx_lcd.c b/hw/display/pxa2xx_lcd.c index 2887ce496b..0f06ed6e9f 100644 --- a/hw/display/pxa2xx_lcd.c +++ b/hw/display/pxa2xx_lcd.c @@ -1427,7 +1427,7 @@ PXA2xxLCDState *pxa2xx_lcdc_init(MemoryRegion *sysmem, { PXA2xxLCDState *s; =20 - s =3D (PXA2xxLCDState *) g_malloc0(sizeof(PXA2xxLCDState)); + s =3D g_new0(PXA2xxLCDState, 1); s->invalidated =3D 1; s->irq =3D irq; s->sysmem =3D sysmem; diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c index 1f28223c7b..c7beba453b 100644 --- a/hw/display/tc6393xb.c +++ b/hw/display/tc6393xb.c @@ -540,7 +540,7 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint= 32_t base, qemu_irq irq) }, }; =20 - s =3D (TC6393xbState *) g_malloc0(sizeof(TC6393xbState)); + s =3D g_new0(TC6393xbState, 1); s->irq =3D irq; s->gpio_in =3D qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS= ); =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index c6dc818988..529b5246b2 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -831,9 +831,9 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, } =20 if (!(v % 16)) { - *iov =3D g_realloc(*iov, sizeof(struct iovec) * (v + 16)); + *iov =3D g_renew(struct iovec, *iov, v + 16); if (addr) { - *addr =3D g_realloc(*addr, sizeof(uint64_t) * (v + 16)= ); + *addr =3D g_renew(uint64_t, *addr, v + 16); } } (*iov)[v].iov_base =3D map; diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 838260b6ad..cea10fe3c7 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -496,8 +496,8 @@ static int xenfb_map_fb(struct XenFB *xenfb) n_fbdirs =3D xenfb->fbpages * mode / 8; n_fbdirs =3D DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE); =20 - pgmfns =3D g_malloc0(sizeof(xen_pfn_t) * n_fbdirs); - fbmfns =3D g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages); + pgmfns =3D g_new0(xen_pfn_t, n_fbdirs); + fbmfns =3D g_new0(xen_pfn_t, xenfb->fbpages); =20 xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd); map =3D xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom, diff --git a/hw/dma/rc4030.c b/hw/dma/rc4030.c index e4d2f1725b..aa1d323a36 100644 --- a/hw/dma/rc4030.c +++ b/hw/dma/rc4030.c @@ -646,8 +646,8 @@ static rc4030_dma *rc4030_allocate_dmas(void *opaque, i= nt n) struct rc4030DMAState *p; int i; =20 - s =3D (rc4030_dma *)g_new0(rc4030_dma, n); - p =3D (struct rc4030DMAState *)g_new0(struct rc4030DMAState, n); + s =3D g_new0(rc4030_dma, n); + p =3D g_new0(struct rc4030DMAState, n); for (i =3D 0; i < n; i++) { p->opaque =3D opaque; p->n =3D i; diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 0e7d2763b9..d0cb2d32fa 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -274,7 +274,7 @@ static int i2c_slave_post_load(void *opaque, int versio= n_id) bus =3D I2C_BUS(qdev_get_parent_bus(DEVICE(dev))); if ((bus->saved_address =3D=3D dev->address) || (bus->saved_address =3D=3D I2C_BROADCAST)) { - node =3D g_malloc(sizeof(struct I2CNode)); + node =3D g_new(struct I2CNode, 1); node->elt =3D dev; QLIST_INSERT_HEAD(&bus->current_devs, node, next); } @@ -319,7 +319,7 @@ static bool i2c_slave_match(I2CSlave *candidate, uint8_= t address, bool broadcast, I2CNodeList *current_devs) { if ((candidate->address =3D=3D address) || (broadcast)) { - I2CNode *node =3D g_malloc(sizeof(struct I2CNode)); + I2CNode *node =3D g_new(struct I2CNode, 1); node->elt =3D candidate; QLIST_INSERT_HEAD(current_devs, node, next); return true; diff --git a/hw/i2c/i2c_mux_pca954x.c b/hw/i2c/i2c_mux_pca954x.c index a9517b612a..3945de795c 100644 --- a/hw/i2c/i2c_mux_pca954x.c +++ b/hw/i2c/i2c_mux_pca954x.c @@ -71,7 +71,7 @@ static bool pca954x_match(I2CSlave *candidate, uint8_t ad= dress, =20 /* They are talking to the mux itself (or all devices enabled). */ if ((candidate->address =3D=3D address) || broadcast) { - I2CNode *node =3D g_malloc(sizeof(struct I2CNode)); + I2CNode *node =3D g_new(struct I2CNode, 1); node->elt =3D candidate; QLIST_INSERT_HEAD(current_devs, node, next); if (!broadcast) { diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 4d13d8e697..9dd9b0ecf2 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -1405,7 +1405,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus= , void *opaque, int devfn) =20 /* allocate memory during the first run */ if (!iommu_as) { - iommu_as =3D g_malloc0(sizeof(AMDVIAddressSpace *) * PCI_DEVFN_MAX= ); + iommu_as =3D g_new0(AMDVIAddressSpace *, PCI_DEVFN_MAX); s->address_spaces[bus_num] =3D iommu_as; } =20 @@ -1413,7 +1413,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus= , void *opaque, int devfn) if (!iommu_as[devfn]) { snprintf(name, sizeof(name), "amd_iommu_devfn_%d", devfn); =20 - iommu_as[devfn] =3D g_malloc0(sizeof(AMDVIAddressSpace)); + iommu_as[devfn] =3D g_new0(AMDVIAddressSpace, 1); iommu_as[devfn]->bus_num =3D (uint8_t)bus_num; iommu_as[devfn]->devfn =3D (uint8_t)devfn; iommu_as[devfn]->iommu_state =3D s; diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 32471a44cb..c64aa81a83 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3416,7 +3416,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, = PCIBus *bus, int devfn) if (!vtd_dev_as) { snprintf(name, sizeof(name), "vtd-%02x.%x", PCI_SLOT(devfn), PCI_FUNC(devfn)); - vtd_bus->dev_as[devfn] =3D vtd_dev_as =3D g_malloc0(sizeof(VTDAddr= essSpace)); + vtd_bus->dev_as[devfn] =3D vtd_dev_as =3D g_new0(VTDAddressSpace, = 1); =20 vtd_dev_as->bus =3D bus; vtd_dev_as->devfn =3D (uint8_t)devfn; diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index cf8e500514..0731f70410 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -396,7 +396,7 @@ go_physmap: =20 mr_name =3D memory_region_name(mr); =20 - physmap =3D g_malloc(sizeof(XenPhysmap)); + physmap =3D g_new(XenPhysmap, 1); =20 physmap->start_addr =3D start_addr; physmap->size =3D size; @@ -1281,7 +1281,7 @@ static void xen_read_physmap(XenIOState *state) return; =20 for (i =3D 0; i < num; i++) { - physmap =3D g_malloc(sizeof (XenPhysmap)); + physmap =3D g_new(XenPhysmap, 1); physmap->phys_offset =3D strtoull(entries[i], NULL, 16); snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/physmap/%s/start_addr", @@ -1410,7 +1410,7 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegi= on **ram_memory) xen_pfn_t ioreq_pfn; XenIOState *state; =20 - state =3D g_malloc0(sizeof (XenIOState)); + state =3D g_new0(XenIOState, 1); =20 state->xce_handle =3D xenevtchn_open(NULL, 0); if (state->xce_handle =3D=3D NULL) { @@ -1463,7 +1463,7 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegi= on **ram_memory) } =20 /* Note: cpus is empty at this point in init */ - state->cpu_by_vcpu_id =3D g_malloc0(max_cpus * sizeof(CPUState *)); + state->cpu_by_vcpu_id =3D g_new0(CPUState *, max_cpus); =20 rc =3D xen_set_ioreq_server_state(xen_domid, state->ioservid, true); if (rc < 0) { @@ -1472,7 +1472,7 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegi= on **ram_memory) goto err; } =20 - state->ioreq_local_port =3D g_malloc0(max_cpus * sizeof (evtchn_port_t= )); + state->ioreq_local_port =3D g_new0(evtchn_port_t, max_cpus); =20 /* FIXME: how about if we overflow the page here? */ for (i =3D 0; i < max_cpus; i++) { diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index f2ef977963..a2f93096e7 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -108,7 +108,7 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void = *opaque) unsigned long size; struct rlimit rlimit_as; =20 - mapcache =3D g_malloc0(sizeof (MapCache)); + mapcache =3D g_new0(MapCache, 1); =20 mapcache->phys_offset_to_gaddr =3D f; mapcache->opaque =3D opaque; @@ -164,8 +164,8 @@ static void xen_remap_bucket(MapCacheEntry *entry, =20 trace_xen_remap_bucket(address_index); =20 - pfns =3D g_malloc0(nb_pfn * sizeof (xen_pfn_t)); - err =3D g_malloc0(nb_pfn * sizeof (int)); + pfns =3D g_new0(xen_pfn_t, nb_pfn); + err =3D g_new0(int, nb_pfn); =20 if (entry->vaddr_base !=3D NULL) { if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) { @@ -231,8 +231,8 @@ static void xen_remap_bucket(MapCacheEntry *entry, entry->vaddr_base =3D vaddr_base; entry->paddr_index =3D address_index; entry->size =3D size; - entry->valid_mapping =3D (unsigned long *) g_malloc0(sizeof(unsigned l= ong) * - BITS_TO_LONGS(size >> XC_PAGE_SHIFT)); + entry->valid_mapping =3D g_new0(unsigned long, + BITS_TO_LONGS(size >> XC_PAGE_SHIFT)); =20 if (dummy) { entry->flags |=3D XEN_MAPCACHE_ENTRY_DUMMY; @@ -319,7 +319,7 @@ tryagain: pentry =3D free_pentry; } if (!entry) { - entry =3D g_malloc0(sizeof (MapCacheEntry)); + entry =3D g_new0(MapCacheEntry, 1); pentry->next =3D entry; xen_remap_bucket(entry, NULL, cache_size, address_index, dummy); } else if (!entry->lock) { @@ -353,7 +353,7 @@ tryagain: =20 mapcache->last_entry =3D entry; if (lock) { - MapCacheRev *reventry =3D g_malloc0(sizeof(MapCacheRev)); + MapCacheRev *reventry =3D g_new0(MapCacheRev, 1); entry->lock++; if (entry->lock =3D=3D 0) { fprintf(stderr, diff --git a/hw/input/lasips2.c b/hw/input/lasips2.c index 68d741d342..94f18be4cd 100644 --- a/hw/input/lasips2.c +++ b/hw/input/lasips2.c @@ -266,7 +266,7 @@ void lasips2_init(MemoryRegion *address_space, { LASIPS2State *s; =20 - s =3D g_malloc0(sizeof(LASIPS2State)); + s =3D g_new0(LASIPS2State, 1); =20 s->irq =3D irq; s->mouse.id =3D 1; diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 1773db0d25..4efdf75620 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -649,7 +649,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, MemoryRegion *region, ram_addr_t size, hwaddr mask) { - KBDState *s =3D g_malloc0(sizeof(KBDState)); + KBDState *s =3D g_new0(KBDState, 1); =20 s->irq_kbd =3D kbd_irq; s->irq_mouse =3D mouse_irq; diff --git a/hw/input/ps2.c b/hw/input/ps2.c index 6236711e1b..c16df1de7a 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -1226,7 +1226,7 @@ static QemuInputHandler ps2_keyboard_handler =3D { =20 void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg) { - PS2KbdState *s =3D (PS2KbdState *)g_malloc0(sizeof(PS2KbdState)); + PS2KbdState *s =3D g_new0(PS2KbdState, 1); =20 trace_ps2_kbd_init(s); s->common.update_irq =3D update_irq; @@ -1248,7 +1248,7 @@ static QemuInputHandler ps2_mouse_handler =3D { =20 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg) { - PS2MouseState *s =3D (PS2MouseState *)g_malloc0(sizeof(PS2MouseState)); + PS2MouseState *s =3D g_new0(PS2MouseState, 1); =20 trace_ps2_mouse_init(s); s->common.update_irq =3D update_irq; diff --git a/hw/input/pxa2xx_keypad.c b/hw/input/pxa2xx_keypad.c index 7f2f739fb3..3dd03e8c9f 100644 --- a/hw/input/pxa2xx_keypad.c +++ b/hw/input/pxa2xx_keypad.c @@ -306,7 +306,7 @@ PXA2xxKeyPadState *pxa27x_keypad_init(MemoryRegion *sys= mem, { PXA2xxKeyPadState *s; =20 - s =3D (PXA2xxKeyPadState *) g_malloc0(sizeof(PXA2xxKeyPadState)); + s =3D g_new0(PXA2xxKeyPadState, 1); s->irq =3D irq; =20 memory_region_init_io(&s->iomem, NULL, &pxa2xx_keypad_ops, s, diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c index 55d61cc843..14698ce109 100644 --- a/hw/input/tsc2005.c +++ b/hw/input/tsc2005.c @@ -489,8 +489,7 @@ void *tsc2005_init(qemu_irq pintdav) { TSC2005State *s; =20 - s =3D (TSC2005State *) - g_malloc0(sizeof(TSC2005State)); + s =3D g_new0(TSC2005State, 1); s->x =3D 400; s->y =3D 240; s->pressure =3D false; diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c index f1a5d3d284..e43b050e92 100644 --- a/hw/intc/riscv_aclint.c +++ b/hw/intc/riscv_aclint.c @@ -235,7 +235,7 @@ static void riscv_aclint_mtimer_realize(DeviceState *de= v, Error **errp) s, TYPE_RISCV_ACLINT_MTIMER, s->aperture_size); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio); =20 - s->timer_irqs =3D g_malloc(sizeof(qemu_irq) * s->num_harts); + s->timer_irqs =3D g_new(qemu_irq, s->num_harts); qdev_init_gpio_out(dev, s->timer_irqs, s->num_harts); =20 /* Claim timer interrupt bits */ @@ -292,7 +292,7 @@ DeviceState *riscv_aclint_mtimer_create(hwaddr addr, hw= addr size, RISCVCPU *rvcpu =3D RISCV_CPU(cpu); CPURISCVState *env =3D cpu ? cpu->env_ptr : NULL; riscv_aclint_mtimer_callback *cb =3D - g_malloc0(sizeof(riscv_aclint_mtimer_callback)); + g_new0(riscv_aclint_mtimer_callback, 1); =20 if (!env) { g_free(cb); @@ -393,7 +393,7 @@ static void riscv_aclint_swi_realize(DeviceState *dev, = Error **errp) TYPE_RISCV_ACLINT_SWI, RISCV_ACLINT_SWI_SIZE); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &swi->mmio); =20 - swi->soft_irqs =3D g_malloc(sizeof(qemu_irq) * swi->num_harts); + swi->soft_irqs =3D g_new(qemu_irq, swi->num_harts); qdev_init_gpio_out(dev, swi->soft_irqs, swi->num_harts); =20 /* Claim software interrupt bits */ diff --git a/hw/intc/xics.c b/hw/intc/xics.c index 48a835eab7..24e67020db 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -604,7 +604,7 @@ static void ics_realize(DeviceState *dev, Error **errp) error_setg(errp, "Number of interrupts needs to be greater 0"); return; } - ics->irqs =3D g_malloc0(ics->nr_irqs * sizeof(ICSIRQState)); + ics->irqs =3D g_new0(ICSIRQState, ics->nr_irqs); =20 qemu_register_reset(ics_reset_handler, ics); } diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index bbaf630bbf..8e630282e0 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -132,7 +132,7 @@ static void virt_init(MachineState *machine) exit(1); } =20 - reset_info =3D g_malloc0(sizeof(ResetInfo)); + reset_info =3D g_new0(ResetInfo, 1); =20 /* init CPUs */ cpu =3D M68K_CPU(cpu_create(machine->cpu_type)); diff --git a/hw/mips/mipssim.c b/hw/mips/mipssim.c index 2325e7e05a..27a46bd538 100644 --- a/hw/mips/mipssim.c +++ b/hw/mips/mipssim.c @@ -162,7 +162,7 @@ mips_mipssim_init(MachineState *machine) cpu =3D mips_cpu_create_with_clock(machine->cpu_type, cpuclk); env =3D &cpu->env; =20 - reset_info =3D g_malloc0(sizeof(ResetData)); + reset_info =3D g_new0(ResetData, 1); reset_info->cpu =3D cpu; reset_info->vector =3D env->active_tc.PC; qemu_register_reset(main_cpu_reset, reset_info); diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c index 1b9acaf1d3..81cd6b6423 100644 --- a/hw/misc/applesmc.c +++ b/hw/misc/applesmc.c @@ -253,7 +253,7 @@ static void applesmc_add_key(AppleSMCState *s, const ch= ar *key, { struct AppleSMCData *def; =20 - def =3D g_malloc0(sizeof(struct AppleSMCData)); + def =3D g_new0(struct AppleSMCData, 1); def->key =3D key; def->len =3D len; def->data =3D data; diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c index 79f4375911..7b0e968804 100644 --- a/hw/misc/imx6_src.c +++ b/hw/misc/imx6_src.c @@ -151,7 +151,7 @@ static void imx6_defer_clear_reset_bit(int cpuid, return; } =20 - ri =3D g_malloc(sizeof(struct SRCSCRResetInfo)); + ri =3D g_new(struct SRCSCRResetInfo, 1); ri->s =3D s; ri->reset_bit =3D reset_shift; =20 diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 299837e5c1..b54778ada5 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -411,7 +411,7 @@ static void resize_peers(IVShmemState *s, int nb_peers) assert(nb_peers > old_nb_peers); IVSHMEM_DPRINTF("bumping storage to %d peers\n", nb_peers); =20 - s->peers =3D g_realloc(s->peers, nb_peers * sizeof(Peer)); + s->peers =3D g_renew(Peer, s->peers, nb_peers); s->nb_peers =3D nb_peers; =20 for (i =3D old_nb_peers; i < nb_peers; i++) { @@ -728,7 +728,7 @@ static void ivshmem_reset(DeviceState *d) static int ivshmem_setup_interrupts(IVShmemState *s, Error **errp) { /* allocate QEMU callback data for receiving interrupts */ - s->msi_vectors =3D g_malloc0(s->vectors * sizeof(MSIVector)); + s->msi_vectors =3D g_new0(MSIVector, s->vectors); =20 if (ivshmem_has_feature(s, IVSHMEM_MSI)) { if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1, errp)) { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b02a0632df..bd121103f3 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1994,7 +1994,7 @@ static void virtio_net_rsc_cache_buf(VirtioNetRscChai= n *chain, VirtioNetRscSeg *seg; =20 hdr_len =3D chain->n->guest_hdr_len; - seg =3D g_malloc(sizeof(VirtioNetRscSeg)); + seg =3D g_new(VirtioNetRscSeg, 1); seg->buf =3D g_malloc(hdr_len + sizeof(struct eth_header) + sizeof(struct ip6_header) + VIRTIO_NET_MAX_TCP_PAYLOAD); memcpy(seg->buf, buf, size); @@ -3442,7 +3442,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) virtio_cleanup(vdev); return; } - n->vqs =3D g_malloc0(sizeof(VirtIONetQueue) * n->max_queue_pairs); + n->vqs =3D g_new0(VirtIONetQueue, n->max_queue_pairs); n->curr_queue_pairs =3D 1; n->tx_timeout =3D n->net_conf.txtimer; =20 diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 8a3613d9ab..324f53ea0c 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -268,7 +268,7 @@ static void nvme_ns_init_zoned(NvmeNamespace *ns) =20 nvme_ns_zoned_init_state(ns); =20 - id_ns_z =3D g_malloc0(sizeof(NvmeIdNsZoned)); + id_ns_z =3D g_new0(NvmeIdNsZoned, 1); =20 /* MAR/MOR are zeroes-based, FFFFFFFFFh means no limit */ id_ns_z->mar =3D cpu_to_le32(ns->params.max_active_zones - 1); diff --git a/hw/pci-host/pnv_phb3.c b/hw/pci-host/pnv_phb3.c index aafd46b635..ac6fe48975 100644 --- a/hw/pci-host/pnv_phb3.c +++ b/hw/pci-host/pnv_phb3.c @@ -946,7 +946,7 @@ static AddressSpace *pnv_phb3_dma_iommu(PCIBus *bus, vo= id *opaque, int devfn) } =20 if (ds =3D=3D NULL) { - ds =3D g_malloc0(sizeof(PnvPhb3DMASpace)); + ds =3D g_new0(PnvPhb3DMASpace, 1); ds->bus =3D bus; ds->devfn =3D devfn; ds->pe_num =3D PHB_INVALID_PE; diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c index b5b384e9ee..d0d1612e1e 100644 --- a/hw/pci-host/pnv_phb4.c +++ b/hw/pci-host/pnv_phb4.c @@ -1466,7 +1466,7 @@ static AddressSpace *pnv_phb4_dma_iommu(PCIBus *bus, = void *opaque, int devfn) ds =3D pnv_phb4_dma_find(phb, bus, devfn); =20 if (ds =3D=3D NULL) { - ds =3D g_malloc0(sizeof(PnvPhb4DMASpace)); + ds =3D g_new0(PnvPhb4DMASpace, 1); ds->bus =3D bus; ds->devfn =3D devfn; ds->pe_num =3D PHB_INVALID_PE; diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 87abad6ac8..8e3faf1f59 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -177,7 +177,7 @@ static void register_vfs(PCIDevice *dev) assert(sriov_cap > 0); num_vfs =3D pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); =20 - dev->exp.sriov_pf.vf =3D g_malloc(sizeof(PCIDevice *) * num_vfs); + dev->exp.sriov_pf.vf =3D g_new(PCIDevice *, num_vfs); assert(dev->exp.sriov_pf.vf); =20 trace_sriov_register_vfs(dev->name, PCI_SLOT(dev->devfn), diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 960e7efcd3..c7e6767f91 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -899,7 +899,7 @@ void ppce500_init(MachineState *machine) if (!i) { /* Primary CPU */ struct boot_info *boot_info; - boot_info =3D g_malloc0(sizeof(struct boot_info)); + boot_info =3D g_new0(struct boot_info, 1); qemu_register_reset(ppce500_cpu_reset, cpu); env->load_info =3D boot_info; } else { diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 9e99625ea9..faa02d6710 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -1063,7 +1063,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint3= 2_t freq) PowerPCCPU *cpu =3D env_archcpu(env); ppc_tb_t *tb_env; =20 - tb_env =3D g_malloc0(sizeof(ppc_tb_t)); + tb_env =3D g_new0(ppc_tb_t, 1); env->tb_env =3D tb_env; tb_env->flags =3D PPC_DECR_UNDERFLOW_TRIGGERED; if (is_book3s_arch2x(env)) { @@ -1338,8 +1338,8 @@ clk_setup_cb ppc_40x_timers_init (CPUPPCState *env, u= int32_t freq, =20 trace_ppc40x_timers_init(freq); =20 - tb_env =3D g_malloc0(sizeof(ppc_tb_t)); - ppc40x_timer =3D g_malloc0(sizeof(ppc40x_timer_t)); + tb_env =3D g_new0(ppc_tb_t, 1); + ppc40x_timer =3D g_new0(ppc40x_timer_t, 1); =20 env->tb_env =3D tb_env; tb_env->flags =3D PPC_DECR_UNDERFLOW_TRIGGERED; @@ -1447,7 +1447,7 @@ int ppc_dcr_init (CPUPPCState *env, int (*read_error)= (int dcrn), { ppc_dcr_t *dcr_env; =20 - dcr_env =3D g_malloc0(sizeof(ppc_dcr_t)); + dcr_env =3D g_new0(ppc_dcr_t, 1); dcr_env->read_error =3D read_error; dcr_env->write_error =3D write_error; env->dcr_env =3D dcr_env; diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c index 3ae2b36373..7e1a4ac955 100644 --- a/hw/ppc/ppc405_boards.c +++ b/hw/ppc/ppc405_boards.c @@ -130,7 +130,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, ui= nt32_t base) ref405ep_fpga_t *fpga; MemoryRegion *fpga_memory =3D g_new(MemoryRegion, 1); =20 - fpga =3D g_malloc0(sizeof(ref405ep_fpga_t)); + fpga =3D g_new0(ref405ep_fpga_t, 1); memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga, "fpga", 0x00000100); memory_region_add_subregion(sysmem, base, fpga_memory); @@ -431,7 +431,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint3= 2_t base) taihu_cpld_t *cpld; MemoryRegion *cpld_memory =3D g_new(MemoryRegion, 1); =20 - cpld =3D g_malloc0(sizeof(taihu_cpld_t)); + cpld =3D g_new0(taihu_cpld_t, 1); memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld"= , 0x100); memory_region_add_subregion(sysmem, base, cpld_memory); qemu_register_reset(&taihu_cpld_reset, cpld); diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c index 8aacd275a6..36c8ba6f3c 100644 --- a/hw/ppc/ppc405_uc.c +++ b/hw/ppc/ppc405_uc.c @@ -215,7 +215,7 @@ void ppc4xx_plb_init(CPUPPCState *env) { ppc4xx_plb_t *plb; =20 - plb =3D g_malloc0(sizeof(ppc4xx_plb_t)); + plb =3D g_new0(ppc4xx_plb_t, 1); ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb); ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb); ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb); @@ -300,7 +300,7 @@ static void ppc4xx_pob_init(CPUPPCState *env) { ppc4xx_pob_t *pob; =20 - pob =3D g_malloc0(sizeof(ppc4xx_pob_t)); + pob =3D g_new0(ppc4xx_pob_t, 1); ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob); ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob); ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob); @@ -380,7 +380,7 @@ static void ppc4xx_opba_init(hwaddr base) =20 trace_opba_init(base); =20 - opba =3D g_malloc0(sizeof(ppc4xx_opba_t)); + opba =3D g_new0(ppc4xx_opba_t, 1); memory_region_init_io(&opba->io, NULL, &opba_ops, opba, "opba", 0x002); memory_region_add_subregion(get_system_memory(), base, &opba->io); qemu_register_reset(ppc4xx_opba_reset, opba); @@ -575,7 +575,7 @@ void ppc405_ebc_init(CPUPPCState *env) { ppc4xx_ebc_t *ebc; =20 - ebc =3D g_malloc0(sizeof(ppc4xx_ebc_t)); + ebc =3D g_new0(ppc4xx_ebc_t, 1); qemu_register_reset(&ebc_reset, ebc); ppc_dcr_register(env, EBC0_CFGADDR, ebc, &dcr_read_ebc, &dcr_write_ebc); @@ -658,7 +658,7 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq = irqs[4]) { ppc405_dma_t *dma; =20 - dma =3D g_malloc0(sizeof(ppc405_dma_t)); + dma =3D g_new0(ppc405_dma_t, 1); memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq)); qemu_register_reset(&ppc405_dma_reset, dma); ppc_dcr_register(env, DMA0_CR0, @@ -757,7 +757,7 @@ static void ppc405_gpio_init(hwaddr base) =20 trace_ppc405_gpio_init(base); =20 - gpio =3D g_malloc0(sizeof(ppc405_gpio_t)); + gpio =3D g_new0(ppc405_gpio_t, 1); memory_region_init_io(&gpio->io, NULL, &ppc405_gpio_ops, gpio, "pgio",= 0x038); memory_region_add_subregion(get_system_memory(), base, &gpio->io); qemu_register_reset(&ppc405_gpio_reset, gpio); @@ -906,7 +906,7 @@ static void ppc405_ocm_init(CPUPPCState *env) { ppc405_ocm_t *ocm; =20 - ocm =3D g_malloc0(sizeof(ppc405_ocm_t)); + ocm =3D g_new0(ppc405_ocm_t, 1); /* XXX: Size is 4096 or 0x04000000 */ memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4 * KiB, &error_fatal); @@ -1148,7 +1148,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq irq= s[5]) =20 trace_ppc4xx_gpt_init(base); =20 - gpt =3D g_malloc0(sizeof(ppc4xx_gpt_t)); + gpt =3D g_new0(ppc4xx_gpt_t, 1); for (i =3D 0; i < 5; i++) { gpt->irqs[i] =3D irqs[i]; } @@ -1399,7 +1399,7 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_= setup_t clk_setup[8], { ppc405ep_cpc_t *cpc; =20 - cpc =3D g_malloc0(sizeof(ppc405ep_cpc_t)); + cpc =3D g_new0(ppc405ep_cpc_t, 1); memcpy(cpc->clk_setup, clk_setup, PPC405EP_CLK_NB * sizeof(clk_setup_t)); cpc->jtagid =3D 0x20267049; diff --git a/hw/ppc/ppc4xx_devs.c b/hw/ppc/ppc4xx_devs.c index e7d82ae501..737c0896b4 100644 --- a/hw/ppc/ppc4xx_devs.c +++ b/hw/ppc/ppc4xx_devs.c @@ -389,7 +389,7 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq,= int nbanks, { ppc4xx_sdram_t *sdram; =20 - sdram =3D g_malloc0(sizeof(ppc4xx_sdram_t)); + sdram =3D g_new0(ppc4xx_sdram_t, 1); sdram->irq =3D irq; sdram->nbanks =3D nbanks; sdram->ram_memories =3D ram_memories; diff --git a/hw/ppc/ppc_booke.c b/hw/ppc/ppc_booke.c index 10b643861f..ca22da196a 100644 --- a/hw/ppc/ppc_booke.c +++ b/hw/ppc/ppc_booke.c @@ -337,8 +337,8 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t fr= eq, uint32_t flags) booke_timer_t *booke_timer; int ret =3D 0; =20 - tb_env =3D g_malloc0(sizeof(ppc_tb_t)); - booke_timer =3D g_malloc0(sizeof(booke_timer_t)); + tb_env =3D g_new0(ppc_tb_t, 1); + booke_timer =3D g_new0(booke_timer_t, 1); =20 cpu->env.tb_env =3D tb_env; tb_env->flags =3D flags | PPC_TIMER_BOOKE | PPC_DECR_ZERO_TRIGGERED; diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 953fc65fa8..a4372ba189 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3601,7 +3601,7 @@ static SpaprDimmState *spapr_pending_dimm_unplugs_add= (SpaprMachineState *spapr, */ ds =3D spapr_pending_dimm_unplugs_find(spapr, dimm); if (!ds) { - ds =3D g_malloc0(sizeof(SpaprDimmState)); + ds =3D g_new0(SpaprDimmState, 1); ds->nr_lmbs =3D nr_lmbs; ds->dimm =3D dimm; QTAILQ_INSERT_HEAD(&spapr->pending_dimm_unplugs, ds, next); diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 630e86282c..4508e40814 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -594,7 +594,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint= 8_t hp_action, struct rtas_event_log_v6_hp *hp; =20 entry =3D g_new(SpaprEventLogEntry, 1); - new_hp =3D g_malloc0(sizeof(struct hp_extended_log)); + new_hp =3D g_new0(struct hp_extended_log, 1); entry->extended_log =3D new_hp; =20 v6hdr =3D &new_hp->v6hdr; diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index f008290787..7c8bb76f99 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1596,7 +1596,7 @@ static target_ulong h_enter_nested(PowerPCCPU *cpu, return H_PARAMETER; } =20 - spapr_cpu->nested_host_state =3D g_try_malloc(sizeof(CPUPPCState)); + spapr_cpu->nested_host_state =3D g_try_new(CPUPPCState, 1); if (!spapr_cpu->nested_host_state) { return H_NO_MEM; } diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 4f93bdefec..d7c0e212ba 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -436,8 +436,7 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachineSt= ate *spapr, void *fdt, int i; =20 /* ibm,associativity-lookup-arrays */ - int_buf =3D g_malloc0((nr_nodes * max_distance_ref_points + 2) * - sizeof(uint32_t)); + int_buf =3D g_new0(uint32_t, nr_nodes * max_distance_ref_points + 2); cur_index =3D int_buf; int_buf[0] =3D cpu_to_be32(nr_nodes); /* Number of entries per associativity list */ diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c index 42130667a7..598e6adc5e 100644 --- a/hw/rdma/vmw/pvrdma_dev_ring.c +++ b/hw/rdma/vmw/pvrdma_dev_ring.c @@ -41,7 +41,7 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, = PCIDevice *dev, qatomic_set(&ring->ring_state->cons_head, 0); */ ring->npages =3D npages; - ring->pages =3D g_malloc0(npages * sizeof(void *)); + ring->pages =3D g_new0(void *, npages); =20 for (i =3D 0; i < npages; i++) { if (!tbl[i]) { diff --git a/hw/rdma/vmw/pvrdma_qp_ops.c b/hw/rdma/vmw/pvrdma_qp_ops.c index 8050287a6c..bd7cbf2bdf 100644 --- a/hw/rdma/vmw/pvrdma_qp_ops.c +++ b/hw/rdma/vmw/pvrdma_qp_ops.c @@ -154,7 +154,7 @@ void pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle) CompHandlerCtx *comp_ctx; =20 /* Prepare CQE */ - comp_ctx =3D g_malloc(sizeof(CompHandlerCtx)); + comp_ctx =3D g_new(CompHandlerCtx, 1); comp_ctx->dev =3D dev; comp_ctx->cq_handle =3D qp->send_cq_handle; comp_ctx->cqe.wr_id =3D wqe->hdr.wr_id; @@ -217,7 +217,7 @@ void pvrdma_qp_recv(PVRDMADev *dev, uint32_t qp_handle) CompHandlerCtx *comp_ctx; =20 /* Prepare CQE */ - comp_ctx =3D g_malloc(sizeof(CompHandlerCtx)); + comp_ctx =3D g_new(CompHandlerCtx, 1); comp_ctx->dev =3D dev; comp_ctx->cq_handle =3D qp->recv_cq_handle; comp_ctx->cqe.wr_id =3D wqe->hdr.wr_id; @@ -259,7 +259,7 @@ void pvrdma_srq_recv(PVRDMADev *dev, uint32_t srq_handl= e) CompHandlerCtx *comp_ctx; =20 /* Prepare CQE */ - comp_ctx =3D g_malloc(sizeof(CompHandlerCtx)); + comp_ctx =3D g_new(CompHandlerCtx, 1); comp_ctx->dev =3D dev; comp_ctx->cq_handle =3D srq->recv_cq_handle; comp_ctx->cqe.wr_id =3D wqe->hdr.wr_id; diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c index 72759413f3..39fc4f19d9 100644 --- a/hw/sh4/r2d.c +++ b/hw/sh4/r2d.c @@ -190,7 +190,7 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem, { r2d_fpga_t *s; =20 - s =3D g_malloc0(sizeof(r2d_fpga_t)); + s =3D g_new0(r2d_fpga_t, 1); =20 s->irl =3D irl; =20 @@ -248,7 +248,7 @@ static void r2d_init(MachineState *machine) cpu =3D SUPERH_CPU(cpu_create(machine->cpu_type)); env =3D &cpu->env; =20 - reset_info =3D g_malloc0(sizeof(ResetData)); + reset_info =3D g_new0(ResetData, 1); reset_info->cpu =3D cpu; reset_info->vector =3D env->pc; qemu_register_reset(main_cpu_reset, reset_info); diff --git a/hw/sh4/sh7750.c b/hw/sh4/sh7750.c index 43dfb6497b..c77792d150 100644 --- a/hw/sh4/sh7750.c +++ b/hw/sh4/sh7750.c @@ -770,7 +770,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *= sysmem) SysBusDevice *sb; MemoryRegion *mr, *alias; =20 - s =3D g_malloc0(sizeof(SH7750State)); + s =3D g_new0(SH7750State, 1); s->cpu =3D cpu; s->periph_freq =3D 60000000; /* 60MHz */ memory_region_init_io(&s->iomem, NULL, &sh7750_mem_ops, s, diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c index 7b4dec1721..a9f2496827 100644 --- a/hw/sparc/leon3.c +++ b/hw/sparc/leon3.c @@ -241,7 +241,7 @@ static void leon3_generic_hw_init(MachineState *machine) cpu_sparc_set_id(env, 0); =20 /* Reset data */ - reset_info =3D g_malloc0(sizeof(ResetData)); + reset_info =3D g_new0(ResetData, 1); reset_info->cpu =3D cpu; reset_info->sp =3D LEON3_RAM_OFFSET + ram_size; qemu_register_reset(main_cpu_reset, reset_info); diff --git a/hw/sparc64/sparc64.c b/hw/sparc64/sparc64.c index 8654e955eb..72f0849f50 100644 --- a/hw/sparc64/sparc64.c +++ b/hw/sparc64/sparc64.c @@ -81,7 +81,7 @@ static CPUTimer *cpu_timer_create(const char *name, SPARC= CPU *cpu, QEMUBHFunc *cb, uint32_t frequency, uint64_t disabled_mask, uint64_t npt_mas= k) { - CPUTimer *timer =3D g_malloc0(sizeof(CPUTimer)); + CPUTimer *timer =3D g_new0(CPUTimer, 1); =20 timer->name =3D name; timer->frequency =3D frequency; @@ -288,7 +288,7 @@ SPARCCPU *sparc64_cpu_devinit(const char *cpu_type, uin= t64_t prom_addr) hstick_frequency, TICK_INT_DIS, TICK_NPT_MASK); =20 - reset_info =3D g_malloc0(sizeof(ResetData)); + reset_info =3D g_new0(ResetData, 1); reset_info->cpu =3D cpu; reset_info->prom_addr =3D prom_addr; qemu_register_reset(main_cpu_reset, reset_info); diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c index 15caff0e41..84cf2726bb 100644 --- a/hw/timer/arm_timer.c +++ b/hw/timer/arm_timer.c @@ -176,7 +176,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq) { arm_timer_state *s; =20 - s =3D (arm_timer_state *)g_malloc0(sizeof(arm_timer_state)); + s =3D g_new0(arm_timer_state, 1); s->freq =3D freq; s->control =3D TIMER_CTRL_IE; =20 diff --git a/hw/timer/slavio_timer.c b/hw/timer/slavio_timer.c index 03e33fc592..90fdce4c44 100644 --- a/hw/timer/slavio_timer.c +++ b/hw/timer/slavio_timer.c @@ -400,7 +400,7 @@ static void slavio_timer_init(Object *obj) uint64_t size; char timer_name[20]; =20 - tc =3D g_malloc0(sizeof(TimerContext)); + tc =3D g_new0(TimerContext, 1); tc->s =3D s; tc->timer_index =3D i; =20 diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7b45353ce2..436b5cbcb1 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1529,8 +1529,8 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int p= os, Error **errp) int ret; Error *err =3D NULL; =20 - vdev->msix->pending =3D g_malloc0(BITS_TO_LONGS(vdev->msix->entries) * - sizeof(unsigned long)); + vdev->msix->pending =3D g_new0(unsigned long, + BITS_TO_LONGS(vdev->msix->entries)); ret =3D msix_init(&vdev->pdev, vdev->msix->entries, vdev->bars[vdev->msix->table_bar].mr, vdev->msix->table_bar, vdev->msix->table_offset, diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index f8f08a0f36..5af73f9287 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -71,7 +71,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, sysbus_init_irq(sbdev, &intp->qemuirq); =20 /* Get an eventfd for trigger */ - intp->interrupt =3D g_malloc0(sizeof(EventNotifier)); + intp->interrupt =3D g_new0(EventNotifier, 1); ret =3D event_notifier_init(intp->interrupt, 0); if (ret) { g_free(intp->interrupt); @@ -82,7 +82,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, } if (vfio_irq_is_automasked(intp)) { /* Get an eventfd for resample/unmask */ - intp->unmask =3D g_malloc0(sizeof(EventNotifier)); + intp->unmask =3D g_new0(EventNotifier, 1); ret =3D event_notifier_init(intp->unmask, 0); if (ret) { g_free(intp->interrupt); diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 54f9bbb789..dcd80b904d 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -812,7 +812,7 @@ static void virtio_crypto_device_realize(DeviceState *d= ev, Error **errp) =20 virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_s= ize); vcrypto->curr_queues =3D 1; - vcrypto->vqs =3D g_malloc0(sizeof(VirtIOCryptoQueue) * vcrypto->max_qu= eues); + vcrypto->vqs =3D g_new0(VirtIOCryptoQueue, vcrypto->max_queues); for (i =3D 0; i < vcrypto->max_queues; i++) { vcrypto->vqs[i].dataq =3D virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq_b= h); diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 239fe97b12..664cbd9583 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -316,7 +316,7 @@ static AddressSpace *virtio_iommu_find_add_as(PCIBus *b= us, void *opaque, char *name =3D g_strdup_printf("%s-%d-%d", TYPE_VIRTIO_IOMMU_MEMORY_REGION, mr_index++, devfn); - sdev =3D sbus->pbdev[devfn] =3D g_malloc0(sizeof(IOMMUDevice)); + sdev =3D sbus->pbdev[devfn] =3D g_new0(IOMMUDevice, 1); =20 sdev->viommu =3D s; sdev->bus =3D bus; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9e8f51dfb0..32b1859391 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2380,8 +2380,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int q= ueue_size, vdev->vq[i].vring.num_default =3D queue_size; vdev->vq[i].vring.align =3D VIRTIO_PCI_VRING_ALIGN; vdev->vq[i].handle_output =3D handle_output; - vdev->vq[i].used_elems =3D g_malloc0(sizeof(VirtQueueElement) * - queue_size); + vdev->vq[i].used_elems =3D g_new0(VirtQueueElement, queue_size); =20 return &vdev->vq[i]; } @@ -3228,7 +3227,7 @@ void virtio_init(VirtIODevice *vdev, const char *name, qatomic_set(&vdev->isr, 0); vdev->queue_sel =3D 0; vdev->config_vector =3D VIRTIO_NO_VECTOR; - vdev->vq =3D g_malloc0(sizeof(VirtQueue) * VIRTIO_QUEUE_MAX); + vdev->vq =3D g_new0(VirtQueue, VIRTIO_QUEUE_MAX); vdev->vm_running =3D runstate_is_running(); vdev->broken =3D false; for (i =3D 0; i < VIRTIO_QUEUE_MAX; i++) { diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c index 17f087b395..c1e004e882 100644 --- a/hw/xtensa/xtfpga.c +++ b/hw/xtensa/xtfpga.c @@ -126,7 +126,7 @@ static const MemoryRegionOps xtfpga_fpga_ops =3D { static XtfpgaFpgaState *xtfpga_fpga_init(MemoryRegion *address_space, hwaddr base, uint32_t freq) { - XtfpgaFpgaState *s =3D g_malloc(sizeof(XtfpgaFpgaState)); + XtfpgaFpgaState *s =3D g_new(XtfpgaFpgaState, 1); =20 memory_region_init_io(&s->iomem, NULL, &xtfpga_fpga_ops, s, "xtfpga.fpga", 0x10000); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b9b18a7eaf..75ed71eb46 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5076,7 +5076,7 @@ do_ioctl_usbdevfs_submiturb(const IOCTLEntry *ie, uin= t8_t *buf_temp, target_size =3D thunk_type_size(arg_type, THUNK_TARGET); =20 /* construct host copy of urb and metadata */ - lurb =3D g_try_malloc0(sizeof(struct live_urb)); + lurb =3D g_try_new0(struct live_urb, 1); if (!lurb) { return -TARGET_ENOMEM; } diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index d65e744af9..aace12a787 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -91,7 +91,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) { int i; int64_t dirty_rate =3D DirtyStat.dirty_rate; - struct DirtyRateInfo *info =3D g_malloc0(sizeof(DirtyRateInfo)); + struct DirtyRateInfo *info =3D g_new0(DirtyRateInfo, 1); DirtyRateVcpuList *head =3D NULL, **tail =3D &head; =20 info->status =3D CalculatingState; @@ -112,7 +112,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) info->sample_pages =3D 0; info->has_vcpu_dirty_rate =3D true; for (i =3D 0; i < DirtyStat.dirty_ring.nvcpu; i++) { - DirtyRateVcpu *rate =3D g_malloc0(sizeof(DirtyRateVcpu)); + DirtyRateVcpu *rate =3D g_new0(DirtyRateVcpu, 1); rate->id =3D DirtyStat.dirty_ring.rates[i].id; rate->dirty_rate =3D DirtyStat.dirty_ring.rates[i].dirty_r= ate; QAPI_LIST_APPEND(tail, rate); diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index aba1c88a0c..3a7ae44485 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -43,7 +43,7 @@ struct zlib_data { */ static int zlib_send_setup(MultiFDSendParams *p, Error **errp) { - struct zlib_data *z =3D g_malloc0(sizeof(struct zlib_data)); + struct zlib_data *z =3D g_new0(struct zlib_data, 1); z_stream *zs =3D &z->zs; =20 zs->zalloc =3D Z_NULL; @@ -164,7 +164,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) */ static int zlib_recv_setup(MultiFDRecvParams *p, Error **errp) { - struct zlib_data *z =3D g_malloc0(sizeof(struct zlib_data)); + struct zlib_data *z =3D g_new0(struct zlib_data, 1); z_stream *zs =3D &z->zs; =20 p->data =3D z; diff --git a/migration/ram.c b/migration/ram.c index 170e522a1f..3532f64ecb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2059,7 +2059,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr= _t start, ram_addr_t len) } =20 struct RAMSrcPageRequest *new_entry =3D - g_malloc0(sizeof(struct RAMSrcPageRequest)); + g_new0(struct RAMSrcPageRequest, 1); new_entry->rb =3D ramblock; new_entry->offset =3D start; new_entry->len =3D len; diff --git a/monitor/misc.c b/monitor/misc.c index b1839cb8ee..a756dbd6db 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1028,7 +1028,7 @@ void qmp_getfd(const char *fdname, Error **errp) return; } =20 - monfd =3D g_malloc0(sizeof(mon_fd_t)); + monfd =3D g_new0(mon_fd_t, 1); monfd->name =3D g_strdup(fdname); monfd->fd =3D fd; =20 diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index ad82c275c4..0b04855ce8 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -318,7 +318,7 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **err= p) =20 MemoryInfo *qmp_query_memory_size_summary(Error **errp) { - MemoryInfo *mem_info =3D g_malloc0(sizeof(MemoryInfo)); + MemoryInfo *mem_info =3D g_new0(MemoryInfo, 1); MachineState *ms =3D MACHINE(qdev_get_machine()); =20 mem_info->base_memory =3D ms->ram_size; diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4fbbad793f..3c428213db 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -949,7 +949,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) } else if (last_err =3D=3D ERROR_INVALID_FUNCTION) { /* Possibly CD-ROM or a shared drive. Try to pass the volume */ g_debug("volume not on disk"); - disk =3D g_malloc0(sizeof(GuestDiskAddress)); + disk =3D g_new0(GuestDiskAddress, 1); disk->has_dev =3D true; disk->dev =3D g_strdup(name); get_single_disk_info(0xffffffff, disk, &local_err); @@ -972,7 +972,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) =20 /* Go through each extent */ for (i =3D 0; i < extents->NumberOfDiskExtents; i++) { - disk =3D g_malloc0(sizeof(GuestDiskAddress)); + disk =3D g_new0(GuestDiskAddress, 1); =20 /* Disk numbers directly correspond to numbers used in UNCs * @@ -1076,7 +1076,7 @@ GuestDiskInfoList *qmp_guest_get_disks(Error **errp) sdn.DeviceNumber); =20 g_debug(" number: %lu", sdn.DeviceNumber); - address =3D g_malloc0(sizeof(GuestDiskAddress)); + address =3D g_new0(GuestDiskAddress, 1); address->has_dev =3D true; address->dev =3D g_strdup(disk->name); get_single_disk_info(sdn.DeviceNumber, address, &local_err); @@ -1368,7 +1368,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, E= rror **errp) continue; } =20 - uc_path =3D g_malloc(sizeof(WCHAR) * char_count); + uc_path =3D g_new(WCHAR, char_count); if (!GetVolumePathNamesForVolumeNameW(guid, uc_path, char_count, &char_count) || !*uc_path) { /* strange, but this condition could be faced even with size = =3D=3D 2 */ diff --git a/qga/commands.c b/qga/commands.c index 80501e4a73..72e6022207 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -244,7 +244,7 @@ static char **guest_exec_get_args(const strList *entry,= bool log) =20 str =3D g_malloc(str_size); *str =3D 0; - args =3D g_malloc(count * sizeof(char *)); + args =3D g_new(char *, count); for (it =3D entry; it !=3D NULL; it =3D it->next) { args[i++] =3D it->value; pstrcat(str, str_size, it->value); diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 2d6f41ecc7..2e63a4c184 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -49,7 +49,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Er= ror **errp) =20 object_property_iter_init(&iter, obj); while ((prop =3D object_property_iter_next(&iter))) { - ObjectPropertyInfo *value =3D g_malloc0(sizeof(ObjectPropertyInfo)= ); + ObjectPropertyInfo *value =3D g_new0(ObjectPropertyInfo, 1); =20 QAPI_LIST_PREPEND(props, value); =20 diff --git a/replay/replay-char.c b/replay/replay-char.c index dc0002367e..d2025948cf 100644 --- a/replay/replay-char.c +++ b/replay/replay-char.c @@ -50,7 +50,7 @@ void replay_register_char_driver(Chardev *chr) =20 void replay_chr_be_write(Chardev *s, uint8_t *buf, int len) { - CharEvent *event =3D g_malloc0(sizeof(CharEvent)); + CharEvent *event =3D g_new0(CharEvent, 1); =20 event->id =3D find_char_driver(s); if (event->id < 0) { @@ -85,7 +85,7 @@ void replay_event_char_read_save(void *opaque) =20 void *replay_event_char_read_load(void) { - CharEvent *event =3D g_malloc0(sizeof(CharEvent)); + CharEvent *event =3D g_new0(CharEvent, 1); =20 event->id =3D replay_get_byte(); replay_get_array_alloc(&event->buf, &event->len); diff --git a/replay/replay-events.c b/replay/replay-events.c index 15983dd250..ac47c89834 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -119,7 +119,7 @@ void replay_add_event(ReplayAsyncEventKind event_kind, return; } =20 - Event *event =3D g_malloc0(sizeof(Event)); + Event *event =3D g_new0(Event, 1); event->event_kind =3D event_kind; event->opaque =3D opaque; event->opaque2 =3D opaque2; @@ -243,17 +243,17 @@ static Event *replay_read_event(int checkpoint) } break; case REPLAY_ASYNC_EVENT_INPUT: - event =3D g_malloc0(sizeof(Event)); + event =3D g_new0(Event, 1); event->event_kind =3D replay_state.read_event_kind; event->opaque =3D replay_read_input_event(); return event; case REPLAY_ASYNC_EVENT_INPUT_SYNC: - event =3D g_malloc0(sizeof(Event)); + event =3D g_new0(Event, 1); event->event_kind =3D replay_state.read_event_kind; event->opaque =3D 0; return event; case REPLAY_ASYNC_EVENT_CHAR_READ: - event =3D g_malloc0(sizeof(Event)); + event =3D g_new0(Event, 1); event->event_kind =3D replay_state.read_event_kind; event->opaque =3D replay_event_char_read_load(); return event; @@ -263,7 +263,7 @@ static Event *replay_read_event(int checkpoint) } break; case REPLAY_ASYNC_EVENT_NET: - event =3D g_malloc0(sizeof(Event)); + event =3D g_new0(Event, 1); event->event_kind =3D replay_state.read_event_kind; event->opaque =3D replay_event_net_load(); return event; diff --git a/softmmu/bootdevice.c b/softmmu/bootdevice.c index add4e3d2d1..c0713bfa9f 100644 --- a/softmmu/bootdevice.c +++ b/softmmu/bootdevice.c @@ -166,7 +166,7 @@ void add_boot_device_path(int32_t bootindex, DeviceStat= e *dev, =20 del_boot_device_path(dev, suffix); =20 - node =3D g_malloc0(sizeof(FWBootEntry)); + node =3D g_new0(FWBootEntry, 1); node->bootindex =3D bootindex; node->suffix =3D g_strdup(suffix); node->dev =3D dev; @@ -367,7 +367,7 @@ void add_boot_device_lchs(DeviceState *dev, const char = *suffix, =20 assert(dev !=3D NULL || suffix !=3D NULL); =20 - node =3D g_malloc0(sizeof(FWLCHSEntry)); + node =3D g_new0(FWLCHSEntry, 1); node->suffix =3D g_strdup(suffix); node->dev =3D dev; node->lcyls =3D lcyls; diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index 160095e4ba..7820fec54c 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -29,7 +29,7 @@ MemTxResult dma_memory_set(AddressSpace *as, dma_addr_t a= ddr, void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint, AddressSpace *as) { - qsg->sg =3D g_malloc(alloc_hint * sizeof(ScatterGatherEntry)); + qsg->sg =3D g_new(ScatterGatherEntry, alloc_hint); qsg->nsg =3D 0; qsg->nalloc =3D alloc_hint; qsg->size =3D 0; @@ -42,7 +42,7 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dm= a_addr_t len) { if (qsg->nsg =3D=3D qsg->nalloc) { qsg->nalloc =3D 2 * qsg->nalloc + 1; - qsg->sg =3D g_realloc(qsg->sg, qsg->nalloc * sizeof(ScatterGatherE= ntry)); + qsg->sg =3D g_renew(ScatterGatherEntry, qsg->sg, qsg->nalloc); } qsg->sg[qsg->nsg].base =3D base; qsg->sg[qsg->nsg].len =3D len; diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c index 8320165ea2..f6f0a829fd 100644 --- a/softmmu/memory_mapping.c +++ b/softmmu/memory_mapping.c @@ -42,7 +42,7 @@ static void create_new_memory_mapping(MemoryMappingList *= list, { MemoryMapping *memory_mapping; =20 - memory_mapping =3D g_malloc(sizeof(MemoryMapping)); + memory_mapping =3D g_new(MemoryMapping, 1); memory_mapping->phys_addr =3D phys_addr; memory_mapping->virt_addr =3D virt_addr; memory_mapping->length =3D length; diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c index 37b7c562f5..e254d8ba10 100644 --- a/target/i386/cpu-sysemu.c +++ b/target/i386/cpu-sysemu.c @@ -313,7 +313,7 @@ GuestPanicInformation *x86_cpu_get_crash_info(CPUState = *cs) GuestPanicInformation *panic_info =3D NULL; =20 if (hyperv_feat_enabled(cpu, HYPERV_FEAT_CRASH)) { - panic_info =3D g_malloc0(sizeof(GuestPanicInformation)); + panic_info =3D g_new0(GuestPanicInformation, 1); =20 panic_info->type =3D GUEST_PANIC_INFORMATION_TYPE_HYPER_V; =20 diff --git a/target/i386/hax/hax-accel-ops.c b/target/i386/hax/hax-accel-op= s.c index 136630e9b2..18114fe34d 100644 --- a/target/i386/hax/hax-accel-ops.c +++ b/target/i386/hax/hax-accel-ops.c @@ -61,8 +61,8 @@ static void hax_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 - cpu->thread =3D g_malloc0(sizeof(QemuThread)); - cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); + cpu->thread =3D g_new0(QemuThread, 1); + cpu->halt_cond =3D g_new0(QemuCond, 1); qemu_cond_init(cpu->halt_cond); =20 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX", diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-acce= l-ops.c index f788f75289..6c46101ac1 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -64,8 +64,8 @@ static void nvmm_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 - cpu->thread =3D g_malloc0(sizeof(QemuThread)); - cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); + cpu->thread =3D g_new0(QemuThread, 1); + cpu->halt_cond =3D g_new0(QemuCond, 1); qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/NVMM", cpu->cpu_index); diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-acce= l-ops.c index 1d30e4e2ed..dd2a9f7657 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -64,8 +64,8 @@ static void whpx_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 - cpu->thread =3D g_malloc0(sizeof(QemuThread)); - cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); + cpu->thread =3D g_new0(QemuThread, 1); + cpu->halt_cond =3D g_new0(QemuCond, 1); qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", cpu->cpu_index); diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index c7e25abf42..9fd287e5d4 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1354,7 +1354,7 @@ int whpx_init_vcpu(CPUState *cpu) } } =20 - vcpu =3D g_malloc0(sizeof(struct whpx_vcpu)); + vcpu =3D g_new0(struct whpx_vcpu, 1); =20 if (!vcpu) { error_report("WHPX: Failed to allocte VCPU context."); diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 5471e01ee8..948e4bd3e0 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -76,7 +76,7 @@ static GuestPanicInformation *s390_cpu_get_crash_info(CPU= State *cs) S390CPU *cpu =3D S390_CPU(cs); =20 cpu_synchronize_state(cs); - panic_info =3D g_malloc0(sizeof(GuestPanicInformation)); + panic_info =3D g_new0(GuestPanicInformation, 1); =20 panic_info->type =3D GUEST_PANIC_INFORMATION_TYPE_S390; panic_info->u.s390.core =3D cpu->env.core_id; diff --git a/tests/unit/test-hbitmap.c b/tests/unit/test-hbitmap.c index b6726cf76b..a4fe067917 100644 --- a/tests/unit/test-hbitmap.c +++ b/tests/unit/test-hbitmap.c @@ -113,7 +113,7 @@ static void hbitmap_test_truncate_impl(TestHBitmapData = *data, =20 n =3D hbitmap_test_array_size(size); m =3D hbitmap_test_array_size(data->old_size); - data->bits =3D g_realloc(data->bits, sizeof(unsigned long) * n); + data->bits =3D g_renew(unsigned long, data->bits, n); if (n > m) { memset(&data->bits[m], 0x00, sizeof(unsigned long) * (n - m)); } diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c index faa858624a..6085c09995 100644 --- a/tests/unit/test-qmp-cmds.c +++ b/tests/unit/test-qmp-cmds.c @@ -82,8 +82,8 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, Error **errp) { UserDefTwo *ret; - UserDefOne *ud1c =3D g_malloc0(sizeof(UserDefOne)); - UserDefOne *ud1d =3D g_malloc0(sizeof(UserDefOne)); + UserDefOne *ud1c =3D g_new0(UserDefOne, 1); + UserDefOne *ud1d =3D g_new0(UserDefOne, 1); =20 ud1c->string =3D strdup(ud1a->string); ud1c->integer =3D ud1a->integer; @@ -344,23 +344,23 @@ static void test_dealloc_types(void) UserDefOne *ud1test, *ud1a, *ud1b; UserDefOneList *ud1list; =20 - ud1test =3D g_malloc0(sizeof(UserDefOne)); + ud1test =3D g_new0(UserDefOne, 1); ud1test->integer =3D 42; ud1test->string =3D g_strdup("hi there 42"); =20 qapi_free_UserDefOne(ud1test); =20 - ud1a =3D g_malloc0(sizeof(UserDefOne)); + ud1a =3D g_new0(UserDefOne, 1); ud1a->integer =3D 43; ud1a->string =3D g_strdup("hi there 43"); =20 - ud1b =3D g_malloc0(sizeof(UserDefOne)); + ud1b =3D g_new0(UserDefOne, 1); ud1b->integer =3D 44; ud1b->string =3D g_strdup("hi there 44"); =20 - ud1list =3D g_malloc0(sizeof(UserDefOneList)); + ud1list =3D g_new0(UserDefOneList, 1); ud1list->value =3D ud1a; - ud1list->next =3D g_malloc0(sizeof(UserDefOneList)); + ud1list->next =3D g_new0(UserDefOneList, 1); ud1list->next->value =3D ud1b; =20 qapi_free_UserDefOneList(ud1list); diff --git a/tests/unit/test-qobject-output-visitor.c b/tests/unit/test-qob= ject-output-visitor.c index 34d67a439a..6af4c33eec 100644 --- a/tests/unit/test-qobject-output-visitor.c +++ b/tests/unit/test-qobject-output-visitor.c @@ -338,7 +338,7 @@ static void test_visitor_out_union_flat(TestOutputVisit= orData *data, { QDict *qdict; =20 - UserDefFlatUnion *tmp =3D g_malloc0(sizeof(UserDefFlatUnion)); + UserDefFlatUnion *tmp =3D g_new0(UserDefFlatUnion, 1); tmp->enum1 =3D ENUM_ONE_VALUE1; tmp->string =3D g_strdup("str"); tmp->integer =3D 41; diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index 4688c03ea7..6a417bb102 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -1002,22 +1002,22 @@ static TestGTreeDomain *create_first_domain(void) TestGTreeMapping *map_a, *map_b; TestGTreeInterval *a, *b; =20 - domain =3D g_malloc0(sizeof(TestGTreeDomain)); + domain =3D g_new0(TestGTreeDomain, 1); domain->id =3D 6; =20 - a =3D g_malloc0(sizeof(TestGTreeInterval)); + a =3D g_new0(TestGTreeInterval, 1); a->low =3D 0x1000; a->high =3D 0x1FFF; =20 - b =3D g_malloc0(sizeof(TestGTreeInterval)); + b =3D g_new0(TestGTreeInterval, 1); b->low =3D 0x4000; b->high =3D 0x4FFF; =20 - map_a =3D g_malloc0(sizeof(TestGTreeMapping)); + map_a =3D g_new0(TestGTreeMapping, 1); map_a->phys_addr =3D 0xa000; map_a->flags =3D 1; =20 - map_b =3D g_malloc0(sizeof(TestGTreeMapping)); + map_b =3D g_new0(TestGTreeMapping, 1); map_b->phys_addr =3D 0xe0000; map_b->flags =3D 2; =20 @@ -1120,7 +1120,7 @@ static void diff_iommu(TestGTreeIOMMU *iommu1, TestGT= reeIOMMU *iommu2) =20 static void test_gtree_load_domain(void) { - TestGTreeDomain *dest_domain =3D g_malloc0(sizeof(TestGTreeDomain)); + TestGTreeDomain *dest_domain =3D g_new0(TestGTreeDomain, 1); TestGTreeDomain *orig_domain =3D create_first_domain(); QEMUFile *fload, *fsave; char eof; @@ -1185,7 +1185,7 @@ uint8_t iommu_dump[] =3D { =20 static TestGTreeIOMMU *create_iommu(void) { - TestGTreeIOMMU *iommu =3D g_malloc0(sizeof(TestGTreeIOMMU)); + TestGTreeIOMMU *iommu =3D g_new0(TestGTreeIOMMU, 1); TestGTreeDomain *first_domain =3D create_first_domain(); TestGTreeDomain *second_domain; TestGTreeMapping *map_c; @@ -1196,7 +1196,7 @@ static TestGTreeIOMMU *create_iommu(void) NULL, destroy_domain); =20 - second_domain =3D g_malloc0(sizeof(TestGTreeDomain)); + second_domain =3D g_new0(TestGTreeDomain, 1); second_domain->id =3D 5; second_domain->mappings =3D g_tree_new_full((GCompareDataFunc)interval= _cmp, NULL, @@ -1206,11 +1206,11 @@ static TestGTreeIOMMU *create_iommu(void) g_tree_insert(iommu->domains, GUINT_TO_POINTER(6), first_domain); g_tree_insert(iommu->domains, (gpointer)0x0000000000000005, second_dom= ain); =20 - c =3D g_malloc0(sizeof(TestGTreeInterval)); + c =3D g_new0(TestGTreeInterval, 1); c->low =3D 0x1000000; c->high =3D 0x1FFFFFF; =20 - map_c =3D g_malloc0(sizeof(TestGTreeMapping)); + map_c =3D g_new0(TestGTreeMapping, 1); map_c->phys_addr =3D 0xF000000; map_c->flags =3D 0x3; =20 @@ -1235,7 +1235,7 @@ static void test_gtree_save_iommu(void) =20 static void test_gtree_load_iommu(void) { - TestGTreeIOMMU *dest_iommu =3D g_malloc0(sizeof(TestGTreeIOMMU)); + TestGTreeIOMMU *dest_iommu =3D g_new0(TestGTreeIOMMU, 1); TestGTreeIOMMU *orig_iommu =3D create_iommu(); QEMUFile *fsave, *fload; char eof; @@ -1274,11 +1274,11 @@ static uint8_t qlist_dump[] =3D { =20 static TestQListContainer *alloc_container(void) { - TestQListElement *a =3D g_malloc(sizeof(TestQListElement)); - TestQListElement *b =3D g_malloc(sizeof(TestQListElement)); - TestQListElement *c =3D g_malloc(sizeof(TestQListElement)); - TestQListElement *d =3D g_malloc(sizeof(TestQListElement)); - TestQListContainer *container =3D g_malloc(sizeof(TestQListContainer)); + TestQListElement *a =3D g_new(TestQListElement, 1); + TestQListElement *b =3D g_new(TestQListElement, 1); + TestQListElement *c =3D g_new(TestQListElement, 1); + TestQListElement *d =3D g_new(TestQListElement, 1); + TestQListContainer *container =3D g_new(TestQListContainer, 1); =20 a->id =3D 0x0a; b->id =3D 0x0b00; @@ -1332,11 +1332,11 @@ static void manipulate_container(TestQListContainer= *c) TestQListElement *prev =3D NULL, *iter =3D QLIST_FIRST(&c->list); TestQListElement *elem; =20 - elem =3D g_malloc(sizeof(TestQListElement)); + elem =3D g_new(TestQListElement, 1); elem->id =3D 0x12; QLIST_INSERT_AFTER(iter, elem, next); =20 - elem =3D g_malloc(sizeof(TestQListElement)); + elem =3D g_new(TestQListElement, 1); elem->id =3D 0x13; QLIST_INSERT_HEAD(&c->list, elem, next); =20 @@ -1345,11 +1345,11 @@ static void manipulate_container(TestQListContainer= *c) iter =3D QLIST_NEXT(iter, next); } =20 - elem =3D g_malloc(sizeof(TestQListElement)); + elem =3D g_new(TestQListElement, 1); elem->id =3D 0x14; QLIST_INSERT_BEFORE(prev, elem, next); =20 - elem =3D g_malloc(sizeof(TestQListElement)); + elem =3D g_new(TestQListElement, 1); elem->id =3D 0x15; QLIST_INSERT_AFTER(prev, elem, next); =20 @@ -1370,7 +1370,7 @@ static void test_load_qlist(void) { QEMUFile *fsave, *fload; TestQListContainer *orig_container =3D alloc_container(); - TestQListContainer *dest_container =3D g_malloc0(sizeof(TestQListConta= iner)); + TestQListContainer *dest_container =3D g_new0(TestQListContainer, 1); char eof; =20 QLIST_INIT(&dest_container->list); diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index cebd35841a..7b86a4713d 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -1477,7 +1477,7 @@ static int send_sub_rect(VncState *vs, int x, int y, = int w, int h) #endif =20 if (!color_count_palette) { - color_count_palette =3D g_malloc(sizeof(VncPalette)); + color_count_palette =3D g_new(VncPalette, 1); vnc_tight_cleanup_notifier.notify =3D vnc_tight_cleanup; qemu_thread_atexit_add(&vnc_tight_cleanup_notifier); } diff --git a/util/envlist.c b/util/envlist.c index 2bcc13f094..ab5553498a 100644 --- a/util/envlist.c +++ b/util/envlist.c @@ -217,7 +217,7 @@ envlist_to_environ(const envlist_t *envlist, size_t *co= unt) struct envlist_entry *entry; char **env, **penv; =20 - penv =3D env =3D g_malloc((envlist->el_count + 1) * sizeof(char *)); + penv =3D env =3D g_new(char *, envlist->el_count + 1); =20 for (entry =3D envlist->el_entries.lh_first; entry !=3D NULL; entry =3D entry->ev_link.le_next) { diff --git a/util/hbitmap.c b/util/hbitmap.c index dd0501d9a7..ea989e1f0e 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -862,7 +862,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size) } old =3D hb->sizes[i]; hb->sizes[i] =3D size; - hb->levels[i] =3D g_realloc(hb->levels[i], size * sizeof(unsigned = long)); + hb->levels[i] =3D g_renew(unsigned long, hb->levels[i], size); if (!shrink) { memset(&hb->levels[i][old], 0x00, (size - old) * sizeof(*hb->levels[i])); diff --git a/util/main-loop.c b/util/main-loop.c index 4d5a5b9943..b7b0ce4ca0 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -273,7 +273,7 @@ static PollingEntry *first_polling_entry; int qemu_add_polling_cb(PollingFunc *func, void *opaque) { PollingEntry **ppe, *pe; - pe =3D g_malloc0(sizeof(PollingEntry)); + pe =3D g_new0(PollingEntry, 1); pe->func =3D func; pe->opaque =3D opaque; for(ppe =3D &first_polling_entry; *ppe !=3D NULL; ppe =3D &(*ppe)->nex= t); diff --git a/util/qemu-timer.c b/util/qemu-timer.c index f36c75e594..a670a57881 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -100,7 +100,7 @@ QEMUTimerList *timerlist_new(QEMUClockType type, QEMUTimerList *timer_list; QEMUClock *clock =3D qemu_clock_ptr(type); =20 - timer_list =3D g_malloc0(sizeof(QEMUTimerList)); + timer_list =3D g_new0(QEMUTimerList, 1); qemu_event_init(&timer_list->timers_done_ev, true); timer_list->clock =3D clock; timer_list->notify_cb =3D cb; diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 00a80431a0..b037d5faa5 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -279,8 +279,8 @@ static void collect_usable_iova_ranges(QEMUVFIOState *s= , void *buf) s->nb_iova_ranges =3D cap_iova_range->nr_iovas; if (s->nb_iova_ranges > 1) { s->usable_iova_ranges =3D - g_realloc(s->usable_iova_ranges, - s->nb_iova_ranges * sizeof(struct IOVARange)); + g_renew(struct IOVARange, s->usable_iova_ranges, + s->nb_iova_ranges); } =20 for (i =3D 0; i < s->nb_iova_ranges; i++) { --=20 2.35.1