• Takashi Iwai's avatar
    ALSA: add snd_card_disconnect_sync() · c44027c8
    Takashi Iwai authored
    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.
    
    Note: the "lower level" driver here refers to a middle layer driver
    (e.g. ASoC components) that can be unbound freely during operation.
    Most of legacy ALSA helper drivers don't have such a problem because
    they can't be unbound.
    
    Note#2: snd_card_disconnect_sync() merely calls snd_card_disconnect()
    and syncs with closing all pending files.  It takes only the files
    opened by user-space into account, and doesn't care about object
    refcounts.  (The latter is handled by snd_card_free() completion call,
    BTW.)  Also, the function doesn't free resources by itself.
    Tested-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
    Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
    c44027c8
init.c 26.6 KB