mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dmaengine: fsl_raid: free resources in probe
@ 2026-07-18 23:17 Rosen Penev
  2026-07-20 16:04 ` Frank Li
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-07-18 23:17 UTC (permalink / raw)
  To: dmaengine; +Cc: Vinod Koul, Frank Li, Xuelin Shi, Harninder Rai, open list

Add free_irq() in the error unwind of fsl_re_chan_probe() and in
fsl_re_remove_chan() so the interrupt is always released.

Also add tasklet_kill(). Present in _remove but not _probe.

Also add platform_device_put on failure as of_platform_device_create()
increases the reference count and needs platform_device_put on failure.
Requires placing the pointer in the struct for the _remove function.
While at it, use platform_get/set_drvdata as there's no need for using a
device pointer for that.

Fixes: ad80da658bbc ("dmaengine: Driver support for FSL RaidEngine device.")
Assisted-by: opencode:hy3-free
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/dma/fsl_raid.c | 32 ++++++++++++++++++++------------
 drivers/dma/fsl_raid.h |  1 +
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c
index 0b0b4e8fc821..b1a10292324d 100644
--- a/drivers/dma/fsl_raid.c
+++ b/drivers/dma/fsl_raid.c
@@ -212,10 +212,11 @@ static void fsl_re_dequeue(struct tasklet_struct *t)
 /* Per Job Ring interrupt handler */
 static irqreturn_t fsl_re_isr(int irq, void *data)
 {
+	struct platform_device *pdata = data;
 	struct fsl_re_chan *re_chan;
 	u32 irqstate, status;
 
-	re_chan = dev_get_drvdata((struct device *)data);
+	re_chan = platform_get_drvdata(pdata);
 
 	irqstate = in_be32(&re_chan->jrregs->jr_interrupt_status);
 	if (!irqstate)
@@ -645,7 +646,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
 	struct platform_device *chan_ofdev;
 
 	dev = &ofdev->dev;
-	re_priv = dev_get_drvdata(dev);
+	re_priv = platform_get_drvdata(ofdev);
 	dma_dev = &re_priv->dma_dev;
 
 	chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL);
@@ -656,8 +657,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
 	chan_ofdev = of_platform_device_create(np, NULL, dev);
 	if (!chan_ofdev) {
 		dev_err(dev, "Not able to create ofdev for jr %d\n", q);
-		ret = -EINVAL;
-		goto err_free;
+		return -EINVAL;
 	}
 
 	/* read reg property from dts */
@@ -683,17 +683,18 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
 	chandev = &chan_ofdev->dev;
 	tasklet_setup(&chan->irqtask, fsl_re_dequeue);
 
-	ret = request_irq(chan->irq, fsl_re_isr, 0, chan->name, chandev);
+	ret = request_irq(chan->irq, fsl_re_isr, 0, chan->name, chan_ofdev);
 	if (ret) {
 		dev_err(dev, "Unable to register interrupt for JR %d\n", q);
 		ret = -EINVAL;
-		goto err_free;
+		goto err_free_tasklet;
 	}
 
 	re_priv->re_jrs[q] = chan;
 	chan->chan.device = dma_dev;
 	chan->chan.private = chan;
 	chan->dev = chandev;
+	chan->ofdev = chan_ofdev;
 	chan->re_dev = re_priv;
 
 	spin_lock_init(&chan->desc_lock);
@@ -707,7 +708,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
 	if (!chan->inb_ring_virt_addr) {
 		dev_err(dev, "No dma memory for inb_ring_virt_addr\n");
 		ret = -ENOMEM;
-		goto err_free;
+		goto err_free_irq;
 	}
 
 	chan->oub_ring_virt_addr = dma_pool_alloc(chan->re_dev->hw_desc_pool,
@@ -739,7 +740,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
 	out_be32(&chan->jrregs->jr_config_1,
 		 FSL_RE_CFG1_CBSI | FSL_RE_CFG1_CBS0 | status);
 
-	dev_set_drvdata(chandev, chan);
+	platform_set_drvdata(chan_ofdev, chan);
 
 	/* Enable RE/CHAN */
 	out_be32(&chan->jrregs->jr_command, FSL_RE_ENABLE);
@@ -749,7 +750,12 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
 err_free_1:
 	dma_pool_free(chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr,
 		      chan->inb_phys_addr);
+err_free_irq:
+	free_irq(chan->irq, chan_ofdev);
+err_free_tasklet:
+	tasklet_kill(&chan->irqtask);
 err_free:
+	platform_device_put(chan_ofdev);
 	return ret;
 }
 
@@ -828,7 +834,7 @@ static int fsl_re_probe(struct platform_device *ofdev)
 		return -ENOMEM;
 	}
 
-	dev_set_drvdata(dev, re_priv);
+	platform_set_drvdata(ofdev, re_priv);
 
 	/* Parse Device tree to find out the total number of JQs present */
 	for_each_compatible_node_scoped(np, NULL, "fsl,raideng-v1.0-job-queue") {
@@ -864,21 +870,23 @@ static void fsl_re_remove_chan(struct fsl_re_chan *chan)
 {
 	tasklet_kill(&chan->irqtask);
 
+	free_irq(chan->irq, chan->ofdev);
+
 	dma_pool_free(chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr,
 		      chan->inb_phys_addr);
 
 	dma_pool_free(chan->re_dev->hw_desc_pool, chan->oub_ring_virt_addr,
 		      chan->oub_phys_addr);
+
+	platform_device_put(chan->ofdev);
 }
 
 static void fsl_re_remove(struct platform_device *ofdev)
 {
 	struct fsl_re_drv_private *re_priv;
-	struct device *dev;
 	int i;
 
-	dev = &ofdev->dev;
-	re_priv = dev_get_drvdata(dev);
+	re_priv = platform_get_drvdata(ofdev);
 
 	/* Cleanup chan related memory areas */
 	for (i = 0; i < re_priv->total_chans; i++)
diff --git a/drivers/dma/fsl_raid.h b/drivers/dma/fsl_raid.h
index adbfede330a7..34d362803610 100644
--- a/drivers/dma/fsl_raid.h
+++ b/drivers/dma/fsl_raid.h
@@ -270,6 +270,7 @@ struct fsl_re_chan {
 	struct list_head active_q; /* already issued on hw, not completed */
 	struct list_head submit_q;
 	struct list_head free_q; /* alloc available queue */
+	struct platform_device *ofdev;
 	struct device *dev;
 	struct fsl_re_drv_private *re_dev;
 	struct dma_chan chan;
-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] dmaengine: fsl_raid: free resources in probe
  2026-07-18 23:17 [PATCH] dmaengine: fsl_raid: free resources in probe Rosen Penev
@ 2026-07-20 16:04 ` Frank Li
  2026-07-20 20:15   ` Rosen Penev
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Li @ 2026-07-20 16:04 UTC (permalink / raw)
  To: Rosen Penev
  Cc: dmaengine, Vinod Koul, Frank Li, Xuelin Shi, Harninder Rai, open list

On Sat, Jul 18, 2026 at 04:17:15PM -0700, Rosen Penev wrote:
> Add free_irq() in the error unwind of fsl_re_chan_probe() and in
> fsl_re_remove_chan() so the interrupt is always released.
>
> Also add tasklet_kill(). Present in _remove but not _probe.
>
> Also add platform_device_put on failure as of_platform_device_create()
> increases the reference count and needs platform_device_put on failure.
> Requires placing the pointer in the struct for the _remove function.
> While at it, use platform_get/set_drvdata as there's no need for using a
> device pointer for that.
>

Can you split these patch, one patch just fix one problem.
1: replace dev_get_drvdata() with platform_get_drvdata()
2: add error handle one by one.


Frank

> Fixes: ad80da658bbc ("dmaengine: Driver support for FSL RaidEngine device.")
> Assisted-by: opencode:hy3-free
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/dma/fsl_raid.c | 32 ++++++++++++++++++++------------
>  drivers/dma/fsl_raid.h |  1 +
>  2 files changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c
> index 0b0b4e8fc821..b1a10292324d 100644
> --- a/drivers/dma/fsl_raid.c
> +++ b/drivers/dma/fsl_raid.c
> @@ -212,10 +212,11 @@ static void fsl_re_dequeue(struct tasklet_struct *t)
>  /* Per Job Ring interrupt handler */
>  static irqreturn_t fsl_re_isr(int irq, void *data)
>  {
> +	struct platform_device *pdata = data;
>  	struct fsl_re_chan *re_chan;
>  	u32 irqstate, status;
>
> -	re_chan = dev_get_drvdata((struct device *)data);
> +	re_chan = platform_get_drvdata(pdata);
>
>  	irqstate = in_be32(&re_chan->jrregs->jr_interrupt_status);
>  	if (!irqstate)
> @@ -645,7 +646,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
>  	struct platform_device *chan_ofdev;
>
>  	dev = &ofdev->dev;
> -	re_priv = dev_get_drvdata(dev);
> +	re_priv = platform_get_drvdata(ofdev);
>  	dma_dev = &re_priv->dma_dev;
>
>  	chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL);
> @@ -656,8 +657,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
>  	chan_ofdev = of_platform_device_create(np, NULL, dev);
>  	if (!chan_ofdev) {
>  		dev_err(dev, "Not able to create ofdev for jr %d\n", q);
> -		ret = -EINVAL;
> -		goto err_free;
> +		return -EINVAL;
>  	}
>
>  	/* read reg property from dts */
> @@ -683,17 +683,18 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
>  	chandev = &chan_ofdev->dev;
>  	tasklet_setup(&chan->irqtask, fsl_re_dequeue);
>
> -	ret = request_irq(chan->irq, fsl_re_isr, 0, chan->name, chandev);
> +	ret = request_irq(chan->irq, fsl_re_isr, 0, chan->name, chan_ofdev);
>  	if (ret) {
>  		dev_err(dev, "Unable to register interrupt for JR %d\n", q);
>  		ret = -EINVAL;
> -		goto err_free;
> +		goto err_free_tasklet;
>  	}
>
>  	re_priv->re_jrs[q] = chan;
>  	chan->chan.device = dma_dev;
>  	chan->chan.private = chan;
>  	chan->dev = chandev;
> +	chan->ofdev = chan_ofdev;
>  	chan->re_dev = re_priv;
>
>  	spin_lock_init(&chan->desc_lock);
> @@ -707,7 +708,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
>  	if (!chan->inb_ring_virt_addr) {
>  		dev_err(dev, "No dma memory for inb_ring_virt_addr\n");
>  		ret = -ENOMEM;
> -		goto err_free;
> +		goto err_free_irq;
>  	}
>
>  	chan->oub_ring_virt_addr = dma_pool_alloc(chan->re_dev->hw_desc_pool,
> @@ -739,7 +740,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
>  	out_be32(&chan->jrregs->jr_config_1,
>  		 FSL_RE_CFG1_CBSI | FSL_RE_CFG1_CBS0 | status);
>
> -	dev_set_drvdata(chandev, chan);
> +	platform_set_drvdata(chan_ofdev, chan);
>
>  	/* Enable RE/CHAN */
>  	out_be32(&chan->jrregs->jr_command, FSL_RE_ENABLE);
> @@ -749,7 +750,12 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
>  err_free_1:
>  	dma_pool_free(chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr,
>  		      chan->inb_phys_addr);
> +err_free_irq:
> +	free_irq(chan->irq, chan_ofdev);
> +err_free_tasklet:
> +	tasklet_kill(&chan->irqtask);
>  err_free:
> +	platform_device_put(chan_ofdev);
>  	return ret;
>  }
>
> @@ -828,7 +834,7 @@ static int fsl_re_probe(struct platform_device *ofdev)
>  		return -ENOMEM;
>  	}
>
> -	dev_set_drvdata(dev, re_priv);
> +	platform_set_drvdata(ofdev, re_priv);
>
>  	/* Parse Device tree to find out the total number of JQs present */
>  	for_each_compatible_node_scoped(np, NULL, "fsl,raideng-v1.0-job-queue") {
> @@ -864,21 +870,23 @@ static void fsl_re_remove_chan(struct fsl_re_chan *chan)
>  {
>  	tasklet_kill(&chan->irqtask);
>
> +	free_irq(chan->irq, chan->ofdev);
> +
>  	dma_pool_free(chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr,
>  		      chan->inb_phys_addr);
>
>  	dma_pool_free(chan->re_dev->hw_desc_pool, chan->oub_ring_virt_addr,
>  		      chan->oub_phys_addr);
> +
> +	platform_device_put(chan->ofdev);
>  }
>
>  static void fsl_re_remove(struct platform_device *ofdev)
>  {
>  	struct fsl_re_drv_private *re_priv;
> -	struct device *dev;
>  	int i;
>
> -	dev = &ofdev->dev;
> -	re_priv = dev_get_drvdata(dev);
> +	re_priv = platform_get_drvdata(ofdev);
>
>  	/* Cleanup chan related memory areas */
>  	for (i = 0; i < re_priv->total_chans; i++)
> diff --git a/drivers/dma/fsl_raid.h b/drivers/dma/fsl_raid.h
> index adbfede330a7..34d362803610 100644
> --- a/drivers/dma/fsl_raid.h
> +++ b/drivers/dma/fsl_raid.h
> @@ -270,6 +270,7 @@ struct fsl_re_chan {
>  	struct list_head active_q; /* already issued on hw, not completed */
>  	struct list_head submit_q;
>  	struct list_head free_q; /* alloc available queue */
> +	struct platform_device *ofdev;
>  	struct device *dev;
>  	struct fsl_re_drv_private *re_dev;
>  	struct dma_chan chan;
> --
> 2.55.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] dmaengine: fsl_raid: free resources in probe
  2026-07-20 16:04 ` Frank Li
