From patchwork Wed Jan 17 14:08:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mirza Krak X-Patchwork-Id: 10169347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3627A603ED for ; Wed, 17 Jan 2018 14:08:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2698728583 for ; Wed, 17 Jan 2018 14:08:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AFC328591; Wed, 17 Jan 2018 14:08:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9779528583 for ; Wed, 17 Jan 2018 14:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: References:In-Reply-To:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2nFmN/vR9BuAr+uvwZJlNdO7hGWPe2RlFXsDeP3JIL8=; b=Oou0JS+IgwVA3Z Lx1MDLJe7VMrA2/9vnoh0Tqd9adeQuAksmH1whrEx3tWsTHfq+tCdGzaQcmWqd27Q2Bds1DLQVLXT s4KZ6P2ho+J1T1dxuhCmV+IzRSO3znOCs0idWEff1Lcv1P6TgVVjD7YqlUmLQQ5t234elX4xcZ6qy yO9vz+JlsLoCC0gZf+MUO9PYVBYGE+d4X7kb1nAQKfdNw4VJi7h77djlIp3OhQSREEK0lqCKhvlww mB+9gSu+tyNLXenJFkq4bOYVWfckY8tA9u5nElVWUy4rgyVN0zqYFD6eoHRbtOOMht0d4gswrmA2g lvI6Yj/FURL3xyhdRLpQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eboOV-0002bI-2I; Wed, 17 Jan 2018 14:08:47 +0000 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eboOO-0002aP-KL for linux-rockchip@lists.infradead.org; Wed, 17 Jan 2018 14:08:46 +0000 Received: by mail-qt0-x241.google.com with SMTP id m59so22644175qte.11 for ; Wed, 17 Jan 2018 06:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=L0jMCiyU1OvpSbOQ6EgXeqM+jSmyQ+6iqAz0DVxmxRI=; b=q+yxR7t4lVvDuJtW0MPPd2EHZjZ4skTjwj+KkSboR8GHTQKGncFJg9I/VPCe8B79Ll zA4800ZB0cQMN0pQohL0id5kjLsF0qPVg3L+5n6XsIiz+I9kN2vKZpvG69BDRX57hl7U 0denwlNZQOOwvo61Y9k799PJAzI8XZBLLeXe4BLpJzRtu8UICkU1zMJzfLY/8InIeEHu FPaA6o50D0Pro/IXJk0r35wCb+InbhBI5N/zPruJ1RAWWgAFx1EGoiPsCBAuA4gXd3AN RkZACiqEOrEC7f6wEQYUuIAF6HqtVSruo2VKSfdPRQSHHdkV1p2dFuCEM224fY+FnR2F Jd8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=L0jMCiyU1OvpSbOQ6EgXeqM+jSmyQ+6iqAz0DVxmxRI=; b=MiteZNWiOlo7AEgFUAbvxDiPX9fcdjcNC03AbsOmO1bHvds0c22iWJ48hDakt544E0 n9GcWJuvR8joxIAMxYxcmn229qkRXvygBuEY7YDnoxYySO9iIPJ3mYA423ATjfeVMt3s +Istmi2lbe5CyQcbwlqpvwAQL/Jo62bwm1fi1fv7UOaBZe3OoT/ALv2M7hL7Qge8jS2f lj7hegeQLsY/3rtVaamywekjllNCtl82loEgETDdIfO8hF+MQDHNgWt+pykWvrOOJM2E QHTzmhzMo7VWCjovt8zN0X/862ix7XyiNB3HhXsmGzhJTa9M0GUHVAYohjQyeYv9Ly07 8mrg== X-Gm-Message-State: AKwxyteN4hdPz713Wlf3wEXV/cPqHnjz7aw5AEJFpY/PkWQ7m7A+Po6/ gmvMRoQ7k9NQM5sQzEih8KLmfS6swYrJOmaqG7AVXQ== X-Google-Smtp-Source: ACJfBosFC1NefT7v6GmNp6KsmslK3w22rb+ncklS+fnZPy0fXNp2aimvNxTwKIJnoKgzarmoqCHFZLbCoJAYbGGbDpQ= X-Received: by 10.237.39.213 with SMTP id m21mr19761785qtg.303.1516198107632; Wed, 17 Jan 2018 06:08:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.63.14 with HTTP; Wed, 17 Jan 2018 06:08:27 -0800 (PST) In-Reply-To: References: From: Mirza Krak Date: Wed, 17 Jan 2018 15:08:27 +0100 Message-ID: Subject: Re: [alsa-devel] Bad PCM stream after a suspend/resume cycle To: Takashi Iwai X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-rockchip@lists.infradead.org, alsa-devel@alsa-project.org, =?UTF-8?Q?Heiko_St=C3=BCbner?= Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 12 January 2018 at 19:04, Takashi Iwai wrote: > On Fri, 12 Jan 2018 14:36:45 +0100, > Mirza Krak wrote: >> < snip > > > The EBADFD is already indicating a fatal error, and something is wrong > in the driver. Basically the driver should suspend the stream via > snd_pcm_suspend*() call in the PM resume ops. Most likely your driver > misses that. > > That said, it's specific to your using driver, and you'd need to take > a look at that code there. Thank you for you patience with me. I have looked further in to my hardware drivers and I can not really see any faults here. But I did some further testing and applying the following diff on aplay "resolves" the problem (v1.1.4 of alsa-utils): Which means that there is no error in regard to suspending the stream as it properly reports this when checked. My problem is that this condition: (r >= 0 && (size_t)r < count) Is always true after a suspend/resume cycle. Which normally does not result in a "resume" call from aplay nor from snd_pcm_recover, which means that it will try to write data to a suspended stream which results in -EBADFD due to this (from alsa-lib): snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size) { < snip > if (bad_pcm_state(pcm, P_STATE_RUNNABLE)) return -EBADFD; return _snd_pcm_writei(pcm, buffer, size); } Because SUSPENDED is not part of the P_STATE_RUNNABLE, which maybe it should be? diff --git a/aplay/aplay.c b/aplay/aplay.c index f793c82..040cec1 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -2020,6 +2020,8 @@ static ssize_t pcm_write(u_char *data, size_t count) if (test_position) do_test_position(); if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) { + if (snd_pcm_state(handle) == SND_PCM_STATE_SUSPENDED) + suspend(); if (!test_nowait) snd_pcm_wait(handle, 100); } else if (r == -EPIPE) {