From patchwork Mon Jun 22 06:58:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 11617017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6FB0013A0 for ; Mon, 22 Jun 2020 06:58:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5949325440 for ; Mon, 22 Jun 2020 06:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592809120; bh=UQA6roE5vMe7DuXL5wfFwW1a+4Izllpm3Vh8e3+Lxlo=; h=From:Cc:Subject:Date:In-Reply-To:References:To:List-ID:From; b=b6SKCefwZzSGrTcGmPIxWQHTv1G+lodTwUvuLV8uQr9RnD3t89UJ6w1dPZ/+b/9AB OIV8ql7BVl103nW/hzePhyOfCPIv5XD392wHANsN2VBc6egondCgpOGU7O3VXHUpdV BmnCrbhZG+Hb7nwKHXmik4X6Gzh8S/qXWcoKXpOw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731314AbgFVG6j (ORCPT ); Mon, 22 Jun 2020 02:58:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgFVG6i (ORCPT ); Mon, 22 Jun 2020 02:58:38 -0400 Received: from localhost.localdomain (unknown [171.61.66.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0BABF2543D; Mon, 22 Jun 2020 06:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592809117; bh=UQA6roE5vMe7DuXL5wfFwW1a+4Izllpm3Vh8e3+Lxlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ni4vPRF6mN1e4+i/fWwpy7wzPUbjCqt8oPVW4xbAYGGsyJHD4FJ/vZkSe7KEfu5Xw vIMol42e5KZdCikaSEgD6d/63cEeR9l9r+LmGBTuazzM9Dq2vXOepYmXGLIE2EoQig wRTL5dFg13uRUVddL+0nyqDrOzGTadRXEZCoyT+Y= From: Vinod Koul Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Vinod Koul , Srinivas Kandagatla Subject: [PATCH v2 3/3] ALSA: compress: fix partial_drain completion state Date: Mon, 22 Jun 2020 12:28:11 +0530 Message-Id: <20200622065811.221485-4-vkoul@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622065811.221485-1-vkoul@kernel.org> References: <20200622065811.221485-1-vkoul@kernel.org> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On partial_drain completion we should be in SNDRV_PCM_STATE_RUNNING state, so set that for partially draining streams in snd_compr_drain_notify() and use a flag for partially draining streams While at it, add locks for stream state change in snd_compr_drain_notify() as well. Fixes: f44f2a5417b2 ("ALSA: compress: fix drain calls blocking other compress functions (v6)") Reported-by: Srinivas Kandagatla Reviewed-by: Srinivas Kandagatla Tested-by: Srinivas Kandagatla Signed-off-by: Vinod Koul --- include/sound/compress_driver.h | 12 +++++++++++- sound/core/compress_offload.c | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h index 3df8d8c90191..93a5897201ea 100644 --- a/include/sound/compress_driver.h +++ b/include/sound/compress_driver.h @@ -66,6 +66,7 @@ struct snd_compr_runtime { * @direction: stream direction, playback/recording * @metadata_set: metadata set flag, true when set * @next_track: has userspace signal next track transition, true when set + * @partial_drain: undergoing partial_drain for stream, true when set * @private_data: pointer to DSP private data * @dma_buffer: allocated buffer if any */ @@ -78,6 +79,7 @@ struct snd_compr_stream { enum snd_compr_direction direction; bool metadata_set; bool next_track; + bool partial_drain; void *private_data; struct snd_dma_buffer dma_buffer; }; @@ -187,7 +189,15 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream) if (snd_BUG_ON(!stream)) return; - stream->runtime->state = SNDRV_PCM_STATE_SETUP; + mutex_lock(&stream->device->lock); + /* for partial_drain case we are back to running state on success */ + if (stream->partial_drain) { + stream->runtime->state = SNDRV_PCM_STATE_RUNNING; + stream->partial_drain = false; /* clear this flag as well */ + } else { + stream->runtime->state = SNDRV_PCM_STATE_SETUP; + } + mutex_unlock(&stream->device->lock); wake_up(&stream->runtime->sleep); } diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index e618580feac4..1c4b2cf450a0 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -803,6 +803,9 @@ static int snd_compr_stop(struct snd_compr_stream *stream) retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); if (!retval) { + /* clear flags and stop any drain wait */ + stream->partial_drain = false; + stream->metadata_set = false; snd_compr_drain_notify(stream); stream->runtime->total_bytes_available = 0; stream->runtime->total_bytes_transferred = 0; @@ -960,6 +963,7 @@ static int snd_compr_partial_drain(struct snd_compr_stream *stream) if (stream->next_track == false) return -EPERM; + stream->partial_drain = true; retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); if (retval) { pr_debug("Partial drain returned failure\n");