All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] dma: bcm6348: incorrect buffer allocation
@ 2020-12-27  9:26 Heinrich Schuchardt
  2020-12-27 10:18 ` Álvaro Fernández Rojas
  2021-01-19 13:05 ` Tom Rini
  0 siblings, 2 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2020-12-27  9:26 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
I have no device to actually test the driver.
---
 drivers/dma/bcm6348-iudma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/bcm6348-iudma.c b/drivers/dma/bcm6348-iudma.c
index 91172d483c..81597c56a7 100644
--- a/drivers/dma/bcm6348-iudma.c
+++ b/drivers/dma/bcm6348-iudma.c
@@ -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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 1/1] dma: bcm6348: incorrect buffer allocation
  2020-12-27  9:26 [PATCH 1/1] dma: bcm6348: incorrect buffer allocation Heinrich Schuchardt
@ 2020-12-27 10:18 ` Álvaro Fernández Rojas
  2020-12-27 10:51   ` Heinrich Schuchardt
  2021-01-19 13:05 ` Tom Rini
  1 sibling, 1 reply; 4+ messages in thread
From: Álvaro Fernández Rojas @ 2020-12-27 10:18 UTC (permalink / raw)
  To: u-boot

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?:
> 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.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> I have no device to actually test the driver.
> ---
>   drivers/dma/bcm6348-iudma.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/bcm6348-iudma.c b/drivers/dma/bcm6348-iudma.c
> index 91172d483c..81597c56a7 100644
> --- a/drivers/dma/bcm6348-iudma.c
> +++ b/drivers/dma/bcm6348-iudma.c
> @@ -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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] dma: bcm6348: incorrect buffer allocation
  2020-12-27 10:18 ` Álvaro Fernández Rojas
@ 2020-12-27 10:51   ` Heinrich Schuchardt
  0 siblings, 0 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2020-12-27 10:51 UTC (permalink / raw)
  To: u-boot

On 12/27/20 11:18 AM, ?lvaro Fern?ndez Rojas wrote:
> 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

>
> El 27/12/2020 a las 10:26, Heinrich Schuchardt escribi?:
>> 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.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>> I have no device to actually test the driver.
>> ---
>> ? drivers/dma/bcm6348-iudma.c | 4 ++--
>> ? 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma/bcm6348-iudma.c b/drivers/dma/bcm6348-iudma.c
>> index 91172d483c..81597c56a7 100644
>> --- a/drivers/dma/bcm6348-iudma.c
>> +++ b/drivers/dma/bcm6348-iudma.c
>> @@ -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
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] dma: bcm6348: incorrect buffer allocation
  2020-12-27  9:26 [PATCH 1/1] dma: bcm6348: incorrect buffer allocation Heinrich Schuchardt
  2020-12-27 10:18 ` Álvaro Fernández Rojas
@ 2021-01-19 13:05 ` Tom Rini
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2021-01-19 13:05 UTC (permalink / raw)
  To: u-boot

On Sun, Dec 27, 2020 at 10:26:00AM +0100, Heinrich Schuchardt wrote:

> 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.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Applied to u-boot/master, thanks!

-- 
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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-19 13:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27  9:26 [PATCH 1/1] dma: bcm6348: incorrect buffer allocation Heinrich Schuchardt
2020-12-27 10:18 ` Álvaro Fernández Rojas
2020-12-27 10:51   ` Heinrich Schuchardt
2021-01-19 13:05 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.