From patchwork Wed Feb 24 08:22:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neo Jia X-Patchwork-Id: 8402691 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6FC6AC0554 for ; Wed, 24 Feb 2016 08:22:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 842C02035E for ; Wed, 24 Feb 2016 08:22:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E7A4A2035D for ; Wed, 24 Feb 2016 08:22:45 +0000 (UTC) Received: from localhost ([::1]:34253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYUib-0008Mg-9Q for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Feb 2016 03:22:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYUiO-0008Jm-A7 for qemu-devel@nongnu.org; Wed, 24 Feb 2016 03:22:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYUiL-00060Z-1w for qemu-devel@nongnu.org; Wed, 24 Feb 2016 03:22:32 -0500 Received: from hqemgate15.nvidia.com ([216.228.121.64]:17982) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYUiK-00060U-QO for qemu-devel@nongnu.org; Wed, 24 Feb 2016 03:22:28 -0500 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Wed, 24 Feb 2016 00:22:13 -0800 Received: from hqemhub02.nvidia.com ([172.20.150.31]) by hqnvupgp07.nvidia.com (PGP Universal service); Wed, 24 Feb 2016 00:21:23 -0800 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 24 Feb 2016 00:21:23 -0800 Received: from cjia-vgx-kvm.nvidia.com (172.20.144.16) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server id 8.3.406.0; Wed, 24 Feb 2016 00:22:26 -0800 From: Neo Jia To: qemu-devel@nongnu.org, alex.williamson@redhat.com Date: Wed, 24 Feb 2016 00:22:02 -0800 Message-ID: <1456302122-11917-1-git-send-email-cjia@nvidia.com> X-Mailer: git-send-email 1.8.3.1 X-NVConfidentiality: public MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 216.228.121.64 Cc: kwankhede@nvidia.com, cjia@nvidia.com Subject: [Qemu-devel] [PATCH] replace fixed str limit by g_strdup_printf X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A trivial change to remove string limit by using g_strdup_printf and g_strconcat Tested-by: Neo Jia Signed-off-by: Neo Jia Signed-off-by: Kirti Wankhede --- hw/vfio/pci.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index bfe421528618..795e035a6a9b 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -874,7 +874,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK); off_t offset = vdev->config_offset + PCI_ROM_ADDRESS; DeviceState *dev = DEVICE(vdev); - char name[32]; + char *name; int fd = vdev->vbasedev.fd; if (vdev->pdev.romfile || !vdev->pdev.rom_bar) { @@ -917,16 +917,18 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) trace_vfio_pci_size_rom(vdev->vbasedev.name, size); - snprintf(name, sizeof(name), "vfio[%s].rom", vdev->vbasedev.name); + name = g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name); memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev), &vfio_rom_ops, vdev, name, size); + g_free(name); pci_register_bar(&vdev->pdev, PCI_ROM_SLOT, PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom); vdev->pdev.has_rom = true; vdev->rom_read_failed = false; + } void vfio_vga_write(void *opaque, hwaddr addr, @@ -1318,7 +1320,7 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) { VFIOBAR *bar = &vdev->bars[nr]; uint64_t size = bar->region.size; - char name[64]; + char *name; uint32_t pci_bar; uint8_t type; int ret; @@ -1328,8 +1330,6 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) return; } - snprintf(name, sizeof(name), "VFIO %s BAR %d", vdev->vbasedev.name, nr); - /* Determine what type of BAR this is for registration */ ret = pread(vdev->vbasedev.fd, &pci_bar, sizeof(pci_bar), vdev->config_offset + PCI_BASE_ADDRESS_0 + (4 * nr)); @@ -1338,6 +1338,8 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) return; } + name = g_strdup_printf("VFIO %s BAR %d", vdev->vbasedev.name, nr); + pci_bar = le32_to_cpu(pci_bar); bar->ioport = (pci_bar & PCI_BASE_ADDRESS_SPACE_IO); bar->mem64 = bar->ioport ? 0 : (pci_bar & PCI_BASE_ADDRESS_MEM_TYPE_64); @@ -1357,7 +1359,8 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) size = vdev->msix->table_offset & qemu_real_host_page_mask; } - strncat(name, " mmap", sizeof(name) - strlen(name) - 1); + name = g_strconcat(name, " mmap", NULL); + if (vfio_mmap_region(OBJECT(vdev), &bar->region, &bar->region.mem, &bar->region.mmap_mem, &bar->region.mmap, size, 0, name)) { @@ -1372,7 +1375,8 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) PCI_MSIX_ENTRY_SIZE)); size = start < bar->region.size ? bar->region.size - start : 0; - strncat(name, " msix-hi", sizeof(name) - strlen(name) - 1); + name = g_strconcat(name, " msix-hi", NULL); + /* VFIOMSIXInfo contains another MemoryRegion for this mapping */ if (vfio_mmap_region(OBJECT(vdev), &bar->region, &bar->region.mem, &vdev->msix->mmap_mem, @@ -1382,6 +1386,7 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) } vfio_bar_quirk_setup(vdev, nr); + g_free(name); } static void vfio_map_bars(VFIOPCIDevice *vdev)