Skip to content

fix(i2s): stop DMA before freeing clockless frame - #5484

Merged
zackees merged 1 commit into
masterfrom
fix/i2s-clockless-stop-before-free
Nov 25, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/i2s-clockless-stop-before-free

Conversation

@zackees

@zackees zackees commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #5356.

On classic ESP32, clockless I2S DMA descriptors point directly at the engine's scratch buffer. If the teardown wait expires, stop the peripheral and unregister the callback before releasing channels or freeing that buffer.

The host regression reproduces a free while the peripheral still reports busy. It passes under ASan/UBSan after the fix and confirms cleanup releases the channel and buffer. Changed-file lint passed. Full host C++ and hosted ESP32 checks are running.

Summary by CodeRabbit

  • Bug Fixes
    • Improved audio reliability when an engine is shut down during an active transmission. The peripheral is now properly deinitialized, and channel resources are released without leaving buffers outstanding or the channel marked as in use.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review.

Walkthrough

The I2S engine destructor now waits for transmission activity, deinitializes an initialized peripheral, and unregisters its transmit callback before releasing channel marks and the scratch buffer. A unit test checks buffer release when the engine is destroyed during transmission.

Changes: I2S teardown

Layer / File(s) Summary
Order teardown and verify buffer release
src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp, tests/unit/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
The destructor deinitializes the peripheral and unregisters the transmit callback before releasing channel marks and the scratch buffer. The test helper can check that the mock is idle before freeing a buffer, and a new test checks teardown during active transmission.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#5482 — Both changes address scratch-buffer lifetime while DMA may still be active; this PR handles teardown, while #5482 handles a wait timeout.
Merge Risk: Minimal · up to bbaf9

This change reorders I2S engine teardown so DMA is stopped before the scratch buffer is freed, which prevents use-after-free on classic ESP32. No actionable merge-blocking risk was found. The one CI failure is an infrastructure error in project automation and does not reflect the code.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(i2s): stop DMA before freeing clockless frame" matches the main change. The changeset reorders teardown in ChannelEngineI2sEsp32Dev so the peripheral is deinitialized and the transmit c…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(i2s): stop DMA before freeing clockless frame" matches the main change. The changeset reorders teardown in ChannelEngineI2sEsp32Dev so the peripheral is deinitialized and the transmit callback is unregistered before channel marks and the scratch buffer are released. The added test covers destroying the engine during an active transmission, and the PR objectives describe stopping the peripheral before freeing the buffer. The title is specific and uses the conventional commit format.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e8f141f and bbaf9c5.

Files selected for processing: 2

  • src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
  • tests/unit/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@zackees
zackees added this pull request to the merge queue Nov 25, 2026
Merged via the queue into master with commit e2e11c3 Nov 25, 2026
136 of 139 checks passed
@zackees
zackees deleted the fix/i2s-clockless-stop-before-free branch November 25, 2026 16: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.

1 participant