pcm: direct: Protect from freeing semaphore when already in use

In the case of dshare, dsnoop, and dmix when a device is opened twice
and fails the second time, the semaphore is completely discarded. This
creates dangling semaphore data.

This patch removes the possibility for the semaphore to be destroyed during
a typical open failure by first checking if the shared memory can be destroyed
or not. If the shared memory cannot be released it means both it and the
semaphore are still in use and therefore the semaphore is just released.

Signed-off-by: Joshua Frkuska <joshua_frkuska@mentor.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Joshua Frkuska 2016-11-25 15:43:40 +05:30 committed by Takashi Iwai
parent 2ef7a53c31
commit 2dd78251ff
3 changed files with 13 additions and 9 deletions

View file

@ -1154,9 +1154,10 @@ int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_close(spcm);
if (dmix->u.dmix.shmid_sum >= 0)
shm_sum_discard(dmix);
if (dmix->shmid >= 0)
snd_pcm_direct_shm_discard(dmix);
if (snd_pcm_direct_semaphore_discard(dmix) < 0)
if ((dmix->shmid >= 0) && (snd_pcm_direct_shm_discard(dmix))) {
if (snd_pcm_direct_semaphore_discard(dmix))
snd_pcm_direct_semaphore_final(dmix, DIRECT_IPC_SEM_CLIENT);
} else
snd_pcm_direct_semaphore_up(dmix, DIRECT_IPC_SEM_CLIENT);
_err_nosem:
if (dmix) {