[alsa-devel] How ALSA handle PCM playing when the ALSA modules are removing

Takashi Sakamoto o-takashi at sakamocchi.jp
Wed Jan 23 06:22:41 CET 2019


Hi,

(I'm another Takashi.)

On 2019/01/23 14:01, Zhu, Yingjiang wrote:
>          I am doing an ALSA module test with insert module/remove module 
> loop, when playing a wave during this loop, there will be kernel oops. 

It's just a bug of your modules.

Linux kernel module is maintained by reference counter. In Linux sound
subsystem, when applications opens any character devices added by driver
module, the reference counter is incremented, then it cannot be unload
until all of character devices added by the module are released by
applications.

If you can unload your module during transmission of audio data frame,
it's apparently a bug of your module.

> Does ALSA need handle this case? Or just forbid wave playing during the 
> module load/unload?
>          If this need to be handled, module unload will wait the wave 
> play ending, or just stop the wave play at the first of the load/unload?

All of character devices for a sound card are associated to sound card
structure (struct snd_card). Kernel modules should set 'disconnected'
state to the structure in its callback for .remove invoked in
unloading/unbinding operation. Then appliations receives errors in I/O
operations to the character device. The applications are expected to
close the character device. When all of character devices are closed,
then sound card structure is going to be released.


Regards

Takashi Sakamoto


More information about the Alsa-devel mailing list