From: Neo Jia <cjia@nvidia.com>
To: qemu-devel@nongnu.org, alex.williamson@redhat.com
Cc: kwankhede@nvidia.com, cjia@nvidia.com
Subject: [Qemu-devel] [PATCH] replace fixed str limit by g_strdup_printf
Date: Wed, 24 Feb 2016 00:22:02 -0800 [thread overview]
Message-ID: <1456302122-11917-1-git-send-email-cjia@nvidia.com> (raw)
A trivial change to remove string limit by using g_strdup_printf
and g_strconcat
Tested-by: Neo Jia <cjia@nvidia.com>
Signed-off-by: Neo Jia <cjia@nvidia.com>
Signed-off-by: Kirti Wankhede <kwankhede@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;
+
}
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)
--
1.8.3.1
next reply other threads:[~2016-02-24 8:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 8:22 Neo Jia [this message]
2016-02-24 19:31 ` [Qemu-devel] [PATCH] replace fixed str limit by g_strdup_printf Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456302122-11917-1-git-send-email-cjia@nvidia.com \
--to=cjia@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=kwankhede@nvidia.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).