From: Christopher N. Hesse Date: Sat, 24 Mar 2018 09:18:36 +0000 (+0100) Subject: a7xelte: amplifier: Fix deadlock X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f138460da98fc421bfcf066351b66ca839a44f38;p=GitHub%2FLineageOS%2Fandroid_device_samsung_a7xelte.git a7xelte: amplifier: Fix deadlock If pcm_open() fails with -EBUSY, t->cond is never signaled and tfa_clock_on() stalls the driver in its while (!tfa_dev->writing) loop where it waits for the signal to be delivered. Avoid this by always signaling the calling thread. Change-Id: I4fd81080e77d5f37963714a5d6b4556c387f5a33 (cherry picked from commit 07b6fbed54c84e8e83f4e3f6ceb89fef81038536) --- diff --git a/amplifier/tfa.c b/amplifier/tfa.c index 858c820..b56e199 100644 --- a/amplifier/tfa.c +++ b/amplifier/tfa.c @@ -35,6 +35,8 @@ static void * write_dummy_data(void *param) { uint8_t *buffer; int size; struct pcm *pcm; + bool signaled = false; + struct pcm_config config = { .channels = 2, .rate = 48000, @@ -63,7 +65,6 @@ static void * write_dummy_data(void *param) { goto err_close_pcm; } - bool signaled = false; do { if (pcm_write(pcm, buffer, size)) { ALOGE("%s: pcm_write failed", __func__); @@ -84,6 +85,13 @@ err_free: err_close_pcm: pcm_close(pcm); exit: + if (!signaled) { + pthread_mutex_lock(&t->mutex); + t->writing = true; + pthread_cond_signal(&t->cond); + pthread_mutex_unlock(&t->mutex); + } + return NULL; }