diff mbox

[1/2] dmaengine: axi-dmac: Use devm_request_irq()

Message ID 20180426161239.15234-1-mdf@kernel.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Moritz Fischer April 26, 2018, 4:12 p.m. UTC
Use devm_request_irq() instead of request_irq() to request the IRQ.

Signed-off-by: Moritz Fischer <mdf@kernel.org>
---

Hi Lars,

was there a specific reason not to use devm_request_irq() ?

Cheers,

Moritz

---
 drivers/dma/dma-axi-dmac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Lars-Peter Clausen April 26, 2018, 4:26 p.m. UTC | #1
On 04/26/2018 06:12 PM, Moritz Fischer wrote:
> Use devm_request_irq() instead of request_irq() to request the IRQ.
> 
> Signed-off-by: Moritz Fischer <mdf@kernel.org>
> ---
> 
> Hi Lars,
> 
> was there a specific reason not to use devm_request_irq() ?

Yes, it is wrong :)

This reorders the sequence in the remove() function. We really need to free
the IRQ at the point in the sequence where it is at the moment. We need to
call tasklet_kill() after the free_irq() function has been called, otherwise
the tasklet can be re-scheduled and we might end up with a use after free.

But also if we disable the clock to the core before the IRQ is freed we
might end up trying to access the register map while the clock is off and
then never get a response and block the AXI bus.

This is all very very unlikely to ever happen, but still I'd like to have
correct code.

> 
> Cheers,
> 
> Moritz
> 
> ---
>  drivers/dma/dma-axi-dmac.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
> index 2419fe524daa..75ccedaa96d2 100644
> --- a/drivers/dma/dma-axi-dmac.c
> +++ b/drivers/dma/dma-axi-dmac.c
> @@ -687,8 +687,9 @@ static int axi_dmac_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto err_unregister_device;
>  
> -	ret = request_irq(dmac->irq, axi_dmac_interrupt_handler, 0,
> -		dev_name(&pdev->dev), dmac);
> +	ret = devm_request_irq(&pdev->dev, dmac->irq,
> +			       axi_dmac_interrupt_handler, 0,
> +			       dev_name(&pdev->dev), dmac);
>  	if (ret)
>  		goto err_unregister_of;
>  
> @@ -711,7 +712,6 @@ static int axi_dmac_remove(struct platform_device *pdev)
>  	struct axi_dmac *dmac = platform_get_drvdata(pdev);
>  
>  	of_dma_controller_free(pdev->dev.of_node);
> -	free_irq(dmac->irq, dmac);
>  	tasklet_kill(&dmac->chan.vchan.task);
>  	dma_async_device_unregister(&dmac->dma_dev);
>  	clk_disable_unprepare(dmac->clk);
> 

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Moritz Fischer April 26, 2018, 4:43 p.m. UTC | #2
Hi Lars,

On Thu, Apr 26, 2018 at 9:26 AM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 04/26/2018 06:12 PM, Moritz Fischer wrote:
>> Use devm_request_irq() instead of request_irq() to request the IRQ.
>>
>> Signed-off-by: Moritz Fischer <mdf@kernel.org>
>> ---
>>
>> Hi Lars,
>>
>> was there a specific reason not to use devm_request_irq() ?
>
> Yes, it is wrong :)
>
> This reorders the sequence in the remove() function. We really need to free
> the IRQ at the point in the sequence where it is at the moment. We need to
> call tasklet_kill() after the free_irq() function has been called, otherwise
> the tasklet can be re-scheduled and we might end up with a use after free.
>
> But also if we disable the clock to the core before the IRQ is freed we
> might end up trying to access the register map while the clock is off and
> then never get a response and block the AXI bus.
>
> This is all very very unlikely to ever happen, but still I'd like to have
> correct code.

Thanks for the explanation. I'll drop this and resubmit [2/2] without
this change.

- Moritz
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
index 2419fe524daa..75ccedaa96d2 100644
--- a/drivers/dma/dma-axi-dmac.c
+++ b/drivers/dma/dma-axi-dmac.c
@@ -687,8 +687,9 @@  static int axi_dmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_unregister_device;
 
-	ret = request_irq(dmac->irq, axi_dmac_interrupt_handler, 0,
-		dev_name(&pdev->dev), dmac);
+	ret = devm_request_irq(&pdev->dev, dmac->irq,
+			       axi_dmac_interrupt_handler, 0,
+			       dev_name(&pdev->dev), dmac);
 	if (ret)
 		goto err_unregister_of;
 
@@ -711,7 +712,6 @@  static int axi_dmac_remove(struct platform_device *pdev)
 	struct axi_dmac *dmac = platform_get_drvdata(pdev);
 
 	of_dma_controller_free(pdev->dev.of_node);
-	free_irq(dmac->irq, dmac);
 	tasklet_kill(&dmac->chan.vchan.task);
 	dma_async_device_unregister(&dmac->dma_dev);
 	clk_disable_unprepare(dmac->clk);