From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPPdf-0007fp-8S for qemu-devel@nongnu.org; Tue, 19 Jul 2016 03:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPPdd-0008EG-Me for qemu-devel@nongnu.org; Tue, 19 Jul 2016 03:40:23 -0400 Received: from [59.151.112.132] (port=49608 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPPdc-0008DR-3d for qemu-devel@nongnu.org; Tue, 19 Jul 2016 03:40:21 -0400 From: Zhou Jie Date: Tue, 19 Jul 2016 15:38:22 +0800 Message-ID: <1468913909-21811-5-git-send-email-zhoujie2011@cn.fujitsu.com> In-Reply-To: <1468913909-21811-1-git-send-email-zhoujie2011@cn.fujitsu.com> References: <1468913909-21811-1-git-send-email-zhoujie2011@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v9 04/11] vfio: refine function vfio_pci_host_match List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: alex.williamson@redhat.com Cc: qemu-devel@nongnu.org, izumi.taku@jp.fujitsu.com, mst@redhat.com, fan.chen@easystack.cn, Chen Fan From: Chen Fan Signed-off-by: Chen Fan --- 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 11c895c..21fd801 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.8.3.1