2022-05-10 08:10:27

by Radhey Shyam Pandey

[permalink] [raw]
Subject: [PATCH 0/3] dmaengine: zynqmp_dma: coverity fixes

This patchset addresses coverity issues reported on zynqmp dma driver.


Radhey Shyam Pandey (2):
dmaengine: zynqmp_dma: In struct zynqmp_dma_chan fix desc_size data
type
dmaengine: zynqmp_dma: use pm_runtime_resume_and_get() instead of
pm_runtime_get_sync()

Shravya Kumbham (1):
dmaengine: zynqmp_dma: check dma_async_device_register return value

drivers/dma/xilinx/zynqmp_dma.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

--
2.25.1



2022-05-10 09:53:34

by Radhey Shyam Pandey

[permalink] [raw]
Subject: [PATCH 2/3] dmaengine: zynqmp_dma: check dma_async_device_register return value

From: Shravya Kumbham <[email protected]>

Add condition to check the return value of dma_async_device_register
and implement its error handling.

Addresses-Coverity: Event check_return.
Signed-off-by: Shravya Kumbham <[email protected]>
Signed-off-by: Harini Katakam <[email protected]>
Signed-off-by: Radhey Shyam Pandey <[email protected]>
---
drivers/dma/xilinx/zynqmp_dma.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
index 3ffa7f37c701..915dbe6275d4 100644
--- a/drivers/dma/xilinx/zynqmp_dma.c
+++ b/drivers/dma/xilinx/zynqmp_dma.c
@@ -1094,7 +1094,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.25.1


2022-05-10 11:08:09

by Radhey Shyam Pandey

[permalink] [raw]
Subject: [PATCH 3/3] dmaengine: zynqmp_dma: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()

pm_runtime_resume_and_get() automatically handle dev->power.usage_count
decrement on errors, so prefer using it and also implement it's error
handling.

Signed-off-by: Radhey Shyam Pandey <[email protected]>
---
drivers/dma/xilinx/zynqmp_dma.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
index 915dbe6275d4..dc299ab36818 100644
--- a/drivers/dma/xilinx/zynqmp_dma.c
+++ b/drivers/dma/xilinx/zynqmp_dma.c
@@ -1078,7 +1078,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_resume_and_get(zdev->dev);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "device wakeup failed.\n");
+ pm_runtime_disable(zdev->dev);
+ }
if (!pm_runtime_enabled(zdev->dev)) {
ret = zynqmp_dma_runtime_resume(zdev->dev);
if (ret)
--
2.25.1


2022-05-10 13:46:35

by Radhey Shyam Pandey

[permalink] [raw]
Subject: [PATCH 1/3] dmaengine: zynqmp_dma: In struct zynqmp_dma_chan fix desc_size data type

In zynqmp_dma_alloc/free_chan_resources functions there is a
potential overflow in the below expressions.

dma_alloc_coherent(chan->dev, (2 * chan->desc_size *
ZYNQMP_DMA_NUM_DESCS),
&chan->desc_pool_p, GFP_KERNEL);

dma_free_coherent(chan->dev,(2 * ZYNQMP_DMA_DESC_SIZE(chan) *
ZYNQMP_DMA_NUM_DESCS),
chan->desc_pool_v, chan->desc_pool_p);

The arguments desc_size and ZYNQMP_DMA_NUM_DESCS were 32 bit. Though
this overflow condition is not observed but it is a potential problem
in the case of 32-bit multiplication. Hence fix it by changing the
desc_size data type to size_t.

In addition to coverity fix it also reuse ZYNQMP_DMA_DESC_SIZE macro in
dma_alloc_coherent API argument.

Addresses-Coverity: Event overflow_before_widen.
Signed-off-by: Radhey Shyam Pandey <[email protected]>
---
drivers/dma/xilinx/zynqmp_dma.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
index 7aa63b652027..3ffa7f37c701 100644
--- a/drivers/dma/xilinx/zynqmp_dma.c
+++ b/drivers/dma/xilinx/zynqmp_dma.c
@@ -229,7 +229,7 @@ struct zynqmp_dma_chan {
bool is_dmacoherent;
struct tasklet_struct tasklet;
bool idle;
- u32 desc_size;
+ size_t desc_size;
bool err;
u32 bus_width;
u32 src_burst_len;
@@ -486,7 +486,8 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan)
}

chan->desc_pool_v = dma_alloc_coherent(chan->dev,
- (2 * chan->desc_size * ZYNQMP_DMA_NUM_DESCS),
+ (2 * ZYNQMP_DMA_DESC_SIZE(chan) *
+ ZYNQMP_DMA_NUM_DESCS),
&chan->desc_pool_p, GFP_KERNEL);
if (!chan->desc_pool_v)
return -ENOMEM;
--
2.25.1


2022-05-17 01:29:46

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/3] dmaengine: zynqmp_dma: coverity fixes

On 10-05-22, 12:42, Radhey Shyam Pandey wrote:
> This patchset addresses coverity issues reported on zynqmp dma driver.
>

Applied, thanks

--
~Vinod