Skip to contentSkip to conversation

dmaengine: ppc4xx: use devm_platform_ioremap_resource()

PATCH Superseded Rosen Penev 2 participants 3 messages Sep 11 – Sep 14 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dmaengine: ppc4xx: use devm_platform_ioremap_resource()

Replace the open-coded sequence of of_address_to_resource(), request_mem_region(), and ioremap() with devm_platform_ioremap_resource(). This eliminates error-path cleanup for both the memory region and the ioremap.

The two separate initcodes PPC_ADMA_INIT_MEMRES and PPC_ADMA_INIT_MEMREG are collapsed into PPC_ADMA_INIT_MEMRES since the combined call covers both steps.

Also emove unused PPC_ADMA_INIT_MEMREG enum value

The PPC_ADMA_INIT_MEMREG error code is no longer used after converting to devm_platform_ioremap_resource(). Remove it from the enum and the corresponding error string.

Assisted-by LLM

---
v2: cut some stuff from description

 drivers/dma/ppc4xx/adma.c | 46 +++++----------------------------------
 1 file changed, 6 insertions(+), 40 deletions(-)
drivers/dma/ppc4xx/adma.c +6 -40
index 39498779e241..17b60704a702 100644
@@ -37,7 +37,6 @@
 enum ppc_adma_init_code {
 	PPC_ADMA_INIT_OK = 0,
 	PPC_ADMA_INIT_MEMRES,
-	PPC_ADMA_INIT_MEMREG,
 	PPC_ADMA_INIT_ALLOC,
 	PPC_ADMA_INIT_COHERENT,
 	PPC_ADMA_INIT_CHANNEL,
@@ -49,7 +48,6 @@ enum ppc_adma_init_code {
 static char *ppc_adma_errors[] = {
 	[PPC_ADMA_INIT_OK] = "ok",
 	[PPC_ADMA_INIT_MEMRES] = "failed to get memory resource",
-	[PPC_ADMA_INIT_MEMREG] = "failed to request memory region",
 	[PPC_ADMA_INIT_ALLOC] = "failed to allocate memory for adev "
 				"structure",
 	[PPC_ADMA_INIT_COHERENT] = "failed to allocate coherent memory for "
@@ -3997,7 +3995,6 @@ static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device *adev,
 static int ppc440spe_adma_probe(struct platform_device *ofdev)
 {
 	struct device_node *np = ofdev->dev.of_node;
-	struct resource res;
 	struct ppc440spe_adma_device *adev;
 	struct ppc440spe_adma_chan *chan;
 	struct ppc_dma_chan_ref *ref, *_ref;
@@ -4040,28 +4037,12 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 		pool_size <<= 2;
 	}
 
-	if (of_address_to_resource(np, 0, &res)) {
-		dev_err(&ofdev->dev, "failed to get memory resource\n");
-		initcode = PPC_ADMA_INIT_MEMRES;
-		ret = -ENODEV;
-		goto out;
-	}
-
-	if (!request_mem_region(res.start, resource_size(&res),
-				dev_driver_string(&ofdev->dev))) {
-		dev_err(&ofdev->dev, "failed to request memory region %pR\n",
-			&res);
-		initcode = PPC_ADMA_INIT_MEMREG;
-		ret = -EBUSY;
-		goto out;
-	}
-
 	/* create a device */
 	adev = kzalloc_obj(*adev);
 	if (!adev) {
 		initcode = PPC_ADMA_INIT_ALLOC;
 		ret = -ENOMEM;
-		goto err_adev_alloc;
+		goto out;
 	}
 
 	adev->id = id;
@@ -4081,10 +4062,10 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 	dev_dbg(&ofdev->dev, "allocated descriptor pool virt 0x%p phys 0x%llx\n",
 		adev->dma_desc_pool_virt, (u64)adev->dma_desc_pool);
 
-	regs = ioremap(res.start, resource_size(&res));
-	if (!regs) {
-		dev_err(&ofdev->dev, "failed to ioremap regs!\n");
-		ret = -ENOMEM;
+	regs = devm_platform_ioremap_resource(ofdev, 0);
+	if (IS_ERR(regs)) {
+		ret = PTR_ERR(regs);
+		initcode = PPC_ADMA_INIT_MEMRES;
 		goto err_regs_alloc;
 	}
 
@@ -4121,7 +4102,7 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 	if (!chan) {
 		initcode = PPC_ADMA_INIT_CHANNEL;
 		ret = -ENOMEM;
-		goto err_chan_alloc;
+		goto err_regs_alloc;
 	}
 
 	spin_lock_init(&chan->lock);
@@ -4214,19 +4195,12 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 	}
 err_page_alloc:
 	kfree(chan);
-err_chan_alloc:
-	if (adev->id == PPC440SPE_XOR_ID)
-		iounmap(adev->xor_reg);
-	else
-		iounmap(adev->dma_reg);
 err_regs_alloc:
 	dma_free_coherent(&ofdev->dev, adev->pool_size,
 			  adev->dma_desc_pool_virt,
 			  adev->dma_desc_pool);
 err_dma_alloc:
 	kfree(adev);
-err_adev_alloc:
-	release_mem_region(res.start, resource_size(&res));
 out:
 	if (id < PPC440SPE_ADMA_ENGINES_NUM)
 		ppc440spe_adma_devices[id] = initcode;
@@ -4240,8 +4214,6 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 static void ppc440spe_adma_remove(struct platform_device *ofdev)
 {
 	struct ppc440spe_adma_device *adev = platform_get_drvdata(ofdev);
-	struct device_node *np = ofdev->dev.of_node;
-	struct resource res;
 	struct dma_chan *chan, *_chan;
 	struct ppc_dma_chan_ref *ref, *_ref;
 	struct ppc440spe_adma_chan *ppc440spe_chan;
@@ -4278,12 +4250,6 @@ static void ppc440spe_adma_remove(struct platform_device *ofdev)
 
 	dma_free_coherent(adev->dev, adev->pool_size,
 			  adev->dma_desc_pool_virt, adev->dma_desc_pool);
-	if (adev->id == PPC440SPE_XOR_ID)
-		iounmap(adev->xor_reg);
-	else
-		iounmap(adev->dma_reg);
-	of_address_to_resource(np, 0, &res);
-	release_mem_region(res.start, resource_size(&res));
 	kfree(adev);
 }
 
Signature · 1 line
2.55.0
#1 lore raw
Quoted 10 lines · Rosen Penev

Replace the open-coded sequence of of_address_to_resource(), request_mem_region(), and ioremap() with devm_platform_ioremap_resource(). This eliminates error-path cleanup for both the memory region and the ioremap.

The two separate initcodes PPC_ADMA_INIT_MEMRES and PPC_ADMA_INIT_MEMREG are collapsed into PPC_ADMA_INIT_MEMRES since the combined call covers both steps.

Also emove unused PPC_ADMA_INIT_MEMREG enum value

emove? can you bound all ppc4xx patches to one patch serial to avoid pick up conflict between these patches.

Frank

Quoted 139 lines

The PPC_ADMA_INIT_MEMREG error code is no longer used after converting to devm_platform_ioremap_resource(). Remove it from the enum and the corresponding error string.

Assisted-by LLM

---
v2: cut some stuff from description

 drivers/dma/ppc4xx/adma.c | 46 +++++----------------------------------
 1 file changed, 6 insertions(+), 40 deletions(-)
drivers/dma/ppc4xx/adma.c +6 -41
index 39498779e241..17b60704a702 100644
@@ -37,7 +37,6 @@
 enum ppc_adma_init_code {
 	PPC_ADMA_INIT_OK = 0,
 	PPC_ADMA_INIT_MEMRES,
-	PPC_ADMA_INIT_MEMREG,
 	PPC_ADMA_INIT_ALLOC,
 	PPC_ADMA_INIT_COHERENT,
 	PPC_ADMA_INIT_CHANNEL,
@@ -49,7 +48,6 @@ enum ppc_adma_init_code {
 static char *ppc_adma_errors[] = {
 	[PPC_ADMA_INIT_OK] = "ok",
 	[PPC_ADMA_INIT_MEMRES] = "failed to get memory resource",
-	[PPC_ADMA_INIT_MEMREG] = "failed to request memory region",
 	[PPC_ADMA_INIT_ALLOC] = "failed to allocate memory for adev "
 				"structure",
 	[PPC_ADMA_INIT_COHERENT] = "failed to allocate coherent memory for "
@@ -3997,7 +3995,6 @@ static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device *adev,
 static int ppc440spe_adma_probe(struct platform_device *ofdev)
 {
 	struct device_node *np = ofdev->dev.of_node;
-	struct resource res;
 	struct ppc440spe_adma_device *adev;
 	struct ppc440spe_adma_chan *chan;
 	struct ppc_dma_chan_ref *ref, *_ref;
@@ -4040,28 +4037,12 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 		pool_size <<= 2;
 	}
 
-	if (of_address_to_resource(np, 0, &res)) {
-		dev_err(&ofdev->dev, "failed to get memory resource\n");
-		initcode = PPC_ADMA_INIT_MEMRES;
-		ret = -ENODEV;
-		goto out;
-	}
-
-	if (!request_mem_region(res.start, resource_size(&res),
-				dev_driver_string(&ofdev->dev))) {
-		dev_err(&ofdev->dev, "failed to request memory region %pR\n",
-			&res);
-		initcode = PPC_ADMA_INIT_MEMREG;
-		ret = -EBUSY;
-		goto out;
-	}
-
 	/* create a device */
 	adev = kzalloc_obj(*adev);
 	if (!adev) {
 		initcode = PPC_ADMA_INIT_ALLOC;
 		ret = -ENOMEM;
-		goto err_adev_alloc;
+		goto out;
 	}
 
 	adev->id = id;
@@ -4081,10 +4062,10 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 	dev_dbg(&ofdev->dev, "allocated descriptor pool virt 0x%p phys 0x%llx\n",
 		adev->dma_desc_pool_virt, (u64)adev->dma_desc_pool);
 
-	regs = ioremap(res.start, resource_size(&res));
-	if (!regs) {
-		dev_err(&ofdev->dev, "failed to ioremap regs!\n");
-		ret = -ENOMEM;
+	regs = devm_platform_ioremap_resource(ofdev, 0);
+	if (IS_ERR(regs)) {
+		ret = PTR_ERR(regs);
+		initcode = PPC_ADMA_INIT_MEMRES;
 		goto err_regs_alloc;
 	}
 
@@ -4121,7 +4102,7 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 	if (!chan) {
 		initcode = PPC_ADMA_INIT_CHANNEL;
 		ret = -ENOMEM;
-		goto err_chan_alloc;
+		goto err_regs_alloc;
 	}
 
 	spin_lock_init(&chan->lock);
@@ -4214,19 +4195,12 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 	}
 err_page_alloc:
 	kfree(chan);
-err_chan_alloc:
-	if (adev->id == PPC440SPE_XOR_ID)
-		iounmap(adev->xor_reg);
-	else
-		iounmap(adev->dma_reg);
 err_regs_alloc:
 	dma_free_coherent(&ofdev->dev, adev->pool_size,
 			  adev->dma_desc_pool_virt,
 			  adev->dma_desc_pool);
 err_dma_alloc:
 	kfree(adev);
-err_adev_alloc:
-	release_mem_region(res.start, resource_size(&res));
 out:
 	if (id < PPC440SPE_ADMA_ENGINES_NUM)
 		ppc440spe_adma_devices[id] = initcode;
@@ -4240,8 +4214,6 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 static void ppc440spe_adma_remove(struct platform_device *ofdev)
 {
 	struct ppc440spe_adma_device *adev = platform_get_drvdata(ofdev);
-	struct device_node *np = ofdev->dev.of_node;
-	struct resource res;
 	struct dma_chan *chan, *_chan;
 	struct ppc_dma_chan_ref *ref, *_ref;
 	struct ppc440spe_adma_chan *ppc440spe_chan;
@@ -4278,12 +4250,6 @@ static void ppc440spe_adma_remove(struct platform_device *ofdev)
 
 	dma_free_coherent(adev->dev, adev->pool_size,
 			  adev->dma_desc_pool_virt, adev->dma_desc_pool);
-	if (adev->id == PPC440SPE_XOR_ID)
-		iounmap(adev->xor_reg);
-	else
-		iounmap(adev->dma_reg);
-	of_address_to_resource(np, 0, &res);
-	release_mem_region(res.start, resource_size(&res));
 	kfree(adev);
 }
 
--

2.55.0

#2 lore raw
Quoted 7 lines · Frank Li
Quoted 5 lines · Rosen Penev

Replace the open-coded sequence of of_address_to_resource(), request_mem_region(), and ioremap() with devm_platform_ioremap_resource(). This eliminates error-path cleanup for both the memory region and the ioremap.

Quoted 8 lines
Quoted 5 lines

The two separate initcodes PPC_ADMA_INIT_MEMRES and PPC_ADMA_INIT_MEMREG are collapsed into PPC_ADMA_INIT_MEMRES since the combined call covers both steps.

Also emove unused PPC_ADMA_INIT_MEMREG enum value

emove? can you bound all ppc4xx patches to one patch serial to avoid pick up conflict between these patches.

I sent the ones that have none.

Quoted 142 lines

Frank

Quoted 139 lines

The PPC_ADMA_INIT_MEMREG error code is no longer used after converting to devm_platform_ioremap_resource(). Remove it from the enum and the corresponding error string.

Assisted-by LLM

---
v2: cut some stuff from description

 drivers/dma/ppc4xx/adma.c | 46 +++++----------------------------------
 1 file changed, 6 insertions(+), 40 deletions(-)
drivers/dma/ppc4xx/adma.c +6 -41
index 39498779e241..17b60704a702 100644
@@ -37,7 +37,6 @@
 enum ppc_adma_init_code {
      PPC_ADMA_INIT_OK = 0,
      PPC_ADMA_INIT_MEMRES,
-     PPC_ADMA_INIT_MEMREG,
      PPC_ADMA_INIT_ALLOC,
      PPC_ADMA_INIT_COHERENT,
      PPC_ADMA_INIT_CHANNEL,
@@ -49,7 +48,6 @@ enum ppc_adma_init_code {
 static char *ppc_adma_errors[] = {
      [PPC_ADMA_INIT_OK] = "ok",
      [PPC_ADMA_INIT_MEMRES] = "failed to get memory resource",
-     [PPC_ADMA_INIT_MEMREG] = "failed to request memory region",
      [PPC_ADMA_INIT_ALLOC] = "failed to allocate memory for adev "
                              "structure",
      [PPC_ADMA_INIT_COHERENT] = "failed to allocate coherent memory for "
@@ -3997,7 +3995,6 @@ static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device *adev,
 static int ppc440spe_adma_probe(struct platform_device *ofdev)
 {
      struct device_node *np = ofdev->dev.of_node;
-     struct resource res;
      struct ppc440spe_adma_device *adev;
      struct ppc440spe_adma_chan *chan;
      struct ppc_dma_chan_ref *ref, *_ref;
@@ -4040,28 +4037,12 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
              pool_size <<= 2;
      }
 
-     if (of_address_to_resource(np, 0, &res)) {
-             dev_err(&ofdev->dev, "failed to get memory resource\n");
-             initcode = PPC_ADMA_INIT_MEMRES;
-             ret = -ENODEV;
-             goto out;
-     }
-
-     if (!request_mem_region(res.start, resource_size(&res),
-                             dev_driver_string(&ofdev->dev))) {
-             dev_err(&ofdev->dev, "failed to request memory region %pR\n",
-                     &res);
-             initcode = PPC_ADMA_INIT_MEMREG;
-             ret = -EBUSY;
-             goto out;
-     }
-
      /* create a device */
      adev = kzalloc_obj(*adev);
      if (!adev) {
              initcode = PPC_ADMA_INIT_ALLOC;
              ret = -ENOMEM;
-             goto err_adev_alloc;
+             goto out;
      }
 
      adev->id = id;
@@ -4081,10 +4062,10 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
      dev_dbg(&ofdev->dev, "allocated descriptor pool virt 0x%p phys 0x%llx\n",
              adev->dma_desc_pool_virt, (u64)adev->dma_desc_pool);
 
-     regs = ioremap(res.start, resource_size(&res));
-     if (!regs) {
-             dev_err(&ofdev->dev, "failed to ioremap regs!\n");
-             ret = -ENOMEM;
+     regs = devm_platform_ioremap_resource(ofdev, 0);
+     if (IS_ERR(regs)) {
+             ret = PTR_ERR(regs);
+             initcode = PPC_ADMA_INIT_MEMRES;
              goto err_regs_alloc;
      }
 
@@ -4121,7 +4102,7 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
      if (!chan) {
              initcode = PPC_ADMA_INIT_CHANNEL;
              ret = -ENOMEM;
-             goto err_chan_alloc;
+             goto err_regs_alloc;
      }
 
      spin_lock_init(&chan->lock);
@@ -4214,19 +4195,12 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
      }
 err_page_alloc:
      kfree(chan);
-err_chan_alloc:
-     if (adev->id == PPC440SPE_XOR_ID)
-             iounmap(adev->xor_reg);
-     else
-             iounmap(adev->dma_reg);
 err_regs_alloc:
      dma_free_coherent(&ofdev->dev, adev->pool_size,
                        adev->dma_desc_pool_virt,
                        adev->dma_desc_pool);
 err_dma_alloc:
      kfree(adev);
-err_adev_alloc:
-     release_mem_region(res.start, resource_size(&res));
 out:
      if (id < PPC440SPE_ADMA_ENGINES_NUM)
              ppc440spe_adma_devices[id] = initcode;
@@ -4240,8 +4214,6 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev)
 static void ppc440spe_adma_remove(struct platform_device *ofdev)
 {
      struct ppc440spe_adma_device *adev = platform_get_drvdata(ofdev);
-     struct device_node *np = ofdev->dev.of_node;
-     struct resource res;
      struct dma_chan *chan, *_chan;
      struct ppc_dma_chan_ref *ref, *_ref;
      struct ppc440spe_adma_chan *ppc440spe_chan;
@@ -4278,12 +4250,6 @@ static void ppc440spe_adma_remove(struct platform_device *ofdev)
 
      dma_free_coherent(adev->dev, adev->pool_size,
                        adev->dma_desc_pool_virt, adev->dma_desc_pool);
-     if (adev->id == PPC440SPE_XOR_ID)
-             iounmap(adev->xor_reg);
-     else
-             iounmap(adev->dma_reg);
-     of_address_to_resource(np, 0, &res);
-     release_mem_region(res.start, resource_size(&res));
      kfree(adev);
 }
 
--

2.55.0