@ 2026-07-20 20:15   ` Rosen Penev
  0 siblings, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2026-07-20 20:15 UTC (permalink / raw)
  To: Frank Li
  Cc: dmaengine, Vinod Koul, Frank Li, Xuelin Shi, Harninder Rai, open list

On Mon, Jul 20, 2026 at 9:04 AM Frank Li <Frank.li@oss.nxp.com> wrote:
>
> On Sat, Jul 18, 2026 at 04:17:15PM -0700, Rosen Penev wrote:
> > Add free_irq() in the error unwind of fsl_re_chan_probe() and in
> > fsl_re_remove_chan() so the interrupt is always released.
> >
> > Also add tasklet_kill(). Present in _remove but not _probe.
> >
> > Also add platform_device_put on failure as of_platform_device_create()
> > increases the reference count and needs platform_device_put on failure.
> > Requires placing the pointer in the struct for the _remove function.
> > While at it, use platform_get/set_drvdata as there's no need for using a
> > device pointer for that.
> >
>
> Can you split these patch, one patch just fix one problem.
> 1: replace dev_get_drvdata() with platform_get_drvdata()
> 2: add error handle one by one.
I think splitting into two is fine. The problem with splitting the
resource patch in two is the intermediate state would be broken.

2 files changed, 15 insertions(+), 6 deletions(-)

is a small enough patch anyway.
>
>
> Frank
>
> > Fixes: ad80da658bbc ("dmaengine: Driver support for FSL RaidEngine device.")
> > Assisted-by: opencode:hy3-free
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >  drivers/dma/fsl_raid.c | 32 ++++++++++++++++++++------------
> >  drivers/dma/fsl_raid.h |  1 +
> >  2 files changed, 21 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c
> > index 0b0b4e8fc821..b1a10292324d 100644
> > --- a/drivers/dma/fsl_raid.c
> > +++ b/drivers/dma/fsl_raid.c
> > @@ -212,10 +212,11 @@ static void fsl_re_dequeue(struct tasklet_struct *t)
> >  /* Per Job Ring interrupt handler */
> >  static irqreturn_t fsl_re_isr(int irq, void *data)
> >  {
> > +     struct platform_device *pdata = data;
> >       struct fsl_re_chan *re_chan;
> >       u32 irqstate, status;
> >
> > -     re_chan = dev_get_drvdata((struct device *)data);
> > +     re_chan = platform_get_drvdata(pdata);
> >
> >       irqstate = in_be32(&re_chan->jrregs->jr_interrupt_status);
> >       if (!irqstate)
> > @@ -645,7 +646,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
> >       struct platform_device *chan_ofdev;
> >
> >       dev = &ofdev->dev;
> > -     re_priv = dev_get_drvdata(dev);
> > +     re_priv = platform_get_drvdata(ofdev);
> >       dma_dev = &re_priv->dma_dev;
> >
> >       chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL);
> > @@ -656,8 +657,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
> >       chan_ofdev = of_platform_device_create(np, NULL, dev);
> >       if (!chan_ofdev) {
> >               dev_err(dev, "Not able to create ofdev for jr %d\n", q);
> > -             ret = -EINVAL;
> > -             goto err_free;
> > +             return -EINVAL;
> >       }
> >
> >       /* read reg property from dts */
> > @@ -683,17 +683,18 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
> >       chandev = &chan_ofdev->dev;
> >       tasklet_setup(&chan->irqtask, fsl_re_dequeue);
> >
> > -     ret = request_irq(chan->irq, fsl_re_isr, 0, chan->name, chandev);
> > +     ret = request_irq(chan->irq, fsl_re_isr, 0, chan->name, chan_ofdev);
> >       if (ret) {
> >               dev_err(dev, "Unable to register interrupt for JR %d\n", q);
> >               ret = -EINVAL;
> > -             goto err_free;
> > +             goto err_free_tasklet;
> >       }
> >
> >       re_priv->re_jrs[q] = chan;
> >       chan->chan.device = dma_dev;
> >       chan->chan.private = chan;
> >       chan->dev = chandev;
> > +     chan->ofdev = chan_ofdev;
> >       chan->re_dev = re_priv;
> >
> >       spin_lock_init(&chan->desc_lock);
> > @@ -707,7 +708,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
> >       if (!chan->inb_ring_virt_addr) {
> >               dev_err(dev, "No dma memory for inb_ring_virt_addr\n");
> >               ret = -ENOMEM;
> > -             goto err_free;
> > +             goto err_free_irq;
> >       }
> >
> >       chan->oub_ring_virt_addr = dma_pool_alloc(chan->re_dev->hw_desc_pool,
> > @@ -739,7 +740,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
> >       out_be32(&chan->jrregs->jr_config_1,
> >                FSL_RE_CFG1_CBSI | FSL_RE_CFG1_CBS0 | status);
> >
> > -     dev_set_drvdata(chandev, chan);
> > +     platform_set_drvdata(chan_ofdev, chan);
> >
> >       /* Enable RE/CHAN */
> >       out_be32(&chan->jrregs->jr_command, FSL_RE_ENABLE);
> > @@ -749,7 +750,12 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
> >  err_free_1:
> >       dma_pool_free(chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr,
> >                     chan->inb_phys_addr);
> > +err_free_irq:
> > +     free_irq(chan->irq, chan_ofdev);
> > +err_free_tasklet:
> > +     tasklet_kill(&chan->irqtask);
> >  err_free:
> > +     platform_device_put(chan_ofdev);
> >       return ret;
> >  }
> >
> > @@ -828,7 +834,7 @@ static int fsl_re_probe(struct platform_device *ofdev)
> >               return -ENOMEM;
> >       }
> >
> > -     dev_set_drvdata(dev, re_priv);
> > +     platform_set_drvdata(ofdev, re_priv);
> >
> >       /* Parse Device tree to find out the total number of JQs present */
> >       for_each_compatible_node_scoped(np, NULL, "fsl,raideng-v1.0-job-queue") {
> > @@ -864,21 +870,23 @@ static void fsl_re_remove_chan(struct fsl_re_chan *chan)
> >  {
> >       tasklet_kill(&chan->irqtask);
> >
> > +     free_irq(chan->irq, chan->ofdev);
> > +
> >       dma_pool_free(chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr,
> >                     chan->inb_phys_addr);
> >
> >       dma_pool_free(chan->re_dev->hw_desc_pool, chan->oub_ring_virt_addr,
> >                     chan->oub_phys_addr);
> > +
> > +     platform_device_put(chan->ofdev);
> >  }
> >
> >  static void fsl_re_remove(struct platform_device *ofdev)
> >  {
> >       struct fsl_re_drv_private *re_priv;
> > -     struct device *dev;
> >       int i;
> >
> > -     dev = &ofdev->dev;
> > -     re_priv = dev_get_drvdata(dev);
> > +     re_priv = platform_get_drvdata(ofdev);
> >
> >       /* Cleanup chan related memory areas */
> >       for (i = 0; i < re_priv->total_chans; i++)
> > diff --git a/drivers/dma/fsl_raid.h b/drivers/dma/fsl_raid.h
> > index adbfede330a7..34d362803610 100644
> > --- a/drivers/dma/fsl_raid.h
> > +++ b/drivers/dma/fsl_raid.h
> > @@ -270,6 +270,7 @@ struct fsl_re_chan {
> >       struct list_head active_q; /* already issued on hw, not completed */
> >       struct list_head submit_q;
> >       struct list_head free_q; /* alloc available queue */
> > +     struct platform_device *ofdev;
> >       struct device *dev;
> >       struct fsl_re_drv_private *re_dev;
> >       struct dma_chan chan;
> > --
> > 2.55.0
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-20 20:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-18 23:17 [PATCH] dmaengine: fsl_raid: free resources in probe Rosen Penev
2026-07-20 16:04 ` Frank Li
2026-07-20 20:15   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome