diff mbox series

[3/4] dmaengine: zynqmp_dma: Add conditions for return value check

Message ID 20210914082817.22311-4-harini.katakam@xilinx.com (mailing list archive)
State New, archived
Headers show
Series ZynqMP DMA fixes | expand

Commit Message

Harini Katakam Sept. 14, 2021, 8:28 a.m. UTC
From: Shravya Kumbham <shravya.kumbham@xilinx.com>

Add condition to check the return value of dma_async_device_register
and pm_runtime_get_sync functions.

Addresses-Coverity: Event check_return.
Signed-off-by: Shravya Kumbham <shravya.kumbham@xilinx.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
---
 drivers/dma/xilinx/zynqmp_dma.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Michael Tretter Sept. 23, 2021, 2:40 p.m. UTC | #1
On Tue, 14 Sep 2021 13:58:16 +0530, Harini Katakam wrote:
> From: Shravya Kumbham <shravya.kumbham@xilinx.com>
> 
> Add condition to check the return value of dma_async_device_register
> and pm_runtime_get_sync functions.
> 
> Addresses-Coverity: Event check_return.
> Signed-off-by: Shravya Kumbham <shravya.kumbham@xilinx.com>
> Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
> ---
>  drivers/dma/xilinx/zynqmp_dma.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
> index d28b9ffb4309..588460e56ab8 100644
> --- a/drivers/dma/xilinx/zynqmp_dma.c
> +++ b/drivers/dma/xilinx/zynqmp_dma.c
> @@ -1080,7 +1080,11 @@ static int zynqmp_dma_probe(struct platform_device *pdev)
>  	pm_runtime_set_autosuspend_delay(zdev->dev, ZDMA_PM_TIMEOUT);
>  	pm_runtime_use_autosuspend(zdev->dev);
>  	pm_runtime_enable(zdev->dev);
> -	pm_runtime_get_sync(zdev->dev);
> +	ret = pm_runtime_get_sync(zdev->dev);
> +	if (ret < 0) {
> +		dev_err(zdev->dev, "pm_runtime_get_sync() failed\n");
> +		pm_runtime_disable(zdev->dev);
> +	}

Thanks for the patch.

You need to call pm_runtime_put() on the error path. Or you could use
pm_runtime_resume_and_get(), which does this automatically.

I am wondering, if it wouldn't be cleaner to make this dependent on
pm_runtime_enabled() and avoiding pm_runtime_disable() on the error path
altogether.

Michael

>  	if (!pm_runtime_enabled(zdev->dev)) {
>  		ret = zynqmp_dma_runtime_resume(zdev->dev);
>  		if (ret)
> @@ -1096,7 +1100,11 @@ static int zynqmp_dma_probe(struct platform_device *pdev)
>  	p->dst_addr_widths = BIT(zdev->chan->bus_width / 8);
>  	p->src_addr_widths = BIT(zdev->chan->bus_width / 8);
>  
> -	dma_async_device_register(&zdev->common);
> +	ret = dma_async_device_register(&zdev->common);
> +	if (ret) {
> +		dev_err(zdev->dev, "failed to register the dma device\n");
> +		goto free_chan_resources;
> +	}
>  
>  	ret = of_dma_controller_register(pdev->dev.of_node,
>  					 of_zynqmp_dma_xlate, zdev);
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
Vinod Koul Oct. 25, 2021, 6:12 a.m. UTC | #2
On 14-09-21, 13:58, Harini Katakam wrote:
> From: Shravya Kumbham <shravya.kumbham@xilinx.com>
> 
> Add condition to check the return value of dma_async_device_register
> and pm_runtime_get_sync functions.
> 
> Addresses-Coverity: Event check_return.
> Signed-off-by: Shravya Kumbham <shravya.kumbham@xilinx.com>

sob missing

> Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
> ---
>  drivers/dma/xilinx/zynqmp_dma.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
> index d28b9ffb4309..588460e56ab8 100644
> --- a/drivers/dma/xilinx/zynqmp_dma.c
> +++ b/drivers/dma/xilinx/zynqmp_dma.c
> @@ -1080,7 +1080,11 @@ static int zynqmp_dma_probe(struct platform_device *pdev)
>  	pm_runtime_set_autosuspend_delay(zdev->dev, ZDMA_PM_TIMEOUT);
>  	pm_runtime_use_autosuspend(zdev->dev);
>  	pm_runtime_enable(zdev->dev);
> -	pm_runtime_get_sync(zdev->dev);
> +	ret = pm_runtime_get_sync(zdev->dev);
> +	if (ret < 0) {
> +		dev_err(zdev->dev, "pm_runtime_get_sync() failed\n");
> +		pm_runtime_disable(zdev->dev);

disable is okay but it wont fix the count, you should call put and then
disable if required

> +	}
>  	if (!pm_runtime_enabled(zdev->dev)) {
>  		ret = zynqmp_dma_runtime_resume(zdev->dev);
>  		if (ret)
> @@ -1096,7 +1100,11 @@ static int zynqmp_dma_probe(struct platform_device *pdev)
>  	p->dst_addr_widths = BIT(zdev->chan->bus_width / 8);
>  	p->src_addr_widths = BIT(zdev->chan->bus_width / 8);
>  
> -	dma_async_device_register(&zdev->common);
> +	ret = dma_async_device_register(&zdev->common);
> +	if (ret) {
> +		dev_err(zdev->dev, "failed to register the dma device\n");
> +		goto free_chan_resources;
> +	}
>  
>  	ret = of_dma_controller_register(pdev->dev.of_node,
>  					 of_zynqmp_dma_xlate, zdev);
> -- 
> 2.17.1
diff mbox series

Patch

diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
index d28b9ffb4309..588460e56ab8 100644
--- a/drivers/dma/xilinx/zynqmp_dma.c
+++ b/drivers/dma/xilinx/zynqmp_dma.c
@@ -1080,7 +1080,11 @@  static int zynqmp_dma_probe(struct platform_device *pdev)
 	pm_runtime_set_autosuspend_delay(zdev->dev, ZDMA_PM_TIMEOUT);
 	pm_runtime_use_autosuspend(zdev->dev);
 	pm_runtime_enable(zdev->dev);
-	pm_runtime_get_sync(zdev->dev);
+	ret = pm_runtime_get_sync(zdev->dev);
+	if (ret < 0) {
+		dev_err(zdev->dev, "pm_runtime_get_sync() failed\n");
+		pm_runtime_disable(zdev->dev);
+	}
 	if (!pm_runtime_enabled(zdev->dev)) {
 		ret = zynqmp_dma_runtime_resume(zdev->dev);
 		if (ret)
@@ -1096,7 +1100,11 @@  static int zynqmp_dma_probe(struct platform_device *pdev)
 	p->dst_addr_widths = BIT(zdev->chan->bus_width / 8);
 	p->src_addr_widths = BIT(zdev->chan->bus_width / 8);
 
-	dma_async_device_register(&zdev->common);
+	ret = dma_async_device_register(&zdev->common);
+	if (ret) {
+		dev_err(zdev->dev, "failed to register the dma device\n");
+		goto free_chan_resources;
+	}
 
 	ret = of_dma_controller_register(pdev->dev.of_node,
 					 of_zynqmp_dma_xlate, zdev);