mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister
@ 2024-11-01 10:14 Peng Fan (OSS)
  2024-11-01 10:14 ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove path Peng Fan (OSS)
  2024-11-01 18:27 ` [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Frank Li
  0 siblings, 2 replies; 6+ messages in thread
From: Peng Fan (OSS) @ 2024-11-01 10:14 UTC (permalink / raw)
  To: Frank Li, Vinod Koul, open list:FREESCALE eDMA DRIVER,
	open list:FREESCALE eDMA DRIVER, open list
  Cc: Peng Fan

From: Peng Fan <peng.fan@nxp.com>

There is kernel dump when do module test:
sysfs: cannot create duplicate filename '/devices/platform/soc@0/44000000.bus/44000000.dma-controller/dma/dma0chan0'
 __dma_async_device_channel_register+0x128/0x19c
 dma_async_device_register+0x150/0x454
 fsl_edma_probe+0x6cc/0x8a0
 platform_probe+0x68/0xc8

Clean up chan after dma_async_device_unregister to address this.

Fixes: 6f93b93b2a1b ("dmaengine: fsl-edma: kill the tasklets upon exit")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/dma/fsl-edma-main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
index f9f1eda79254..01bd5cb24a49 100644
--- a/drivers/dma/fsl-edma-main.c
+++ b/drivers/dma/fsl-edma-main.c
@@ -668,9 +668,9 @@ static void fsl_edma_remove(struct platform_device *pdev)
 	struct fsl_edma_engine *fsl_edma = platform_get_drvdata(pdev);
 
 	fsl_edma_irq_exit(pdev, fsl_edma);
-	fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
 	of_dma_controller_free(np);
 	dma_async_device_unregister(&fsl_edma->dma_dev);
+	fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
 	fsl_disable_clocks(fsl_edma, fsl_edma->drvdata->dmamuxs);
 }
 
-- 
2.37.1


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

* [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove path
  2024-11-01 10:14 [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Peng Fan (OSS)
@ 2024-11-01 10:14 ` Peng Fan (OSS)
  2024-11-01 18:29   ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove pathy Frank Li
  2024-11-01 18:27 ` [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Frank Li
  1 sibling, 1 reply; 6+ messages in thread
From: Peng Fan (OSS) @ 2024-11-01 10:14 UTC (permalink / raw)
  To: Frank Li, Vinod Koul, open list:FREESCALE eDMA DRIVER,
	open list:FREESCALE eDMA DRIVER, open list
  Cc: Peng Fan

From: Peng Fan <peng.fan@nxp.com>

To i.MX9, there is no valid fsl_edma->txirq/errirq, so add a check in
fsl_edma_irq_exit to avoid issues.

Fixes: 44eb827264de ("dmaengine: fsl-edma: request per-channel IRQ only when channel is allocated")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/dma/fsl-edma-main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
index 01bd5cb24a49..89c54eeb4925 100644
--- a/drivers/dma/fsl-edma-main.c
+++ b/drivers/dma/fsl-edma-main.c
@@ -303,6 +303,7 @@ fsl_edma2_irq_init(struct platform_device *pdev,
 
 		/* The last IRQ is for eDMA err */
 		if (i == count - 1) {
+			fsl_edma->errirq = irq;
 			ret = devm_request_irq(&pdev->dev, irq,
 						fsl_edma_err_handler,
 						0, "eDMA2-ERR", fsl_edma);
@@ -322,10 +323,13 @@ static void fsl_edma_irq_exit(
 		struct platform_device *pdev, struct fsl_edma_engine *fsl_edma)
 {
 	if (fsl_edma->txirq == fsl_edma->errirq) {
-		devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
+		if (fsl_edma->txirq >= 0)
+			devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
 	} else {
-		devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
-		devm_free_irq(&pdev->dev, fsl_edma->errirq, fsl_edma);
+		if (fsl_edma->txirq >= 0)
+			devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
+		if (fsl_edma->errirq >= 0)
+			devm_free_irq(&pdev->dev, fsl_edma->errirq, fsl_edma);
 	}
 }
 
@@ -485,6 +489,8 @@ static int fsl_edma_probe(struct platform_device *pdev)
 	if (!fsl_edma)
 		return -ENOMEM;
 
+	fsl_edma->errirq = -EINVAL;
+	fsl_edma->txirq = -EINVAL;
 	fsl_edma->drvdata = drvdata;
 	fsl_edma->n_chans = chans;
 	mutex_init(&fsl_edma->fsl_edma_mutex);
-- 
2.37.1


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

* Re: [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister
  2024-11-01 10:14 [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Peng Fan (OSS)
  2024-11-01 10:14 ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove path Peng Fan (OSS)
@ 2024-11-01 18:27 ` Frank Li
  2024-11-04  5:35   ` Peng Fan
  1 sibling, 1 reply; 6+ messages in thread
From: Frank Li @ 2024-11-01 18:27 UTC (permalink / raw)
  To: Peng Fan (OSS)
  Cc: Vinod Koul, open list:FREESCALE eDMA DRIVER,
	open list:FREESCALE eDMA DRIVER, open list, Peng Fan

On Fri, Nov 01, 2024 at 06:14:09PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> There is kernel dump when do module test:
> sysfs: cannot create duplicate filename '/devices/platform/soc@0/44000000.bus/44000000.dma-controller/dma/dma0chan0'
>  __dma_async_device_channel_register+0x128/0x19c
>  dma_async_device_register+0x150/0x454
>  fsl_edma_probe+0x6cc/0x8a0
>  platform_probe+0x68/0xc8
>
> Clean up chan after dma_async_device_unregister to address this.

Can you explan why move it after dma_async_device_unregiste() can fix this
problem?

Frank
>
> Fixes: 6f93b93b2a1b ("dmaengine: fsl-edma: kill the tasklets upon exit")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/dma/fsl-edma-main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
> index f9f1eda79254..01bd5cb24a49 100644
> --- a/drivers/dma/fsl-edma-main.c
> +++ b/drivers/dma/fsl-edma-main.c
> @@ -668,9 +668,9 @@ static void fsl_edma_remove(struct platform_device *pdev)
>  	struct fsl_edma_engine *fsl_edma = platform_get_drvdata(pdev);
>
>  	fsl_edma_irq_exit(pdev, fsl_edma);
> -	fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
>  	of_dma_controller_free(np);
>  	dma_async_device_unregister(&fsl_edma->dma_dev);
> +	fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
>  	fsl_disable_clocks(fsl_edma, fsl_edma->drvdata->dmamuxs);
>  }
>
> --
> 2.37.1
>

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

* Re: [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove pathy
  2024-11-01 10:14 ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove path Peng Fan (OSS)
@ 2024-11-01 18:29   ` Frank Li
  2024-11-04  3:13     ` Peng Fan
  0 siblings, 1 reply; 6+ messages in thread
From: Frank Li @ 2024-11-01 18:29 UTC (permalink / raw)
  To: Peng Fan (OSS)
  Cc: Vinod Koul, open list:FREESCALE eDMA DRIVER,
	open list:FREESCALE eDMA DRIVER, open list, Peng Fan

On Fri, Nov 01, 2024 at 06:14:10PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> To i.MX9, there is no valid fsl_edma->txirq/errirq, so add a check in
> fsl_edma_irq_exit to avoid issues.
>
> Fixes: 44eb827264de ("dmaengine: fsl-edma: request per-channel IRQ only when channel is allocated")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/dma/fsl-edma-main.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
> index 01bd5cb24a49..89c54eeb4925 100644
> --- a/drivers/dma/fsl-edma-main.c
> +++ b/drivers/dma/fsl-edma-main.c
> @@ -303,6 +303,7 @@ fsl_edma2_irq_init(struct platform_device *pdev,
>
>  		/* The last IRQ is for eDMA err */
>  		if (i == count - 1) {
> +			fsl_edma->errirq = irq;
>  			ret = devm_request_irq(&pdev->dev, irq,
>  						fsl_edma_err_handler,
>  						0, "eDMA2-ERR", fsl_edma);
> @@ -322,10 +323,13 @@ static void fsl_edma_irq_exit(
>  		struct platform_device *pdev, struct fsl_edma_engine *fsl_edma)
>  {
>  	if (fsl_edma->txirq == fsl_edma->errirq) {
> -		devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
> +		if (fsl_edma->txirq >= 0)
> +			devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
>  	} else {
> -		devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
> -		devm_free_irq(&pdev->dev, fsl_edma->errirq, fsl_edma);
> +		if (fsl_edma->txirq >= 0)
> +			devm_free_irq(&pdev->dev, fsl_edma->txirq, fsl_edma);
> +		if (fsl_edma->errirq >= 0)
> +			devm_free_irq(&pdev->dev, fsl_edma->errirq, fsl_edma);
>  	}
>  }
>
> @@ -485,6 +489,8 @@ static int fsl_edma_probe(struct platform_device *pdev)
>  	if (!fsl_edma)
>  		return -ENOMEM;
>
> +	fsl_edma->errirq = -EINVAL;
> +	fsl_edma->txirq = -EINVAL;

why not use 0 as invalidate?

Frank

>  	fsl_edma->drvdata = drvdata;
>  	fsl_edma->n_chans = chans;
>  	mutex_init(&fsl_edma->fsl_edma_mutex);
> --
> 2.37.1
>

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

* RE: [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove pathy
  2024-11-01 18:29   ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove pathy Frank Li
@ 2024-11-04  3:13     ` Peng Fan
  0 siblings, 0 replies; 6+ messages in thread
