-
Notifications
You must be signed in to change notification settings - Fork 361
dma: fix error-path and bounds issues in dw/sdma/acp drivers #10932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -532,8 +532,6 @@ static int dw_dma_set_config(struct dma_chan_data *channel, | |
| /* do we need to realloc descriptors */ | ||
| if (config->elem_array.count != channel->desc_count) { | ||
|
|
||
| channel->desc_count = config->elem_array.count; | ||
|
|
||
| /* | ||
| * Allocate descriptors for channel. They must be cache-line | ||
| * size aligned to avoid corrupting adjacent memory when | ||
|
|
@@ -542,18 +540,25 @@ static int dw_dma_set_config(struct dma_chan_data *channel, | |
| * allocations on Zephyr to always force cache-line size | ||
| * alignment. | ||
| */ | ||
| if (dw_chan->lli) | ||
| rfree(dw_chan->lli); | ||
| rfree(dw_chan->lli); | ||
|
|
||
| dw_chan->lli = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA, | ||
| sizeof(struct dw_lli) * channel->desc_count); | ||
| sizeof(struct dw_lli) * config->elem_array.count); | ||
| if (!dw_chan->lli) { | ||
| tr_err(&dwdma_tr, "dma %d channel %d lli alloc failed", | ||
| channel->dma->plat_data.id, | ||
| channel->index); | ||
| /* allocation failed, so dw_chan->lli is now NULL; reset | ||
| * the count to match it so a later config does not | ||
| * bzero() a NULL pointer using a stale count | ||
| */ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather say, that the point is not that it was freed above, but that the allocation has failed and it's now
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reworded — the comment now says the allocation failed so |
||
| channel->desc_count = 0; | ||
| ret = -ENOMEM; | ||
| goto out; | ||
| } | ||
|
|
||
| /* only commit the new count once the buffer is allocated */ | ||
| channel->desc_count = config->elem_array.count; | ||
| } | ||
|
|
||
| /* initialise descriptors */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, the
ifin line 543 / 545 above is redundantThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point — dropped the redundant
if (dw_chan->lli)guard;rfree(NULL)is a no-op (zephyr returns early on NULL, the library build callsfree()), so the unconditionalrfree(dw_chan->lli)is fine.