From patchwork Mon Dec 5 13:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 631056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07DEDC4321E for ; Mon, 5 Dec 2022 13:23:24 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 30A701872; Mon, 5 Dec 2022 14:22:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 30A701872 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1670246602; bh=MaNqeEkhD6uFBQiZvZCRdckHPwLavdJwvT3+JYV4DYA=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mPgcIVhC2ykF0gUBmCq6NXGnM6B9sBGM7o42MGvtsGEImQT+lU4/5IsTL806V5Una 4WYYCMkji/LklQbV+yzNJ9Pzpg7pzdiK0VSx4myi+SY+cFUz+RJ0eIOtneVJazaZT8 PUhorDgLB0qW/xVGy8urXi16LEQ1PhwzUPE+Deq0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 59DD2F80568; Mon, 5 Dec 2022 14:21:40 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 37928F80236; Mon, 5 Dec 2022 14:21:39 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id A92A3F80236 for ; Mon, 5 Dec 2022 14:21:27 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A92A3F80236 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="JGd2wW5U"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="QA0xh0Hx" Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5B528225C0; Mon, 5 Dec 2022 13:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670246487; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kqBVOyE88h6z4FJ0V7WQNfew9pfDbQ4nz1o5y0mrLF8=; b=JGd2wW5UGbqdqXX4fKXriT3MNBRHxPRoz9KOeZq3X3Q8pO9Xz+VLCsBXDuZ99L7aO+VTH1 O35vZf2ViU/9p/qXim70bkHeEH0slTa4gKU65F3EZAYTeUZ/WVg0uks08flULs3mhX5+0v OS4DL33pR/Rso8FFds30rOJ594uuUjA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670246487; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kqBVOyE88h6z4FJ0V7WQNfew9pfDbQ4nz1o5y0mrLF8=; b=QA0xh0HxJsNeUX4qRVqC6M9fk+8ZW/R2EAaIhOeetiVOCvLFhc4pcuOKSxHxMvcAKmT5rM QiTrkEV+nvdrUgDg== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 37E601369C; Mon, 5 Dec 2022 13:21:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id gAI/DFfwjWOZagAAGKfGzw (envelope-from ); Mon, 05 Dec 2022 13:21:27 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 1/3] ALSA: pcm: Set missing stop_operating flag at undoing trigger start Date: Mon, 5 Dec 2022 14:21:22 +0100 Message-Id: <20221205132124.11585-2-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221205132124.11585-1-tiwai@suse.de> References: <20221205132124.11585-1-tiwai@suse.de> MIME-Version: 1.0 Cc: Carl Hetherington X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" When a PCM trigger-start fails at snd_pcm_do_start(), PCM core tries to undo the action at snd_pcm_undo_start() by issuing the trigger STOP manually. At that point, we forgot to set the stop_operating flag, hence the sync-stop won't be issued at the next prepare or other calls. This patch adds the missing stop_operating flag at snd_pcm_undo_start(). Fixes: 1e850beea278 ("ALSA: pcm: Add the support for sync-stop operation") Link: https://lore.kernel.org/r/b4e71631-4a94-613-27b2-fb595792630@carlh.net Signed-off-by: Takashi Iwai --- sound/core/pcm_native.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index ba6e44d02faa..e3deec62b9a1 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1432,8 +1432,10 @@ static int snd_pcm_do_start(struct snd_pcm_substream *substream, static void snd_pcm_undo_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { - if (substream->runtime->trigger_master == substream) + if (substream->runtime->trigger_master == substream) { substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); + substream->runtime->stop_operating = true; + } } static void snd_pcm_post_start(struct snd_pcm_substream *substream, From patchwork Mon Dec 5 13:21:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 631057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E044C4321E for ; Mon, 5 Dec 2022 13:22:50 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 24D7817EE; Mon, 5 Dec 2022 14:21:58 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 24D7817EE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1670246568; bh=GVqasnUZUFppt8L4KzOC3MBgSF4gAWjpRkFb47xIZh0=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OfP9VrkZ5anWDHS9TjJ5ksB959IMB6w7qslKHDcfg342TlWIedrk9PYDripzomq6o yloNVpbuww+puMlYxeLy8+SUbMLD/kw4Z5M8MHRlSXPGDk3JykxngSZR3vmOnegIVJ AmZ9nDxMgJvjBMT+KNsllAc2olMoxvGR5yRKFTpU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B02BCF8052E; Mon, 5 Dec 2022 14:21:35 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5BB86F8049E; Mon, 5 Dec 2022 14:21:34 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3202AF8014C for ; Mon, 5 Dec 2022 14:21:27 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3202AF8014C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="BqpFzupL"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="cQC6eP96" Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 752572260B; Mon, 5 Dec 2022 13:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670246487; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pe3DPYrkMJAqI/+GF8n8S0goPx841PWsO0FySDB9gwU=; b=BqpFzupLs1c89CmDWJ3y+uu7ZXNXeaigEJ8AHGOr7JUhczFwDCnIKq9i3/xSPVC3ff7tvP V+5qVuKtTR9kzXFoL5W9fc1p1v9cffxhhcSo3xeQ+ta2pPGFChk1dAHXMns+6rSpD+S1/M Si2i4xZcpcZ9On+lZPGm+61pdElVKPw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670246487; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pe3DPYrkMJAqI/+GF8n8S0goPx841PWsO0FySDB9gwU=; b=cQC6eP96CdkUhKPCRCfM2p+06trJQzuUwYEHudMsqVmKxG0OjB1vTVwqFlznP74ntlXCHI 8Byaa+NRLIzfqmDQ== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 5A1D513326; Mon, 5 Dec 2022 13:21:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id KOYdFVfwjWOZagAAGKfGzw (envelope-from ); Mon, 05 Dec 2022 13:21:27 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 2/3] ALSA: pcm: Handle XRUN at trigger START Date: Mon, 5 Dec 2022 14:21:23 +0100 Message-Id: <20221205132124.11585-3-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221205132124.11585-1-tiwai@suse.de> References: <20221205132124.11585-1-tiwai@suse.de> MIME-Version: 1.0 Cc: Carl Hetherington X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" When the driver returns -EPIPE for indicating an XRUN already at PCM trigger START, we should treat properly and set it to the XRUN state. Otherwise the state is missing and the application would try to issue trigger again without knowing that it's in an error state. This is just for a theoretical bug, and it won't happen in most cases. Link: https://lore.kernel.org/r/b4e71631-4a94-613-27b2-fb595792630@carlh.net Signed-off-by: Takashi Iwai --- sound/core/pcm_native.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index e3deec62b9a1..9c122e757efe 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1424,9 +1424,15 @@ static int snd_pcm_pre_start(struct snd_pcm_substream *substream, static int snd_pcm_do_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { + int err; + if (substream->runtime->trigger_master != substream) return 0; - return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); + err = substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); + /* XRUN happened during the start */ + if (err == -EPIPE) + __snd_pcm_set_state(substream->runtime, SNDRV_PCM_STATE_XRUN); + return err; } static void snd_pcm_undo_start(struct snd_pcm_substream *substream, From patchwork Mon Dec 5 13:21:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 631924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2326CC4321E for ; Mon, 5 Dec 2022 13:22:27 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 66D9C17F0; Mon, 5 Dec 2022 14:21:35 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 66D9C17F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1670246545; bh=O3Xuifm3408NaRph+0QLbjYAPtAN+r/LZE8d1OnwVCw=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AwO7Fo3wmvBdFEUyS1ETlD70qlcsxJgLl8f7JQ2OsAl68F5lj/oGWNPqXwuNzFbZ7 hRriHR3nsapvsiO9Ro1p7E6HVArND1cP/DG3YErc5zGlyKsZ1Oos8MlxelwEea5zHN gGsvtf+DEsb9IKigRznN8VjszrL3GNkd6LCrYxJk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 18C66F80171; Mon, 5 Dec 2022 14:21:35 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E0A39F8049E; Mon, 5 Dec 2022 14:21:33 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 26EBAF800BD for ; Mon, 5 Dec 2022 14:21:27 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 26EBAF800BD Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DIA8h7i+"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="znx1Zl2f" Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8DF8422622; Mon, 5 Dec 2022 13:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670246487; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o9bcg7EmxxzeLf6cduZG8Zb1DZo7TSFfgvxJ7pUe8Eo=; b=DIA8h7i+0qzMEI5AcTb1oNDJyEUPQNWpoTRKTRWzzp6J42aF2YLfB83Krw76sijD084sX6 bAPNKYI7gK850PKdXs7Wt/eBEkHKs7ofGpRTGgKs7qsWROzbktTI1ulbZWox+PX5ZO9Mos aVe+2iCkLOc0TJMSWrG3b3rSO64BryM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670246487; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o9bcg7EmxxzeLf6cduZG8Zb1DZo7TSFfgvxJ7pUe8Eo=; b=znx1Zl2f3R2XPiNc1Nv1K9+h8cAqa6bXP/2jjcQXw+531iWEEX7eAzbpdGM93WBWfd3tOx Pl86vLe1hH/DU3AA== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 76B881369C; Mon, 5 Dec 2022 13:21:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id uDRgHFfwjWOZagAAGKfGzw (envelope-from ); Mon, 05 Dec 2022 13:21:27 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 3/3] ALSA: usb-audio: Workaround for XRUN at prepare Date: Mon, 5 Dec 2022 14:21:24 +0100 Message-Id: <20221205132124.11585-4-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221205132124.11585-1-tiwai@suse.de> References: <20221205132124.11585-1-tiwai@suse.de> MIME-Version: 1.0 Cc: Carl Hetherington X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Under certain situations (typically in the implicit feedback mode), USB-audio driver starts a playback stream already at PCM prepare call even before the actual PCM trigger-START call. For implicit feedback mode, this effectively starts two streams for data and sync endpoints, and if a coupled sync stream gets XRUN at this point, it results in an error -EPIPE. The problem is that currently we return -EPIPE error as is from the prepare. Then application tries to recover again via the prepare call, but it'll fail again because the sync-stop is missing. The sync-stop is missing because it's an internal trigger call (hence the PCM core isn't involved). Since we'll need to re-issue the prepare in anyway when trapped into this pitfall, this patch attempts to address it in a bit different way; namely, the driver tries to prepare once again after syncing the stop manually by itself -- so applications don't see the internal error. At the second failure, we report the error as is, but this shouldn't happen in normal situations. Reported-and-tested-by: Carl Hetherington Cc: Link: https://lore.kernel.org/r/b4e71631-4a94-613-27b2-fb595792630@carlh.net Signed-off-by: Takashi Iwai --- sound/usb/pcm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 8ed165f036a0..9557bd4d1bbc 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -604,6 +604,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct snd_usb_substream *subs = runtime->private_data; struct snd_usb_audio *chip = subs->stream->chip; + int retry = 0; int ret; ret = snd_usb_lock_shutdown(chip); @@ -614,6 +615,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) goto unlock; } + again: if (subs->sync_endpoint) { ret = snd_usb_endpoint_prepare(chip, subs->sync_endpoint); if (ret < 0) @@ -638,9 +640,16 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) subs->lowlatency_playback = lowlatency_playback_available(runtime, subs); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && - !subs->lowlatency_playback) + !subs->lowlatency_playback) { ret = start_endpoints(subs); - + /* if XRUN happens at starting streams (possibly with implicit + * fb case), restart again, but only try once. + */ + if (ret == -EPIPE && !retry++) { + sync_pending_stops(subs); + goto again; + } + } unlock: snd_usb_unlock_shutdown(chip); return ret;