Skip to contentSkip to conversation

dma: bcm6348: incorrect buffer allocation

PATCH New Heinrich Schuchardt 3 participants 4 messages Dec 27, 2020 – Jan 19, 2021 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma: bcm6348: incorrect buffer allocation

Calling calloc() for 0 members does not make any sense. Setting ch_priv->busy_desc = NULL for ch_priv->desc_cnt > 0 is equally unreasonable.

The current code will lead to a NULL dereference in bcm6348_iudma_enable().

The assignments for ch_priv->busy_desc are obviously swapped.

---
I have no device to actually test the driver.

---
 drivers/dma/bcm6348-iudma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/bcm6348-iudma.c +2 -2
index 91172d483c..81597c56a7 100644
@@ -313,10 +313,10 @@ static int bcm6348_iudma_request(struct dma *dma)
 	ch_priv->desc_id = 0;
 	if (bcm6348_iudma_chan_is_rx(dma->id)) {
 		ch_priv->desc_cnt = 0;
-		ch_priv->busy_desc = calloc(ch_priv->desc_cnt, sizeof(bool));
+		ch_priv->busy_desc = NULL;
 	} else {
 		ch_priv->desc_cnt = ch_priv->dma_ring_size;
-		ch_priv->busy_desc = NULL;
+		ch_priv->busy_desc = calloc(ch_priv->desc_cnt, sizeof(bool));
 	}
 
 	return 0;

--
2.29.2

#1 lore raw

PATCH 1/1 dma: bcm6348: incorrect buffer allocation

Hello Heinrich,

This is not swapped.
busy_desc is only used in RX. Please, check the rest of the driver:
https://github.com/u-boot/u-boot/blob/master/drivers/dma/bcm6348-iudma.c

Regards,
?lvaro.

El 27/12/2020 a las 10:26, Heinrich Schuchardt escribi?:

Quoted 35 lines

Calling calloc() for 0 members does not make any sense. Setting ch_priv->busy_desc = NULL for ch_priv->desc_cnt > 0 is equally unreasonable.

The current code will lead to a NULL dereference in bcm6348_iudma_enable().

The assignments for ch_priv->busy_desc are obviously swapped.

---
I have no device to actually test the driver.

---
  drivers/dma/bcm6348-iudma.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/bcm6348-iudma.c +2 -3
index 91172d483c..81597c56a7 100644
@@ -313,10 +313,10 @@ static int bcm6348_iudma_request(struct dma *dma)
  	ch_priv->desc_id = 0;
  	if (bcm6348_iudma_chan_is_rx(dma->id)) {
  		ch_priv->desc_cnt = 0;
-		ch_priv->busy_desc = calloc(ch_priv->desc_cnt, sizeof(bool));
+		ch_priv->busy_desc = NULL;
  	} else {
  		ch_priv->desc_cnt = ch_priv->dma_ring_size;
-		ch_priv->busy_desc = NULL;
+		ch_priv->busy_desc = calloc(ch_priv->desc_cnt, sizeof(bool));
  	}
 
  	return 0;
--

2.29.2

#2 lore raw

PATCH 1/1 dma: bcm6348: incorrect buffer allocation

Quoted 8 lines · ?lvaro Fern?ndez Rojas

Hello Heinrich,

This is not swapped.
busy_desc is only used in RX. Please, check the rest of the driver:
https://github.com/u-boot/u-boot/blob/master/drivers/dma/bcm6348-iudma.c

Regards,
?lvaro.

Thanks for reviewing. Why is calloc called with count = 0? Couldn't we as well assign NULL?

Best regards

Heinrich

Quoted 38 lines

El 27/12/2020 a las 10:26, Heinrich Schuchardt escribi?:

Quoted 36 lines

Calling calloc() for 0 members does not make any sense. Setting ch_priv->busy_desc = NULL for ch_priv->desc_cnt > 0 is equally unreasonable.

The current code will lead to a NULL dereference in bcm6348_iudma_enable().

The assignments for ch_priv->busy_desc are obviously swapped.

---
I have no device to actually test the driver.
---
? drivers/dma/bcm6348-iudma.c | 4 ++--
? 1 file changed, 2 insertions(+), 2 deletions(-)

drivers/dma/bcm6348-iudma.c +2 -3
index 91172d483c..81597c56a7 100644
@@ -313,10 +313,10 @@ static int bcm6348_iudma_request(struct dma *dma)
 ????? ch_priv->desc_id = 0;
 ????? if (bcm6348_iudma_chan_is_rx(dma->id)) {
 ????????? ch_priv->desc_cnt = 0;
-??????? ch_priv->busy_desc = calloc(ch_priv->desc_cnt, sizeof(bool));
+??????? ch_priv->busy_desc = NULL;
 ????? } else {
 ????????? ch_priv->desc_cnt = ch_priv->dma_ring_size;
-??????? ch_priv->busy_desc = NULL;
+??????? ch_priv->busy_desc = calloc(ch_priv->desc_cnt, sizeof(bool));
 ????? }
 
 ????? return 0;
--

2.29.2

#3 lore raw

PATCH 1/1 dma: bcm6348: incorrect buffer allocation

In reply to Heinrich Schuchardt
Quoted 9 lines · Heinrich Schuchardt

Calling calloc() for 0 members does not make any sense. Setting ch_priv->busy_desc = NULL for ch_priv->desc_cnt > 0 is equally unreasonable.

The current code will lead to a NULL dereference in bcm6348_iudma_enable().

The assignments for ch_priv->busy_desc are obviously swapped.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210119/58ee34af/attachment.sig>