Convert fsl_soc_dma_probe() to managed APIs. Replace the open-coded
of_address_to_resource()/of_iomap() of the DMA channel registers with
devm_platform_ioremap_resource(), and irq_of_parse_and_map() with
platform_get_irq() (which returns a negative errno instead of 0).
Switch the allocation to devm_kzalloc() and register the component via
the devm variant, dropping the now-unneeded error-path cleanup and the
manual fsl_soc_dma_remove().

The SSI node's register resource is still read via of_address_to_resource()
to compute the SSI FIFO physical addresses (dma->ssi_stx_phys /
ssi_srx_phys); only the DMA controller window is mapped.

The DMA controller register window is owned solely by this driver, so the
new region request from devm_platform_ioremap_resource() cannot conflict
with another claimant, and it is mapped exactly once (no double mapping).

The local channel pointer is declared as void __iomem * so the
devm_platform_ioremap_resource() result can be stored before assignment
to dma->channel.

No functional change; built for powerpc (allmodconfig + CONFIG_SND_SOC_FSL_DMA)
with LLVM=1 and sound/soc/fsl/fsl_dma.o compiles cleanly.

Assisted-by: opencode:hy3-free
Signed-off-by: Rosen Penev <[email protected]>
---
 sound/soc/fsl/fsl_dma.c | 68 ++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 41 deletions(-)

diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index b12474880185..b1b341132dd6 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -18,8 +18,6 @@
 #include <linux/delay.h>
 #include <linux/gfp.h>
 #include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/of_platform.h>
 #include <linux/list.h>
 #include <linux/slab.h>
 
@@ -824,9 +822,34 @@ static int fsl_soc_dma_probe(struct platform_device *pdev)
        struct device_node *np = pdev->dev.of_node;
        struct device_node *ssi_np;
        struct resource res;
+       void __iomem *channel;
        const uint32_t *iprop;
+       int irq;
        int ret;
 
+       channel = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(channel))
+               return PTR_ERR(channel);
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0)
+               return irq;
+
+       dma = devm_kzalloc(&pdev->dev, sizeof(*dma), GFP_KERNEL);
+       if (!dma)
+               return -ENOMEM;
+
+       dma->dai.name = DRV_NAME;
+       dma->dai.open = fsl_dma_open;
+       dma->dai.close = fsl_dma_close;
+       dma->dai.hw_params = fsl_dma_hw_params;
+       dma->dai.hw_free = fsl_dma_hw_free;
+       dma->dai.pointer = fsl_dma_pointer;
+       dma->dai.pcm_new = fsl_dma_new;
+
+       dma->channel = channel;
+       dma->irq = irq;
+
        /* Find the SSI node that points to us. */
        ssi_np = find_ssi_node(np);
        if (!ssi_np) {
@@ -842,55 +865,19 @@ static int fsl_soc_dma_probe(struct platform_device *pdev)
                return ret;
        }
 
-       dma = kzalloc_obj(*dma);
-       if (!dma) {
-               of_node_put(ssi_np);
-               return -ENOMEM;
-       }
-
-       dma->dai.name = DRV_NAME;
-       dma->dai.open = fsl_dma_open;
-       dma->dai.close = fsl_dma_close;
-       dma->dai.hw_params = fsl_dma_hw_params;
-       dma->dai.hw_free = fsl_dma_hw_free;
-       dma->dai.pointer = fsl_dma_pointer;
-       dma->dai.pcm_new = fsl_dma_new;
-
        /* Store the SSI-specific information that we need */
        dma->ssi_stx_phys = res.start + REG_SSI_STX0;
        dma->ssi_srx_phys = res.start + REG_SSI_SRX0;
 
        iprop = of_get_property(ssi_np, "fsl,fifo-depth", NULL);
+       of_node_put(ssi_np);
        if (iprop)
                dma->ssi_fifo_depth = be32_to_cpup(iprop);
        else
                 /* Older 8610 DTs didn't have the fifo-depth property */
                dma->ssi_fifo_depth = 8;
 
-       of_node_put(ssi_np);
-
-       ret = devm_snd_soc_register_component(&pdev->dev, &dma->dai, NULL, 0);
-       if (ret) {
-               dev_err(&pdev->dev, "could not register platform\n");
-               kfree(dma);
-               return ret;
-       }
-
-       dma->channel = of_iomap(np, 0);
-       dma->irq = irq_of_parse_and_map(np, 0);
-
-       dev_set_drvdata(&pdev->dev, dma);
-
-       return 0;
-}
-
-static void fsl_soc_dma_remove(struct platform_device *pdev)
-{
-       struct dma_object *dma = dev_get_drvdata(&pdev->dev);
-
-       iounmap(dma->channel);
-       irq_dispose_mapping(dma->irq);
-       kfree(dma);
+       return devm_snd_soc_register_component(&pdev->dev, &dma->dai, NULL, 0);
 }
 
 static const struct of_device_id fsl_soc_dma_ids[] = {
@@ -905,7 +892,6 @@ static struct platform_driver fsl_soc_dma_driver = {
                .of_match_table = fsl_soc_dma_ids,
        },
        .probe = fsl_soc_dma_probe,
-       .remove = fsl_soc_dma_remove,
 };
 
 module_platform_driver(fsl_soc_dma_driver);
-- 
2.55.0


Reply via email to