2023-12-25 10:16:14

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] dmaengine: timb_dma: Adjustments for td_alloc_init_desc()

From: Markus Elfring <[email protected]>
Date: Mon, 25 Dec 2023 11:05:45 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Return directly after a failed kzalloc()
Improve a size determination
One function call less after error detection

drivers/dma/timb_dma.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

--
2.43.0



2023-12-25 10:18:51

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] dmaengine: timb_dma: Return directly after a failed kzalloc() in td_alloc_init_desc()

From: Markus Elfring <[email protected]>
Date: Mon, 25 Dec 2023 10:40:12 +0100

1. Return directly after a call of the function “kzalloc” failed
at the beginning.

2. Delete the label “out” which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/dma/timb_dma.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/dma/timb_dma.c b/drivers/dma/timb_dma.c
index 7410025605e0..abcab0b1ad3b 100644
--- a/drivers/dma/timb_dma.c
+++ b/drivers/dma/timb_dma.c
@@ -327,7 +327,7 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)

td_desc = kzalloc(sizeof(struct timb_dma_desc), GFP_KERNEL);
if (!td_desc)
- goto out;
+ return NULL;

td_desc->desc_list_len = td_chan->desc_elems * TIMB_DMA_DESC_SIZE;

@@ -352,7 +352,6 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)
err:
kfree(td_desc->desc_list);
kfree(td_desc);
-out:
return NULL;

}
--
2.43.0


2023-12-25 10:20:39

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] dmaengine: timb_dma: Improve a size determination in td_alloc_init_desc()

From: Markus Elfring <[email protected]>
Date: Mon, 25 Dec 2023 10:50:10 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/dma/timb_dma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/timb_dma.c b/drivers/dma/timb_dma.c
index abcab0b1ad3b..fc1f67bf9c06 100644
--- a/drivers/dma/timb_dma.c
+++ b/drivers/dma/timb_dma.c
@@ -325,7 +325,7 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)
struct timb_dma_desc *td_desc;
int err;

- td_desc = kzalloc(sizeof(struct timb_dma_desc), GFP_KERNEL);
+ td_desc = kzalloc(sizeof(*td_desc), GFP_KERNEL);
if (!td_desc)
return NULL;

--
2.43.0


2023-12-25 10:22:52

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] dmaengine: timb_dma: One function call less in td_alloc_init_desc() after error detection

From: Markus Elfring <[email protected]>
Date: Mon, 25 Dec 2023 10:55:52 +0100

The kfree() function was called in one case by the
td_alloc_init_desc() function during error handling
even if the passed data structure member contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus use another label.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/dma/timb_dma.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/timb_dma.c b/drivers/dma/timb_dma.c
index fc1f67bf9c06..831c67af0237 100644
--- a/drivers/dma/timb_dma.c
+++ b/drivers/dma/timb_dma.c
@@ -333,7 +333,7 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)

td_desc->desc_list = kzalloc(td_desc->desc_list_len, GFP_KERNEL);
if (!td_desc->desc_list)
- goto err;
+ goto free_td_desc;

dma_async_tx_descriptor_init(&td_desc->txd, chan);
td_desc->txd.tx_submit = td_tx_submit;
@@ -351,4 +351,5 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)
return td_desc;
err:
kfree(td_desc->desc_list);
+free_td_desc:
kfree(td_desc);
--
2.43.0


2024-01-22 11:43:46

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/3] dmaengine: timb_dma: Adjustments for td_alloc_init_desc()

On 25-12-23, 11:15, Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Mon, 25 Dec 2023 11:05:45 +0100
>
> A few update suggestions were taken into account
> from static source code analysis.

was this anaysis done by you or some tool reported this.
Frabkly I dont see much value in these patches, can you fix something
real please

>
> Markus Elfring (3):
> Return directly after a failed kzalloc()
> Improve a size determination
> One function call less after error detection
>
> drivers/dma/timb_dma.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> --
> 2.43.0

--
~Vinod

2024-01-22 12:21:53

by Markus Elfring

[permalink] [raw]
Subject: Re: [0/3] dmaengine: timb_dma: Adjustments for td_alloc_init_desc()

>> A few update suggestions were taken into account
>> from static source code analysis.
>
> was this anaysis done by you

Mostly, yes.


> or some tool reported this.

Some scripts for the semantic patch language (Coccinelle software) can help
to point places out for desirable source code transformations.


> Frabkly I dont see much value in these patches,

It is a pity that you view the presented update steps in this direction.


> can you fix something real please

You might occasionally find adjustments from my patch selection more worthwhile.

Regards,
Markus