Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3075835ybt; Mon, 29 Jun 2020 14:40:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0EjKisEtN216D++uiXYegFD0N93zNXFIcLT45mkgtBHmQFN9USoOthbD1zm0kHUDiwekO X-Received: by 2002:a05:6402:1a42:: with SMTP id bf2mr13418429edb.292.1593466858275; Mon, 29 Jun 2020 14:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593466858; cv=none; d=google.com; s=arc-20160816; b=U7h2CE8i4sCuVIE30lWUzceK8bdv6/fRQyqrOJZSZGruiqgB0VB70Zy4rQQRSTbsg0 1wrm4fL3SrA8CrIrT6NpygMdkqOZUjYvDTLMpaqvoY62rrj/I/Sk3lQiBbGDTH3+7hCa WBsO8cw9VFXI8OBYgTvgD5Nkds5e54bMUpMSf2V7fLal7j0vcSnPph/ScLBU7PoJqUmU E0y+hzTwvqQcwun142aD9qVAiYsDa7merBcyl6Eu7YCjEpa9JL+aCsXzrfNo6h2dXWNA gUJARQ43W1sZOr1PkO0jwrAEV67+fCykjPW9TfUq7Io5GVh8XuRe6FTpVyWgq37xcrpG PWKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fyYQI5ZPkWUGuLdm98P/kLl2qqpBjtlpcH/pIZ5ZV0c=; b=Vh/rg7s5FsPCsEtzBKPAvk+3cmbEdfQcAvDG2+YNIxv+0xgE7gtkE/9qDBdkj1TqBJ XdD7TiSFpCIjO+ob2+k3/f5umgv/keJs1BBvkrA8E0PS3fJyLK8N4I6+ga39/CEQF86l 2oEIe6NnyA1NWXiaK3VylTgPmb3U9PyBJKECTl5rL7Ntvr7/KYicPu1SmzGNoW4ArV5w JNKuZLIJtg51BVUlmDQ4l3crD5eW8OISu6K1lhXBskig3oRkaKV5qLerF1tQPEfOixcR u6wMJrbRcmVfC/YU8bwgV1cGlC7K5hjznre0MqXrtCLjEm90F+DdhMOuRH/ru0SoPQMI 9uwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="XN5O6/go"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si463312edb.116.2020.06.29.14.40.35; Mon, 29 Jun 2020 14:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="XN5O6/go"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388849AbgF2VkS (ORCPT + 99 others); Mon, 29 Jun 2020 17:40:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728264AbgF2Sk3 (ORCPT ); Mon, 29 Jun 2020 14:40:29 -0400 Received: from localhost.localdomain (unknown [122.182.251.219]) (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 C719223D9A; Mon, 29 Jun 2020 13:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593438481; bh=ErchkDOamwN3rAMIPB9pr36SlNkChONRoW17kGzzZts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XN5O6/goHTBPIsgpmRFLcv+H5ankRWmWHBYjLObMz7pwFPR8e9JviNLdsaST18oWJ Ljs5BuHKM/EUAYVkpgg9hvfw0T3+oI6Ba3VAFOjntwIRjhzzkolAHuVeaKrLRQwCQT vq+YB43l2ADmGEyo1PLFmTJzA4fY96BVbHhIhLSk= From: Vinod Koul To: Takashi Iwai , Jaroslav Kysela Cc: Vinod Koul , =?UTF-8?q?Amadeusz=20S=C5=82awi=C5=84ski?= , Srinivas Kandagatla , Pierre-Louis Bossart , Charles Keepax , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 3/3] ALSA: compress: fix partial_drain completion state Date: Mon, 29 Jun 2020 19:17:37 +0530 Message-Id: <20200629134737.105993-4-vkoul@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200629134737.105993-1-vkoul@kernel.org> References: <20200629134737.105993-1-vkoul@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)") Reviewed-by: Srinivas Kandagatla Tested-by: Srinivas Kandagatla Signed-off-by: Vinod Koul --- include/sound/compress_driver.h | 10 +++++++++- sound/core/compress_offload.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h index 3df8d8c90191..8d23351f7ad7 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,13 @@ 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; + /* 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; + } 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"); -- 2.26.2