[PATCH] dmaengine: ti: omap-dma: Initialize sglen after allocation

Kees Cook posted 1 patch 1 year, 5 months ago
drivers/dma/ti/omap-dma.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] dmaengine: ti: omap-dma: Initialize sglen after allocation
Posted by Kees Cook 1 year, 5 months ago
With the new __counted_by annocation, the "sglen" struct member must
be set before accessing the "sg" array. This initialization was done in
other places where a new struct omap_desc is allocated, but these cases
were missed. Set "sglen" after allocation.

Fixes: b85178611c11 ("dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by")
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
---
 drivers/dma/ti/omap-dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c
index 7e6c04afbe89..6ab9bfbdc480 100644
--- a/drivers/dma/ti/omap-dma.c
+++ b/drivers/dma/ti/omap-dma.c
@@ -1186,10 +1186,10 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic(
 	d->dev_addr = dev_addr;
 	d->fi = burst;
 	d->es = es;
+	d->sglen = 1;
 	d->sg[0].addr = buf_addr;
 	d->sg[0].en = period_len / es_bytes[es];
 	d->sg[0].fn = buf_len / period_len;
-	d->sglen = 1;
 
 	d->ccr = c->ccr;
 	if (dir == DMA_DEV_TO_MEM)
@@ -1258,10 +1258,10 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_memcpy(
 	d->dev_addr = src;
 	d->fi = 0;
 	d->es = data_type;
+	d->sglen = 1;
 	d->sg[0].en = len / BIT(data_type);
 	d->sg[0].fn = 1;
 	d->sg[0].addr = dest;
-	d->sglen = 1;
 	d->ccr = c->ccr;
 	d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_POSTINC;
 
@@ -1309,6 +1309,7 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_interleaved(
 	if (data_type > CSDP_DATA_TYPE_32)
 		data_type = CSDP_DATA_TYPE_32;
 
+	d->sglen = 1;
 	sg = &d->sg[0];
 	d->dir = DMA_MEM_TO_MEM;
 	d->dev_addr = xt->src_start;
@@ -1316,7 +1317,6 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_interleaved(
 	sg->en = xt->sgl[0].size / BIT(data_type);
 	sg->fn = xt->numf;
 	sg->addr = xt->dst_start;
-	d->sglen = 1;
 	d->ccr = c->ccr;
 
 	src_icg = dmaengine_get_src_icg(xt, &xt->sgl[0]);
-- 
2.34.1
Re: [PATCH] dmaengine: ti: omap-dma: Initialize sglen after allocation
Posted by Vinod Koul 1 year, 4 months ago
On Tue, 16 Jul 2024 14:57:06 -0700, Kees Cook wrote:
> With the new __counted_by annocation, the "sglen" struct member must
> be set before accessing the "sg" array. This initialization was done in
> other places where a new struct omap_desc is allocated, but these cases
> were missed. Set "sglen" after allocation.
> 
> 

Applied, thanks!

[1/1] dmaengine: ti: omap-dma: Initialize sglen after allocation
      commit: 5e5c793c7fc47219998465361d94510fdf55d83f

Best regards,
-- 
Vinod Koul <vkoul@kernel.org>
Re: [PATCH] dmaengine: ti: omap-dma: Initialize sglen after allocation
Posted by Gustavo A. R. Silva 1 year, 5 months ago

On 16/07/24 15:57, Kees Cook wrote:
> With the new __counted_by annocation, the "sglen" struct member must
> be set before accessing the "sg" array. This initialization was done in
> other places where a new struct omap_desc is allocated, but these cases
> were missed. Set "sglen" after allocation.
> 
> Fixes: b85178611c11 ("dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by")
> Signed-off-by: Kees Cook <kees@kernel.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
> Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: dmaengine@vger.kernel.org
> ---
>   drivers/dma/ti/omap-dma.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c
> index 7e6c04afbe89..6ab9bfbdc480 100644
> --- a/drivers/dma/ti/omap-dma.c
> +++ b/drivers/dma/ti/omap-dma.c
> @@ -1186,10 +1186,10 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic(
>   	d->dev_addr = dev_addr;
>   	d->fi = burst;
>   	d->es = es;
> +	d->sglen = 1;
>   	d->sg[0].addr = buf_addr;
>   	d->sg[0].en = period_len / es_bytes[es];
>   	d->sg[0].fn = buf_len / period_len;
> -	d->sglen = 1;
>   
>   	d->ccr = c->ccr;
>   	if (dir == DMA_DEV_TO_MEM)
> @@ -1258,10 +1258,10 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_memcpy(
>   	d->dev_addr = src;
>   	d->fi = 0;
>   	d->es = data_type;
> +	d->sglen = 1;
>   	d->sg[0].en = len / BIT(data_type);
>   	d->sg[0].fn = 1;
>   	d->sg[0].addr = dest;
> -	d->sglen = 1;
>   	d->ccr = c->ccr;
>   	d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_POSTINC;
>   
> @@ -1309,6 +1309,7 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_interleaved(
>   	if (data_type > CSDP_DATA_TYPE_32)
>   		data_type = CSDP_DATA_TYPE_32;
>   
> +	d->sglen = 1;
>   	sg = &d->sg[0];
>   	d->dir = DMA_MEM_TO_MEM;
>   	d->dev_addr = xt->src_start;
> @@ -1316,7 +1317,6 @@ static struct dma_async_tx_descriptor *omap_dma_prep_dma_interleaved(
>   	sg->en = xt->sgl[0].size / BIT(data_type);
>   	sg->fn = xt->numf;
>   	sg->addr = xt->dst_start;
> -	d->sglen = 1;
>   	d->ccr = c->ccr;
>   
>   	src_icg = dmaengine_get_src_icg(xt, &xt->sgl[0]);