From 9c91ed23603b758fac0f6146cf54b80df7f0c6f7 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Fri, 26 Apr 2024 19:36:43 +0800 Subject: [PATCH] pci/pci_ivshmem: fix bug in remove and add vmid check 1. Should check the vmid in ivshmem_remove() when release irq instead check the ivdev->reg; 2. Add vmid check in ivshmem_probe() because ivshmem driver only support vmid == 0 or 1 for now in NuttX; Signed-off-by: Bowen Wang --- drivers/pci/pci_ivshmem.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci_ivshmem.c b/drivers/pci/pci_ivshmem.c index 151d2b64b6..e3bd75c279 100644 --- a/drivers/pci/pci_ivshmem.c +++ b/drivers/pci/pci_ivshmem.c @@ -247,6 +247,13 @@ static int ivshmem_probe(FAR struct pci_device_s *dev) (FAR char *)ivdev->reg + IVSHMEM_REG_IVPOSITION, &ivdev->vmid); + if (ivdev->vmid != 0 && ivdev->vmid != 1) + { + ret = -EINVAL; + pcierr("Vmid must be 0 or 1\n"); + goto err_master; + } + ret = pci_alloc_irq(dev, &ivdev->irq, 1); if (ret != 1) { @@ -296,7 +303,7 @@ static void ivshmem_remove(FAR struct pci_device_s *dev) FAR struct ivshmem_device_s *ivdev = dev->priv; ivshmem_unregister_device(ivdev); - if (ivdev->reg != NULL) + if (ivdev->vmid != IVSHMEM_INVALID_VMID) { pci_release_irq(dev, &ivdev->irq, 1); }