From nobody Thu Nov 6 06:29:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153933524840610.063776804543977; Fri, 12 Oct 2018 02:07:28 -0700 (PDT) Received: from localhost ([::1]:39137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAtPr-0000xd-37 for importer@patchew.org; Fri, 12 Oct 2018 05:07:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAtO9-0008Vf-WE for qemu-devel@nongnu.org; Fri, 12 Oct 2018 05:05:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAtO4-0006SD-6m for qemu-devel@nongnu.org; Fri, 12 Oct 2018 05:05:41 -0400 Received: from 2.mo6.mail-out.ovh.net ([46.105.76.65]:53478) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gAtO2-0006L1-Vb for qemu-devel@nongnu.org; Fri, 12 Oct 2018 05:05:36 -0400 Received: from player691.ha.ovh.net (unknown [10.109.143.145]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id EF9541899E3 for ; Fri, 12 Oct 2018 11:05:14 +0200 (CEST) Received: from kaod.org (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player691.ha.ovh.net (Postfix) with ESMTPSA id 393DC2600A5; Fri, 12 Oct 2018 11:05:09 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 12 Oct 2018 11:05:09 +0200 Message-ID: <153933510947.3834759.3504000962964977142.stgit@bahia.lan> In-Reply-To: <153933509870.3834759.13291133122604475240.stgit@bahia.lan> References: <153933509870.3834759.13291133122604475240.stgit@bahia.lan> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 7190559757505894852 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrvddtgdduvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.76.65 Subject: [Qemu-devel] [PATCH v2 1/2] spapr_pci: convert g_malloc() to g_new() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When allocating an array, it is a recommended coding practice to call g_new(FooType, n) instead of g_malloc(n * sizeof(FooType)) because it takes care to avoid overflow when calculating the size of the allocated block and it returns FooType *, which allows the compiler to perform type checking. Signed-off-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/ppc/spapr_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index c2271e6ed462..0537ce018f51 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1883,7 +1883,7 @@ static int spapr_pci_pre_save(void *opaque) if (!sphb->msi_devs_num) { return 0; } - sphb->msi_devs =3D g_malloc(sphb->msi_devs_num * sizeof(spapr_pci_msi_= mig)); + sphb->msi_devs =3D g_new(spapr_pci_msi_mig, sphb->msi_devs_num); =20 g_hash_table_iter_init(&iter, sphb->msi); for (i =3D 0; g_hash_table_iter_next(&iter, &key, &value); ++i) {