From: Peng Fan @ 2024-11-04  3:13 UTC (permalink / raw)
  To: Frank Li, Peng Fan (OSS)
  Cc: Vinod Koul, open list:FREESCALE eDMA DRIVER,
	open list:FREESCALE eDMA DRIVER, open list

> Subject: Re: [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in
> remove pathy
> 
> On Fri, Nov 01, 2024 at 06:14:10PM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > To i.MX9, there is no valid fsl_edma->txirq/errirq, so add a check in
> > fsl_edma_irq_exit to avoid issues.
> >
> > Fixes: 44eb827264de ("dmaengine: fsl-edma: request per-channel
> IRQ
> > only when channel is allocated")
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  drivers/dma/fsl-edma-main.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-
> main.c
> > index 01bd5cb24a49..89c54eeb4925 100644
> > --- a/drivers/dma/fsl-edma-main.c
> > +++ b/drivers/dma/fsl-edma-main.c
> > @@ -303,6 +303,7 @@ fsl_edma2_irq_init(struct platform_device
> *pdev,
> >
> >  		/* The last IRQ is for eDMA err */
> >  		if (i == count - 1) {
> > +			fsl_edma->errirq = irq;
> >  			ret = devm_request_irq(&pdev->dev, irq,
> >
> 	fsl_edma_err_handler,
> >  						0, "eDMA2-ERR",
> fsl_edma);
> > @@ -322,10 +323,13 @@ static void fsl_edma_irq_exit(
> >  		struct platform_device *pdev, struct fsl_edma_engine
> *fsl_edma)  {
> >  	if (fsl_edma->txirq == fsl_edma->errirq) {
> > -		devm_free_irq(&pdev->dev, fsl_edma->txirq,
> fsl_edma);
> > +		if (fsl_edma->txirq >= 0)
> > +			devm_free_irq(&pdev->dev, fsl_edma->txirq,
> fsl_edma);
> >  	} else {
> > -		devm_free_irq(&pdev->dev, fsl_edma->txirq,
> fsl_edma);
> > -		devm_free_irq(&pdev->dev, fsl_edma->errirq,
> fsl_edma);
> > +		if (fsl_edma->txirq >= 0)
> > +			devm_free_irq(&pdev->dev, fsl_edma->txirq,
> fsl_edma);
> > +		if (fsl_edma->errirq >= 0)
> > +			devm_free_irq(&pdev->dev, fsl_edma->errirq,
> fsl_edma);
> >  	}
> >  }
> >
> > @@ -485,6 +489,8 @@ static int fsl_edma_probe(struct
> platform_device *pdev)
> >  	if (!fsl_edma)
> >  		return -ENOMEM;
> >
> > +	fsl_edma->errirq = -EINVAL;
> > +	fsl_edma->txirq = -EINVAL;
> 
> why not use 0 as invalidate?

I think 0 might be a valid value. So use -EINVAL here.

Thanks,
Peng.

> 
> Frank
> 
> >  	fsl_edma->drvdata = drvdata;
> >  	fsl_edma->n_chans = chans;
> >  	mutex_init(&fsl_edma->fsl_edma_mutex);
> > --
> > 2.37.1
> >

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

* RE: [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister
  2024-11-01 18:27 ` [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Frank Li
@ 2024-11-04  5:35   ` Peng Fan
  0 siblings, 0 replies; 6+ messages in thread
From: Peng Fan @ 2024-11-04  5:35 UTC (permalink / raw)
  To: Frank Li, Peng Fan (OSS)
  Cc: Vinod Koul, open list:FREESCALE eDMA DRIVER,
	open list:FREESCALE eDMA DRIVER, open list

> Subject: Re: [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after
> dma_async_device_unregister
> 
> On Fri, Nov 01, 2024 at 06:14:09PM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > There is kernel dump when do module test:
> > sysfs: cannot create duplicate filename
> '/devices/platform/soc@0/44000000.bus/44000000.dma-
> controller/dma/dma0chan0'
> >  __dma_async_device_channel_register+0x128/0x19c
> >  dma_async_device_register+0x150/0x454
> >  fsl_edma_probe+0x6cc/0x8a0
> >  platform_probe+0x68/0xc8
> >
> > Clean up chan after dma_async_device_unregister to address this.
> 
> Can you explan why move it after dma_async_device_unregiste() can
> fix this problem?

fsl_edma_cleanup_vchan will unlink vchan.chan.device_node,
while dma_async_device_unregister  needs the link to do
__dma_async_device_channel_unregister. So need move
fsl_edma_cleanup_vchan after dma_async_device_unregister
to make sure channel could be freed.

I will include this in V2 commit log.

Thanks,
Peng.

> 
> Frank
> >
> > Fixes: 6f93b93b2a1b ("dmaengine: fsl-edma: kill the tasklets upon
> > exit")
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  drivers/dma/fsl-edma-main.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-
> main.c
> > index f9f1eda79254..01bd5cb24a49 100644
> > --- a/drivers/dma/fsl-edma-main.c
> > +++ b/drivers/dma/fsl-edma-main.c
> > @@ -668,9 +668,9 @@ static void fsl_edma_remove(struct
> platform_device *pdev)
> >  	struct fsl_edma_engine *fsl_edma =
> platform_get_drvdata(pdev);
> >
> >  	fsl_edma_irq_exit(pdev, fsl_edma);
> > -	fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
> >  	of_dma_controller_free(np);
> >  	dma_async_device_unregister(&fsl_edma->dma_dev);
> > +	fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
> >  	fsl_disable_clocks(fsl_edma, fsl_edma->drvdata->dmamuxs);  }
> >
> > --
> > 2.37.1
> >

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

end of thread, other threads:[~2024-11-04  5:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-01 10:14 [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Peng Fan (OSS)
2024-11-01 10:14 ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove path Peng Fan (OSS)
2024-11-01 18:29   ` [PATCH 2/2] dmaengine: fsl-edma: free irq correctly in remove pathy Frank Li
2024-11-04  3:13     ` Peng Fan
2024-11-01 18:27 ` [PATCH 1/2] dmaengine: fsl-edma: cleanup chan after dma_async_device_unregister Frank Li
2024-11-04  5:35   ` Peng Fan

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

all inboxes | Powered by JetHome®