Skip to content

drm/apple: audio: free the test PCM preallocation with an exported call - #4001

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/dcpaud-legacy-test-prealloc-free
Dec 2, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/dcpaud-legacy-test-prealloc-free

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: aurora_defconfig builds of main fail at modpost since #3410: the apple-dcpaud-legacy KUnit test calls snd_pcm_lib_preallocate_free(), which ALSA does not export. Free the test substream's preallocated buffer with the exported snd_dma_free_pages() instead. Thanks to Joshua Warren for the report.

Tested: no runtime change (one KUnit test file). At 917359aa6398 (on main 2a6502ffdfd5):

  • aurora_defconfig, make Image modules: main f4b229b300bb fails, this head passes modpost over every module.
  • W=1 on audio.o: 0 warnings. checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.
  • arm64 kunit.py build (display.kunitconfig plus sound): builds and links all three dcpaud suites. Built, not run.

Risk: two-way door · none. Test code only; it is compiled into appledrm.ko only with DRM_APPLE_DISPLAY_KUNIT_TEST.

Not yet: the apple-dcpaud-legacy cases were not executed at this head. Hosted KUnit does not cover them either: display.kunitconfig has no CONFIG_SND, so audio.c is not built there. No hardware row is needed.

Details
  • aurora_defconfig has DRM_APPLE=m, SND=m, KUNIT=m and KUNIT_ALL_TESTS=m, so the bool DRM_APPLE_DISPLAY_KUNIT_TEST is y and audio.c includes audio-legacy-test.c into appledrm.ko. Configs with SND=y and DRM_APPLE=y link the symbol directly, which is why earlier KUnit runs passed.
  • snd_pcm_lib_preallocate_free_for_all(sub->pcm) is exported and fixes the link, but it frees nothing here: it walks pcm->streams[], and the tests' PCM is a zeroed struct with no substream on that list. The 1 MiB buffer would leak on each run of two of the three cases.
  • snd_dma_free_pages(&sub->dma_buffer) is the call snd_pcm_lib_preallocate_free() ends in, and audio.c already uses it for the void buffer. The area check matches do_free_pages(), so the case that preallocates nothing (unplugged_hotplug_managed_buffer) is skipped. The steps left out are the card's total_pcm_alloc_bytes decrement and clearing dma_buffer.area, on a test card and substream that KUnit frees right after.
  • The call came in with f39fdeec3e43; 9f33c3f95939 added a third user of the cleanup action.
Evidence

Incremental builds in a warm O= directory, clang 23.1.3, ARCH=arm64 LLVM=1; .config byte-identical to a fresh aurora_defconfig for both builds.

tree command result
main f4b229b300bb make aurora_defconfig olddefconfig; make -j20 Image modules rc 2, ERROR: modpost: drivers/gpu/drm/apple/appledrm.ko: symbol 'snd_pcm_lib_preallocate_free' undefined! (the only modpost error)
917359aa6398 same rc 0, no modpost error; 4 missing MODULE_DESCRIPTION() warnings in other modules, same as on main
917359aa6398 make W=1 drivers/gpu/drm/apple/audio.o rc 0, 0 warnings (audio.c includes the test; DRM_WERROR=y)
917359aa6398 scripts/checkpatch.pl --strict -g HEAD 0 errors, 0 warnings, 0 checks
917359aa6398 kunit.py build --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/gpu/drm/apple/tests/display.kunitconfig --kconfig_add CONFIG_{SOUND,SND,DRM_APPLE_AUDIO,DMADEVICES,DRM_APPLE_DCP_T6030_AUDIO}=y --kconfig_add CONFIG_WERROR=n rc 0; dcpaud_legacy_suite, dcpaud_link_suite, dcpaud_no_sio_suite in vmlinux

llvm-nm -u appledrm.ko at this head lists snd_dma_free_pages and no preallocate symbol. Module.symvers has snd_dma_free_pages from sound/core/snd-pcm.

The apple-dcpaud-legacy KUnit cases release the substream's preallocated
buffer with snd_pcm_lib_preallocate_free(), which ALSA does not export.
aurora_defconfig builds DRM_APPLE, SND and KUNIT as modules with
KUNIT_ALL_TESTS, so DRM_APPLE_DISPLAY_KUNIT_TEST is on, audio.c
includes the test into appledrm.ko, and modpost rejects the module with
snd_pcm_lib_preallocate_free undefined.

The exported snd_pcm_lib_preallocate_free_for_all() is no stand-in: it
walks pcm->streams[], and the tests' PCM is a zeroed struct with no
substream on that list, so it would free nothing and leak the 1 MiB
buffer.

Free the substream's dma_buffer with snd_dma_free_pages() instead. It
is the exported call snd_pcm_lib_preallocate_free() ends in, and the
one audio.c already uses for its void buffer. The steps left out are
the card's total_pcm_alloc_bytes decrement and clearing
dma_buffer.area, on a test card and substream that KUnit frees right
after.

Fixes: f39fdee ("drm/apple: defer unplugged DP audio DMA and pin idle-off external DCP")
Reported-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Closes: #3410 (comment)
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 2, 2026 22:10
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) blast:none Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Merge readiness at 917359aa: not ready yet

Check Detail
CI at head running running: apple-build, host-tests, pr-text / pr-text, KUnit plan
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok not needed: no runtime change
Conflicts ok none
PR text ok Risk: two-way · none. Test code only; it is compiled into appledrm.ko only with DRMAPPLEDISPLAYKUNITTEST.

Areas: area:display

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Local checks at 917359aa6398634676a7e7e8c506077085a0dad6, in place of the queued hosted CI:

  • make aurora_defconfig olddefconfig; make -j20 Image modules (arm64, LLVM=1, incremental): rc 0, no modpost error. The same commands on main f4b229b300bb fail with symbol 'snd_pcm_lib_preallocate_free' undefined! in appledrm.ko.
  • make W=1 drivers/gpu/drm/apple/audio.o: rc 0, 0 warnings.
  • scripts/checkpatch.pl --strict -g HEAD: 0 errors, 0 warnings, 0 checks.
  • kunit.py build --arch=arm64 with display.kunitconfig plus sound: rc 0, the three dcpaud suites link. They were built, not run.
  • tools/asahi/run-host-tests.py --only dcpaud: 22/22. --only hardware-defaults and --only t6030-display-linkage: 1/1 each. The rest of host-tests was not run.

main has moved to 110d84f8ec93 since this head's base; nothing in that range touches the changed file or ALSA.

Independent review of this diff: no code findings. Its note on the commit message (name both skipped steps) is in this head. There is no GitHub approval; merging with the maintainer bypass because this fixes the main build.

@DjDeveloperr
DjDeveloperr merged commit 10f52ab into main Dec 2, 2026
8 of 11 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/dcpaud-legacy-test-prealloc-free branch December 2, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) blast:none Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant