[alsa-devel] [PATCH v2 1/2] ALSA: add snd_card_disconnect_sync()

Takashi Sakamoto o-takashi at sakamocchi.jp
Wed Oct 11 13:22:12 CEST 2017


Hi,

On Oct 11 2017 19:16, Takashi Iwai wrote:
> In case of user unbind ALSA driver during playing back / capturing,
> each driver needs to stop and remove it correctly. One note here is
> that we can't cancel from remove function in such case, because
> unbind operation doesn't check return value from remove function.
> So, we *must* stop and remove in this case.
> 
> For this purpose, we need to sync (= wait) until the all top-level
> operations are canceled at remove function.
> For example, snd_card_free() processes the disconnection procedure at
> first, then waits for the completion. That's how the hot-unplug works
> safely. It's implemented, at least, in the top-level driver removal.
> 
> Now for the lower level driver, we need a similar strategy. Notify to
> the toplevel for hot-unplug (disconnect in ALSA), and sync with the
> stop operation, then continue the rest of its own remove procedure.
> 
> This patch adds snd_card_disconnect_sync(), and driver can use it from
> remove function.
> 
> Tested-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
> Signed-off-by: Takashi Iwai <tiwai at suse.de>
> ---
>   include/sound/core.h |  2 ++
>   sound/core/init.c    | 32 ++++++++++++++++++++++++++++++++
>   2 files changed, 34 insertions(+)

I have a question for this patch. If this patch is applied and the 
lower-level driver call this function in its .remove callback, after all 
references to an instance of snd_card by file instances corresponding to 
each of ALSA character devices are released, the lower-level driver must 
explicitly releases the last reference to the instance of snd_card. On 
ALSA SoC part, which context perform this important task? In my opinion, 
this patch easily allows leak of kobject. Do you have any safety?

At least, it's better for us to add enough comments to inform it to 
developers.


Regards

Takashi Sakamoto


More information about the Alsa-devel mailing list