Skip to content

dma: fix error-path and bounds issues in dw/sdma/acp drivers#10932

Merged
lgirdwood merged 3 commits into
thesofproject:mainfrom
lgirdwood:fix-dma-drivers
Jun 18, 2026
Merged

dma: fix error-path and bounds issues in dw/sdma/acp drivers#10932
lgirdwood merged 3 commits into
thesofproject:mainfrom
lgirdwood:fix-dma-drivers

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Error-path and bounds fixes across three DMA drivers:

  • acp-dma: clear dma->chan after freeing it on a partial-probe failure, so
    a later probe retry doesn't free a dangling pointer
  • dw-dma: commit the descriptor count only after the descriptor buffer is
    successfully (re)allocated; otherwise a stale count with a NULL buffer
    leads to a later bzero(NULL, count * size)
  • sdma: fix an off-by-one in the event-id bound check (> -> >=) in both
    the enable and disable paths

Copilot AI review requested due to automatic review settings June 16, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes error-path and bounds-check issues in multiple DMA drivers to prevent dangling frees, NULL-pointer zeroing, and out-of-range event access.

Changes:

  • acp-dma: clear dma->chan after freeing on partial-probe failure to avoid double-free on retry.
  • dw-dma: only commit desc_count after successful (re)allocation; reset to 0 on alloc failure to keep count/buffer consistent.
  • sdma: correct event-id bounds checks from > to >= in both enable/disable event paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/drivers/imx/sdma.c Tightens event-id bounds checks to prevent out-of-range register access.
src/drivers/dw/dma.c Fixes descriptor count/buffer consistency on realloc failure to avoid NULL bzero.
src/drivers/amd/common/acp_dma.c Prevents probe-retry double-free by NULLing a freed channel pointer.

Comment thread src/drivers/amd/common/acp_dma.c Outdated
rfree(dma->chan);
/* clear the freed pointer so a later probe retry sees no
* channel context instead of a dangling one to free again
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

superfluous obvious comment, should not be there

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed — dropped the comment.

Comment thread src/drivers/dw/dma.c
/* lli was freed above; keep desc_count consistent with
* the now-NULL buffer so a later config does not bzero()
* a NULL pointer using a stale count
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 NULL. Maybe it wasn't freed and instead it was never allocated yet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reworded — the comment now says the allocation failed so dw_chan->lli is now NULL (it may never have been allocated), and the count is reset to match, rather than implying it was freed above.

Comment thread src/drivers/dw/dma.c

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

btw, the if in line 543 / 545 above is redundant

Copy link
Copy Markdown
Member Author

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 calls free()), so the unconditional rfree(dw_chan->lli) is fine.

lrgirdwo added 3 commits June 17, 2026 13:22
On a partial channel-init failure the channel array was freed but the
pointer was left set, so a later probe retry would free it again. Clear
the pointer after freeing.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The descriptor count was updated before the descriptor buffer was
reallocated, so on allocation failure the count was left larger than the
now-NULL buffer and a later config zeroed a NULL pointer using the stale
count. Update the count only after a successful allocation and reset it
on failure.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The event-number range check used a strict greater-than against the
event count, allowing the count value itself to index one past the
array. Use greater-or-equal, in both the enable and disable paths.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood

Copy link
Copy Markdown
Member Author

Files not tested by internal CI.

@lgirdwood lgirdwood merged commit f58d583 into thesofproject:main Jun 18, 2026
43 checks passed
@lgirdwood lgirdwood deleted the fix-dma-drivers branch June 18, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants