ALSA: emux: Fix mutex deadlock in OSS emulation
authorTakashi Iwai <tiwai@suse.de>
Tue, 28 Apr 2015 15:11:44 +0000 (17:11 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 6 Aug 2015 23:32:08 +0000 (00:32 +0100)
commitf696aa6f0c43ba1c180b28e4e895ef005092d331
tree6a972c8a4fc0aac69c22d49fc36f817231418477
parent7bb3b886cd0c9968d870e064a9ec0eb6cce424e3
ALSA: emux: Fix mutex deadlock in OSS emulation

commit 1c94e65c668f44d2c69ae7e7fc268ab3268fba3e upstream.

The OSS emulation in synth-emux helper has a potential AB/BA deadlock
at the simultaneous closing and opening:

  close ->
    snd_seq_release() ->
      sne_seq_free_client() ->
        snd_seq_delete_all_ports(): takes client->ports_mutex ->
  port_delete() ->
    snd_emux_unuse(): takes emux->register_mutex

  open ->
    snd_seq_oss_open() ->
      snd_emux_open_seq_oss(): takes emux->register_mutex ->
        snd_seq_event_port_attach() ->
  snd_seq_create_port(): takes client->ports_mutex

This patch addresses the deadlock by reducing the rance taking
emux->register_mutex in snd_emux_open_seq_oss().  The lock is needed
for the refcount handling, so move it locally.  The calls in
emux_seq.c are already with the mutex, thus they are replaced with the
version without mutex lock/unlock.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
sound/synth/emux/emux_oss.c
sound/synth/emux/emux_seq.c