Skip to content

Conversation

@LucasTambor
Copy link
Contributor

Add GDMA support for esp32s3.
Remove suspend/resume since they are optional and do the same as start/stop.
Fix possible null pointer derreference.

@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: Xtensa Xtensa Architecture platform: ESP32 Espressif ESP32 area: DMA Direct Memory Access labels May 2, 2023
@marekmatej
Copy link

maybe put files in test/drivers/dma/*.[conf,overlay] to separate commit?

@LucasTambor LucasTambor requested a review from teburd May 4, 2023 17:40
@LucasTambor
Copy link
Contributor Author

@marekmatej done ;)

teburd
teburd previously approved these changes May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are freeing buf_temp which is allocated in the dma_esp32_config_tx_descriptor. Why cannot it be allocated for the driver lifetime?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you add trailing space

sylvioalves
sylvioalves previously approved these changes May 5, 2023
Copy link

@marekmatej marekmatej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tx_descriptor func. needs to free the buf_temp too

@LucasTambor LucasTambor dismissed stale reviews from sylvioalves and teburd via c54a1c6 May 5, 2023 12:22
@LucasTambor LucasTambor requested a review from marekmatej May 5, 2023 12:25
@LucasTambor LucasTambor requested a review from sylvioalves May 5, 2023 12:25
sylvioalves
sylvioalves previously approved these changes May 5, 2023
Copy link
Contributor

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that the heap is still being used here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we trying to allocate on behalf of callers here, if an invalid buffer for DMA is being provided this seems like a bug that should be asserted on.

I'm a little confused by the code here to malloc/free a temporary buffer when that's not the case. Is there a particular scenario esp32 expects this to occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are freeing the channel's temporary buffer every time a new descriptor needs to be created. In case the original buffer is in a valid DMA region, the k_free can handle a NULL pointer without issue and no allocation is needed. In case it is in an invalid region, we create a temporary one to handle the transactions, freeing it and reallocating according the size required by the transactions. I'm trying to deal with both scenarios here, since the original buffer location depends on the application or driver using it.

Did I answer your question? I'm not shure haha

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what I'm suggesting is this is a bug then in the driver or application that should be caught. There's an RFC for managing buffers #57602

At the moment this would be, to my best knowledge, the only DMA driver that attempts to fix the buffer you asked a copy to by allocating from the heap. I would suggest pushing that issue up the stack as this is a surprising place to have that happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! I will follow up this RFC and contribute in whatever way I can. But since it is an ongoing discussion, should we block the merge of this commit? This strategy of dealing with buffer is around for quite a while, this commit only add support for esp32s3 and small fixes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd point out that generally Zephyr is trying to follow misra, and in misra-c "dynamic allocation is not allowed" See our guidelines https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#main-rules

So I think this is something that needs to be revisited but today should be considered a programming error trying to ask DMA to work with a buffer that doesn't conform to DMA requirements.

Add GDMA support for esp32s3.
Remove suspend/resume since they are optional and do
the same as start/stop.
Fix possible null pointer derreference.

Signed-off-by: Lucas Tamborrino <[email protected]>
According to the coding guidelines "dynamic allocation is not allowed".

This commit removes handling invalid DMA capable buffers by allocating
temporary buffer in a valid memory region, considering them as errors.

Signed-off-by: Lucas Tamborrino <[email protected]>
Add esp32s3 overlays for dma tests.

Signed-off-by: Lucas Tamborrino <[email protected]>
@LucasTambor LucasTambor requested a review from teburd May 9, 2023 19:32
Copy link

@marekmatej marekmatej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@carlescufi carlescufi merged commit 9431e61 into zephyrproject-rtos:main May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Devicetree Binding PR modifies or adds a Device Tree binding area: DMA Direct Memory Access area: Xtensa Xtensa Architecture platform: ESP32 Espressif ESP32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants