On Wed, 24 Feb 2016 00:22:02 -0800 Neo Jia <c...@nvidia.com> wrote: > A trivial change to remove string limit by using g_strdup_printf > and g_strconcat > > Tested-by: Neo Jia <c...@nvidia.com> > Signed-off-by: Neo Jia <c...@nvidia.com> > Signed-off-by: Kirti Wankhede <kwankh...@nvidia.com> > --- > 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; > +
Stray extra whitespace > } > > 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; If you include my latest patch series[1], I think you'll find that the limit here no longer exists. Thanks, Alex [1] http://lists.gnu.org/archive/html/qemu-devel/2016-02/msg05089.html > 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)