Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11ba943d authored by Bhalchandra Gajare's avatar Bhalchandra Gajare
Browse files

ASoC: msm-cpe-lsm: Correct handling of stopping LAB thread



It is possible that the kthread used for LAB buffering could get stopped
even before it was scheduled. In such cases, the driver still waits for
the thread function to complete, which results into timeout and an error
sent to userspace. Fix handling of stopping LAB thread based on return
value of kthread_stop.

CRs-fixed: 866861
Change-Id: I854d4407ced4dd3b50339614872ee12a9478280f
Signed-off-by: default avatarBhalchandra Gajare <gajare@codeaurora.org>
parent 35afb780
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -343,6 +343,16 @@ static int msm_cpe_lsm_lab_stop(struct snd_pcm_substream *substream)
			__func__);
		rc = kthread_stop(session->lsm_lab_thread);

		/*
		 * kthread_stop returns EINTR if the thread_fn
		 * was not scheduled before calling kthread_stop.
		 * In this case, we dont need to wait for lab
		 * thread to complete as lab thread will not be
		 * scheduled at all.
		 */
		if (rc == -EINTR)
			goto done;

		/* Wait for the lab thread to exit */
		rc = wait_for_completion_timeout(
				&lab_d->thread_complete,
@@ -355,11 +365,6 @@ static int msm_cpe_lsm_lab_stop(struct snd_pcm_substream *substream)
		}
	}

	lab_d->thread_status = MSM_LSM_LAB_THREAD_STOP;
	lab_d->buf_idx = 0;
	atomic_set(&lab_d->in_count, 0);
	lab_d->dma_write = 0;

	rc = lsm_ops->lab_ch_setup(cpe->core_handle,
				   session,
				   WCD_CPE_PRE_DISABLE);
@@ -392,7 +397,12 @@ static int msm_cpe_lsm_lab_stop(struct snd_pcm_substream *substream)
		dev_err(rtd->dev,
			"%s: POST ch teardown failed, err = %d\n",
			__func__, rc);

done:
	lab_d->thread_status = MSM_LSM_LAB_THREAD_STOP;
	lab_d->buf_idx = 0;
	atomic_set(&lab_d->in_count, 0);
	lab_d->dma_write = 0;

	return 0;
}