From nobody Tue Nov 4 07:04:15 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 150496997469149.77146514994229; Sat, 9 Sep 2017 08:12:54 -0700 (PDT) Received: from localhost ([::1]:49904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqhRE-0004BW-Dx for importer@patchew.org; Sat, 09 Sep 2017 11:12:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqhL1-0007ps-Lw for qemu-devel@nongnu.org; Sat, 09 Sep 2017 11:06:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqhKw-00069q-Of for qemu-devel@nongnu.org; Sat, 09 Sep 2017 11:06:27 -0400 Received: from 6.mo177.mail-out.ovh.net ([46.105.51.249]:53098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dqhKw-000687-3Z for qemu-devel@nongnu.org; Sat, 09 Sep 2017 11:06:22 -0400 Received: from player714.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo177.mail-out.ovh.net (Postfix) with ESMTP id CDAE871BB4 for ; Sat, 9 Sep 2017 17:06:20 +0200 (CEST) Received: from [192.168.0.243] (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player714.ha.ovh.net (Postfix) with ESMTPA id 955683C0073; Sat, 9 Sep 2017 17:06:18 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Sat, 09 Sep 2017 17:06:18 +0200 Message-ID: <150496957801.9654.17692506571556698840.stgit@bahia> In-Reply-To: <150496954641.9654.1998704077006846521.stgit@bahia> References: <150496954641.9654.1998704077006846521.stgit@bahia> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 246572081182185811 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrfeeigdekjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.51.249 Subject: [Qemu-devel] [PATCH 3/5] spapr_pci: use g_strdup_printf() 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, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Building strings with g_strdup_printf() instead of snprintf() is a QEMU common practice. Signed-off-by: Greg Kurz --- hw/ppc/spapr_pci.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index cd8efb181223..6da73fe6bc29 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -61,8 +61,6 @@ #define RTAS_TYPE_MSI 1 #define RTAS_TYPE_MSIX 2 =20 -#define FDT_NAME_MAX 128 - #define _FDT(exp) \ do { \ int ret =3D (exp); \ @@ -1194,7 +1192,7 @@ static const char *pci_find_device_name(uint8_t class= , uint8_t subclass, return name; } =20 -static void pci_get_node_name(char *nodename, int len, PCIDevice *dev) +static gchar *pci_get_node_name(PCIDevice *dev) { int slot =3D PCI_SLOT(dev->devfn); int func =3D PCI_FUNC(dev->devfn); @@ -1205,9 +1203,9 @@ static void pci_get_node_name(char *nodename, int len= , PCIDevice *dev) ccode & 0xff); =20 if (func !=3D 0) { - snprintf(nodename, len, "%s@%x,%x", name, slot, func); + return g_strdup_printf("%s@%x,%x", name, slot, func); } else { - snprintf(nodename, len, "%s@%x", name, slot); + return g_strdup_printf("%s@%x", name, slot); } } =20 @@ -1325,10 +1323,12 @@ static int spapr_create_pci_child_dt(sPAPRPHBState = *phb, PCIDevice *dev, void *fdt, int node_offset) { int offset, ret; - char nodename[FDT_NAME_MAX]; + gchar *nodename; =20 - pci_get_node_name(nodename, FDT_NAME_MAX, dev); + nodename =3D pci_get_node_name(dev); offset =3D fdt_add_subnode(fdt, node_offset, nodename); + g_free(nodename); + ret =3D spapr_populate_pci_child_dt(dev, fdt, offset, phb); =20 g_assert(!ret); @@ -2072,7 +2072,7 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, void *fdt) { int bus_off, i, j, ret; - char nodename[FDT_NAME_MAX]; + gchar *nodename; uint32_t bus_range[] =3D { cpu_to_be32(0), cpu_to_be32(0xff) }; struct { uint32_t hi; @@ -2121,8 +2121,9 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, sPAPRFDT s_fdt; =20 /* Start populating the FDT */ - snprintf(nodename, FDT_NAME_MAX, "pci@%" PRIx64, phb->buid); + nodename =3D g_strdup_printf("pci@%" PRIx64, phb->buid); bus_off =3D fdt_add_subnode(fdt, 0, nodename); + g_free(nodename); if (bus_off < 0) { return bus_off; }