Skip to contentSkip to conversation

dmaengine: stm32-dma3: Set lli_size after allocation

PATCH Applied Kees Cook 3 participants 3 messages Jul 16, 2024 – Aug 5, 2024

Subsystems (3)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 dmaengine: stm32-dma3: Set lli_size after allocation

With the new __counted_by annotation, the "lli_size" variable needs to valid for accesses to the "lli" array. This requirement is not met in stm32_dma3_chan_desc_alloc(), since "lli_size" starts at "0", so "lli" index "0" will not be considered valid during the initialization for loop.

Fix this by setting lli_size immediately after allocation (similar to how this is handled in stm32_mdma_alloc_desc() for the node/count relationship).

Fixes f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support")

---
Cc: "Amélie Delaunay" <[email protected]>
Cc: Vinod Koul <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/dma/stm32/stm32-dma3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/stm32/stm32-dma3.c +1 -1
index 4087e0263a48..0be6e944df6f 100644
@@ -403,6 +403,7 @@ static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_ch
 	swdesc = kzalloc(struct_size(swdesc, lli, count), GFP_NOWAIT);
 	if (!swdesc)
 		return NULL;
+	swdesc->lli_size = count;
 
 	for (i = 0; i < count; i++) {
 		swdesc->lli[i].hwdesc = dma_pool_zalloc(chan->lli_pool, GFP_NOWAIT,
@@ -410,7 +411,6 @@ static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_ch
 		if (!swdesc->lli[i].hwdesc)
 			goto err_pool_free;
 	}
-	swdesc->lli_size = count;
 	swdesc->ccr = 0;
 
 	/* Set LL base address */
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Kees Cook

With the new __counted_by annotation, the "lli_size" variable needs to valid for accesses to the "lli" array. This requirement is not met in stm32_dma3_chan_desc_alloc(), since "lli_size" starts at "0", so "lli" index "0" will not be considered valid during the initialization for loop.

Fix this by setting lli_size immediately after allocation (similar to how this is handled in stm32_mdma_alloc_desc() for the node/count relationship).

Fixes f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support")

Thanks

Signature · 1 line
Gustavo
Quoted 32 lines

---
Cc: "Amélie Delaunay" <[email protected]>
Cc: Vinod Koul <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
  drivers/dma/stm32/stm32-dma3.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/stm32/stm32-dma3.c +1 -1
index 4087e0263a48..0be6e944df6f 100644
@@ -403,6 +403,7 @@ static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_ch
  	swdesc = kzalloc(struct_size(swdesc, lli, count), GFP_NOWAIT);
  	if (!swdesc)
  		return NULL;
+	swdesc->lli_size = count;
 
  	for (i = 0; i < count; i++) {
  		swdesc->lli[i].hwdesc = dma_pool_zalloc(chan->lli_pool, GFP_NOWAIT,
@@ -410,7 +411,6 @@ static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_ch
  		if (!swdesc->lli[i].hwdesc)
  			goto err_pool_free;
  	}
-	swdesc->lli_size = count;
  	swdesc->ccr = 0;
 
  	/* Set LL base address */
maintainer Applied
#2 lore raw
In reply to Kees Cook
Quoted 10 lines · Kees Cook

With the new __counted_by annotation, the "lli_size" variable needs to valid for accesses to the "lli" array. This requirement is not met in stm32_dma3_chan_desc_alloc(), since "lli_size" starts at "0", so "lli" index "0" will not be considered valid during the initialization for loop.

Fix this by setting lli_size immediately after allocation (similar to how this is handled in stm32_mdma_alloc_desc() for the node/count relationship).

[...]

Applied, thanks!

[1/1] dmaengine: stm32-dma3: Set lli_size after allocation

      commit: b53b831919a0dc4e6631ebe0497ab2a4d8bef014

Best regards,

Signature · 1 line
Vinod Koul <[email protected]>