casaroli opened a new pull request, #21910:
URL: https://github.com/apache/nuttx/pull/21910

   ## Summary
   
   Since 5a2543cec22 ("audio: stop the lower half even if it completed before 
AUDIOIOC_STOP"), the last close of an audio device calls the `shutdown()` 
method of the lower half and `kumm_free()` of the status while it holds the 
spinlock of the upper half, with the interrupts off. The `shutdown()` of most 
codec drivers (cs43l22, es8388, wm8904 and others) resets the chip over I2C, 
and an I2C transfer waits on a semaphore. `kumm_free()` can wait for the heap 
mutex. The buffer completions take the same spinlock: when a completion comes 
while the close sleeps, the interrupt handler spins on the spinlock and the 
system stops. This PR clears `upper->status` under the spinlock as before, so a 
completion after the last close is still dropped (db34bbe2ee1), and then calls 
`shutdown()` and frees the status after the spinlock is released. The mutex of 
the upper half keeps other opens and closes out.
   
   ## Impact
   
   `audio/audio.c` only, the last close only. The order is the same as before 
5a2543cec22: `shutdown()` runs without the spinlock, as it did for years. A 
completion that comes during `shutdown()` sees no status and is dropped, as a 
completion after the close was before. No API change. No Documentation change. 
The same code in flat, protected and kernel builds.
   
   ## Testing
   
   - Test program `audioclose.c`: open `/dev/audio/pcm0p`, configure 48 kHz 
stereo 16-bit, allocate and enqueue 4 buffers of 25 ms, start, and close at 
once without `AUDIOIOC_STOP` (as a player that is killed), so that the buffer 
completions come during the close. Then `sleep(1)` must take less than 1.5 s 
and the shell must answer. qemu-armv8a:nsh_smp (flat build, 2 CPUs, arm64, QEMU 
with HVF) with `CONFIG_AUDIO`, `CONFIG_DRIVERS_VIRTIO_SOUND` and a QEMU 
virtio-sound device.
   - The `shutdown()` of virtio-snd does nothing, so the test also ran with a 
local change (not in this PR) that makes `virtio_snd_shutdown()` sleep 100 ms, 
as the I2C reset of a codec does. master: the system stops in the close (no 
more output, the shell does not answer). This PR: PASS, `sleep(1)` takes 1.00 s.
   - Without that local change: master PASS, this PR PASS (no regression).
   - ostest: qemu-armv8a:knsh (kernel build) exit 0, qemu-armv8a:nsh (flat 
build) exit 0, arm64, QEMU with HVF.
   - Builds (Make, arm-none-eabi-gcc 13.2): lc823450-xgevk:krndis (protected 
build, Cortex-M3, WM8776 codec) and stm32f4discovery:audio (flat build, 
Cortex-M4, CS43L22 codec): no new warning. Not run: no board with a codec.
   - checkpatch: `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to