You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/10 06:34:46 UTC

(nuttx) 09/10: pci/pci_ivshmem: fix bug in remove and add vmid check

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9c91ed23603b758fac0f6146cf54b80df7f0c6f7
Author: Bowen Wang <wa...@xiaomi.com>
AuthorDate: Fri Apr 26 19:36:43 2024 +0800

    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 <wa...@xiaomi.com>
---
 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);
     }