iommu/fsl_pamu: merge handle_attach_device into fsl_pamu_attach_device
authorChristoph Hellwig <hch@lst.de>
Thu, 1 Apr 2021 15:52:45 +0000 (17:52 +0200)
committerJoerg Roedel <jroedel@suse.de>
Wed, 7 Apr 2021 08:56:52 +0000 (10:56 +0200)
No good reason to split this functionality over two functions.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Will Deacon <will@kernel.org>
Acked-by: Li Yang <leoyang.li@nxp.com>
Link: https://lore.kernel.org/r/20210401155256.298656-10-hch@lst.de
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/fsl_pamu_domain.c

index 198725e..41927c3 100644 (file)
@@ -240,45 +240,13 @@ static int update_domain_stash(struct fsl_dma_domain *dma_domain, u32 val)
        return ret;
 }
 
-/*
- * Attach the LIODN to the DMA domain and configure the geometry
- * and window mappings.
- */
-static int handle_attach_device(struct fsl_dma_domain *dma_domain,
-                               struct device *dev, const u32 *liodn,
-                               int num)
-{
-       unsigned long flags;
-       int ret = 0;
-       int i;
-
-       spin_lock_irqsave(&dma_domain->domain_lock, flags);
-       for (i = 0; i < num; i++) {
-               /* Ensure that LIODN value is valid */
-               if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
-                       pr_debug("Invalid liodn %d, attach device failed for %pOF\n",
-                                liodn[i], dev->of_node);
-                       ret = -EINVAL;
-                       break;
-               }
-
-               attach_device(dma_domain, liodn[i], dev);
-               ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
-               if (ret)
-                       break;
-       }
-       spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-
-       return ret;
-}
-
 static int fsl_pamu_attach_device(struct iommu_domain *domain,
                                  struct device *dev)
 {
        struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
+       unsigned long flags;
+       int len, ret = 0, i;
        const u32 *liodn;
-       u32 liodn_cnt;
-       int len, ret = 0;
        struct pci_dev *pdev = NULL;
        struct pci_controller *pci_ctl;
 
@@ -298,14 +266,27 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
        }
 
        liodn = of_get_property(dev->of_node, "fsl,liodn", &len);
-       if (liodn) {
-               liodn_cnt = len / sizeof(u32);
-               ret = handle_attach_device(dma_domain, dev, liodn, liodn_cnt);
-       } else {
+       if (!liodn) {
                pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
+       spin_lock_irqsave(&dma_domain->domain_lock, flags);
+       for (i = 0; i < len / sizeof(u32); i++) {
+               /* Ensure that LIODN value is valid */
+               if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
+                       pr_debug("Invalid liodn %d, attach device failed for %pOF\n",
+                                liodn[i], dev->of_node);
+                       ret = -EINVAL;
+                       break;
+               }
+
+               attach_device(dma_domain, liodn[i], dev);
+               ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
+               if (ret)
+                       break;
+       }
+       spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
        return ret;
 }