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

Commit 5b1e55ff authored by Eric Laurent's avatar Eric Laurent Committed by Banajit Goswami
Browse files

ALSA: compress: use mutex in drain



Since we dont have lock over the function, we need to acquire mutex
when checking and modifying states in drain and partial_drain handlers

Change-Id: I3f8af90a226b772492fb6e09c625ebedc8ebfeb5
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
Signed-off-by: default avatarEric Laurent <elaurent@google.com>
Git-commit: bab68b886fb87ee82a3e7d86d54f7eaa025950ef
Git-repo: https://android.googlesource.com/kernel/msm


Signed-off-by: default avatarDhananjay Kumar <dhakumar@codeaurora.org>
[bgoswami@codeaurora.org: resolved merge conflicts]
Signed-off-by: default avatarBanajit Goswami <bgoswami@codeaurora.org>
parent fd495394
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -758,21 +758,31 @@ int snd_compr_stop_error(struct snd_compr_stream *stream,
}
EXPORT_SYMBOL_GPL(snd_compr_stop_error);

/* this fn is called without lock being held and we change stream states here
 * so while using the stream state auquire the lock but relase before invoking
 * DSP as the call will possibly take a while
 */
static int snd_compr_drain(struct snd_compr_stream *stream)
{
	int retval;

	mutex_lock(&stream->device->lock);
	if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
			stream->runtime->state == SNDRV_PCM_STATE_SETUP)
		return -EPERM;

			stream->runtime->state == SNDRV_PCM_STATE_SETUP) {
		retval = -EPERM;
		goto ret;
	}
	mutex_unlock(&stream->device->lock);
	retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN);
	mutex_lock(&stream->device->lock);
	if (!retval) {
		stream->runtime->state = SNDRV_PCM_STATE_DRAINING;
		wake_up(&stream->runtime->sleep);
		return retval;
	}

ret:
	mutex_unlock(&stream->device->lock);
	return retval;
}

@@ -801,9 +811,14 @@ static int snd_compr_next_track(struct snd_compr_stream *stream)
static int snd_compr_partial_drain(struct snd_compr_stream *stream)
{
	int retval;

	mutex_lock(&stream->device->lock);
	if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
			stream->runtime->state == SNDRV_PCM_STATE_SETUP)
			stream->runtime->state == SNDRV_PCM_STATE_SETUP) {
		mutex_unlock(&stream->device->lock);
		return -EPERM;
	}
	mutex_unlock(&stream->device->lock);
	/* stream can be drained only when next track has been signalled */
	if (stream->next_track == false)
		return -EPERM;