[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [patch v5 05/12] vfio: refine function vfio_pci_host_match
From: |
Cao jin |
Subject: |
[Qemu-devel] [patch v5 05/12] vfio: refine function vfio_pci_host_match |
Date: |
Wed, 23 Mar 2016 18:12:00 +0800 |
From: Chen Fan <address@hidden>
Signed-off-by: Chen Fan <address@hidden>
---
hw/vfio/pci.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 0516d94..5b23a86 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2060,14 +2060,27 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev)
vfio_intx_enable(vdev);
}
+static int vfio_pci_name_to_addr(const char *name, PCIHostDeviceAddress *addr)
+{
+ if (strlen(name) != 12 ||
+ sscanf(name, "%04x:%02x:%02x.%1x", &addr->domain,
+ &addr->bus, &addr->slot, &addr->function) != 4) {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name)
{
- char tmp[13];
+ PCIHostDeviceAddress tmp;
- sprintf(tmp, "%04x:%02x:%02x.%1x", addr->domain,
- addr->bus, addr->slot, addr->function);
+ if (vfio_pci_name_to_addr(name, &tmp)) {
+ return false;
+ }
- return (strcmp(tmp, name) == 0);
+ return (tmp.domain == addr->domain && tmp.bus == addr->bus &&
+ tmp.slot == addr->slot && tmp.function == addr->function);
}
static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
--
1.9.3
- [Qemu-devel] [patch v5 01/12] vfio: extract vfio_get_hot_reset_info as a single function, (continued)
- [Qemu-devel] [patch v5 01/12] vfio: extract vfio_get_hot_reset_info as a single function, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 02/12] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 04/12] vfio: add aer support for vfio device, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 07/12] pci: add a pci_function_is_valid callback to check function if valid, Cao jin, 2016/03/23
- Re: [Qemu-devel] [patch v5 07/12] pci: add a pci_function_is_valid callback to check function if valid, Michael S. Tsirkin, 2016/03/27
- [Qemu-devel] [patch v5 03/12] vfio: add pcie extended capability support, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 06/12] vfio: add check host bus reset is support or not, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 05/12] vfio: refine function vfio_pci_host_match,
Cao jin <=
- [Qemu-devel] [patch v5 08/12] vfio: add check aer functionality for hotplug device, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 10/12] vfio-pci: pass the aer error to guest, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 09/12] vfio: vote the function 0 to do host bus reset when aer occurred, Cao jin, 2016/03/23
- [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Cao jin, 2016/03/23
- Re: [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Alex Williamson, 2016/03/24
- Re: [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Chen Fan, 2016/03/24
- Re: [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Alex Williamson, 2016/03/24
- Re: [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Chen Fan, 2016/03/31
- Re: [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Alex Williamson, 2016/03/31
- Re: [Qemu-devel] [patch v5 11/12] vfio: device may stuck in D3 when doing aer recovery, Chen Fan, 2016/03/31