Skip to contentSkip to conversation

dmaengine: timb_dma: Adjustments for td_alloc_init_desc()

PATCH In review Markus Elfring 2 participants 6 messages Dec 25, 2023 – Jan 22, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover 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

#1 lore raw

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.

---
 drivers/dma/timb_dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/timb_dma.c +1 -2
index 7410025605e0..abcab0b1ad3b 100644
@@ -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

#2 lore raw

PATCH 2/3 dmaengine: timb_dma: Improve a size determination in td_alloc_init_desc()

In reply to Markus Elfring

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.

---
 drivers/dma/timb_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/timb_dma.c +1 -1
index abcab0b1ad3b..fc1f67bf9c06 100644
@@ -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

#3 lore raw

PATCH 3/3 dmaengine: timb_dma: One function call less in td_alloc_init_desc() after error detection

In reply to Markus Elfring

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.

---
 drivers/dma/timb_dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/timb_dma.c +2 -1
index fc1f67bf9c06..831c67af0237 100644
@@ -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

maintainer
#4 lore raw
In reply to Markus Elfring
Quoted 5 lines · Markus Elfring

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

Quoted 11 lines

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

Signature · 1 line
~Vinod
#5 lore raw
Quoted 4 lines
Quoted 2 lines

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

was this anaysis done by you

Mostly, yes.

Quoted 1 line

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.

Quoted 1 line

Frabkly I dont see much value in these patches,

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

Quoted 1 line

can you fix something real please

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

Regards,
Markus