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

Commit 47aac6c9 authored by Bhalchandra Gajare's avatar Bhalchandra Gajare Committed by Gerrit - the friendly Code Review server
Browse files

ASoC: msm-cpe-lsm: Make sure close is handled gacefully



It may happen that the lsm driver can get closed while bufferring is in
progress. In such case, cleaning up driver resources may cause a crash
in the buferring thread. Fix the crash by explicitly stopping the
bufferring when close is invoked.

Change-Id: I137e2593160ff8d602b3f5eee4a843e223fa45f5
Signed-off-by: default avatarBhalchandra Gajare <gajare@codeaurora.org>
parent 541748cd
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -466,6 +466,7 @@ static int msm_cpe_lsm_close(struct snd_pcm_substream *substream)
	struct cpe_lsm_session *session;
	struct wcd_cpe_afe_ops *afe_ops;
	struct wcd_cpe_afe_port_cfg *afe_cfg;
	struct wcd_cpe_lsm_lab *lab_sess;
	int rc = 0;

	if (!cpe || !cpe->core_handle) {
@@ -484,9 +485,31 @@ static int msm_cpe_lsm_close(struct snd_pcm_substream *substream)

	lsm_ops = &cpe->lsm_ops;
	session = lsm_d->lsm_session;
	lab_sess = &session->lab;
	afe_ops = &cpe->afe_ops;
	afe_cfg = &(lsm_d->lsm_session->afe_port_cfg);

	if (lab_sess->thread_status == MSM_LSM_LAB_THREAD_RUNNING) {
		/*
		 * Close invoked while buferring is in progress.
		 * Gracefully terminate the buferring before closing
		 * the device.
		 */
		pr_err("%s: close when bufferring is in progress\n", __func__);
		rc = kthread_stop(session->lsm_lab_thread);

		/* Wait for the lab thread to exit */
		rc = wait_for_completion_timeout(
				&lab_sess->thread_complete,
				MSM_CPE_LAB_THREAD_TIMEOUT);
		if (!rc) {
			dev_err(rtd->dev,
				"%s: Wait for lab thread timedout\n",
				__func__);
			return -ETIMEDOUT;
		}
	}

	rc = msm_cpe_afe_port_cntl(substream,
				   cpe->core_handle,
				   afe_ops, afe_cfg,