From patchwork Fri Jun 12 08:15:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 6595861 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D881EC0020 for ; Fri, 12 Jun 2015 08:15:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E711620663 for ; Fri, 12 Jun 2015 08:15:51 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id B87E220664 for ; Fri, 12 Jun 2015 08:15:50 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 4AD06266729; Fri, 12 Jun 2015 10:15:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 749302666DE; Fri, 12 Jun 2015 10:15:47 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1FF342666F0; Fri, 12 Jun 2015 10:15:46 +0200 (CEST) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0124.outbound.protection.outlook.com [65.55.169.124]) by alsa0.perex.cz (Postfix) with ESMTP id A5E412666D3 for ; Fri, 12 Jun 2015 10:15:38 +0200 (CEST) Received: from BY2PR03CA001.namprd03.prod.outlook.com (10.255.93.18) by BLUPR03MB279.namprd03.prod.outlook.com (10.255.213.17) with Microsoft SMTP Server (TLS) id 15.1.195.6; Fri, 12 Jun 2015 08:15:28 +0000 Received: from BN1BFFO11FD044.protection.gbl (10.255.93.4) by BY2PR03CA001.outlook.office365.com (10.255.93.18) with Microsoft SMTP Server (TLS) id 15.1.190.14 via Frontend Transport; Fri, 12 Jun 2015 08:15:22 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; alsa-project.org; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD044.mail.protection.outlook.com (10.58.144.107) with Microsoft SMTP Server (TLS) id 15.1.190.9 via Frontend Transport; Fri, 12 Jun 2015 08:15:21 +0000 Received: from audiosh1.ap.freescale.net (audiosh1.ap.freescale.net [10.192.241.212]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t5C8FIeH009210; Fri, 12 Jun 2015 01:15:19 -0700 From: Shengjiu Wang To: , Date: Fri, 12 Jun 2015 16:15:08 +0800 Message-ID: <237099058d5e658610915f8f6a4724d782299a25.1434096300.git.shengjiu.wang@freescale.com> X-Mailer: git-send-email 1.7.9.5 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD044; 1:O9ciicpyRhENPpJsOJXTav7cxolrcC5f2jRNjYCCtcs+9CqDpa/zdnvPOanjbxoGmSl05keso5i1uyT8ZXs6lYbGEDrKnWE8kzSCfymDnwaKxHyb2iO0cSSc1z3ThbUYqoMpkQ5970MsGwubprJTmjDBEy+FdJz2V1GJehyBZNf6F8Ripiv+NRLgWXTtfa7Q+qhHDaIPEpAHOSp2i8GkPrBCBM0qlyTJzwnw7NsiMdSR6T57Cgx4H6JOUGDxKsLUI8ZLWuRW+9yjIjy4zzpDKMuskX6EtAdJ4+DoyV5P1GYnfUbN6hsbkDAATa9Upj9rSza9Tf3eSKIv8UADTWyAsg== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(118296001)(48376002)(5001770100001)(47776003)(50466002)(85426001)(106466001)(189998001)(46102003)(6806004)(229853001)(5001960100002)(50226001)(77096005)(86362001)(87936001)(33646002)(92566002)(36756003)(104016003)(77156002)(50986999)(19580395003)(105606002)(19580405001)(62966003); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB279; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB279; 2:wIQA1lIsyqDszeEoQ8/Bfsb85Ovg6iiY2D8F4uaYiXBJek1Z48OAuG0uKx7ato4Q; 3:zwT8aQQdf+sacR2MbMZOTXhS4QPfOa/BwNL9/a82rxwFtbL49OIY013G6+ZmSJnCrbLFfuvj/tiDlVsAZX8pYqhChxxUGJvbRM5QWeUZgCFB7YqLRyM1n9I6/1cEVXmQuy4/mX51Bc0OydGvAga/Z+HuS0t1QujGqOjEaYaxFNhCYvBeVDhXt/LXi0+VZJ7PgddMt2TB9PPa82LW5aS6QKuk+h2XzeYaH6kKEIW2HKg=; 20:xwt1I4NDqD49OG+ZNHZkCevf4C/VWzVhHTH7FrvKiv6VQI6zBiDZL9O97wwJuji5dAE+r1H0v7nJYEWxC7hy55bV/VALQ9foX7TWOdSt2784zw0J5Srvc3QEFo0fiCxEDoPtR1iWvlXhEEhlaIfQmD23MJHGvbslMd3WlpQoZV08N8yRWP/xxblNuQhY9Tu+/ez8tzUX14h9uGbV36YYXA0gNGa1DBHK97smBAHm+Qjix5RipKsGkYhNIe1+RdiVFJuT6gHfyabYp0Aw2mtTjZr0s6mEnhC6FZ9Yi+y+v7yTMzcuWyuNI1fQG8bbUfi0SXb6Rd1NzkjP30QAltsr5fEoC0W7Y2h5oiife8U8ZoI=; 4:rMCii4K5jYD7DAPp+blVdpdfJ4O9INRglrgPlovh6V0gpSiVuqp7cLVfCTMCoodw5aJp7HS8tMKAyRkMRV+1Phve9RFyKdvoH6+UNURWs79kFvR8sqyJN3FJuXS2ltwuIjJGIN+GGtJxeDVgId27ryj0kaNDRmyqSfKVcfERSw17NZ3x7gmf/QyD/QCJU2t2460H1Un1/RHbePEl2lodnr1pXXBC3A2LaDp4loNs1PzU/VW5jSNEYwuXBNQ7rmIptdM2I+j5l/phNm2vazSn4P3cjWAEBbGgipKbDUwsuXM= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB279; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BLUPR03MB279; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB279; X-Forefront-PRVS: 060503E79B X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB279; 23:qCcNWek8lfzRmswnnp7YCrnkwTaSzUneKYlAA3qXmEIKhtoabmPUmVP/dDcxNTVcPI7H0bT/5IASzXzELDwdI5qC2enxDEGaFShydV4Fj4FzDetu6XMFvaEqK1ug86YPZJxu/mg25dIHI52W6P72cQMHXvVMMM51skXnOxTmxyj8BJ02ft9xrf5Y1XqkQ1dPSdNU9o30o+HPRfvwDXKzVU5tMy6Th1byb44Iw64p2IiSULkOqA4birtFIMVw/aif5kd9TSU8uz7vEmZPdGoEqVbqg5T+ppyUv05ei7PFmshvE6+IJf/apt9CFcDD6CY6DuQx4QHcijsr9f34HXvnSxfmOWOV64erUTymqlraK7bxG1PXSf4NOgByMUn8RjTbrSMXxBDYEu1D3TGqjwgq7VeqzF26rlfse/J7TaT9xmwME2ELggwJuhbxWp2Q2PNceimABLNd3Gv5moyYma3NG5wimUUnN+iSeDgmQjPTIdhHPrmRk6IZI2Hw9EJhmpgxeDZ6oav3I15p5CmItFf0oN3CI+UzKtJJvAReARUALePT0m55k9vWQByj1cL138JsEaaf5sg00C+OBXvqBXZehUJbfzbRKkGbiIJ7v2nVFsfOLra/MChxtIXZu9mjH/kJC2d7O/EeeVDj/dvJwqf+Um+8jZWKmA3iVojzQkFyqEHzyJW4r3qCyGUIF52nJR8nArCYarqxe1HxYgyKYIerhirhfNhY2Cs3vr6dytRmXjD1ttiYFlCJZK88SM1a1XvEEOiYLv6j/l/HLYD2fjLuAvPFzfHlO53WhpkNZspBpCBAiCXnJvyCs2HjcSul41pY X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB279; 5:o/lWV6GflBlALvU5bWw05VMDwMoAdinPCpfnO/7jyX/QdCTQRCr2TOWCVTBjeR3MCDlhjMOl498fRSdD0JbxkwF+7X/x7DhavjihWytsBwqyDplY6CckEU8zv81tUjnm6jDxnOiFnGaKGSPijWX5rA==; 24:09i63E8X7DCbl+2IbQowojMMlsPftY5ZFPfJwn87qSLM9IX/bfnYVuuwlub2V8p4tI9UI52QZrrkZFeWT2v/2Bm8juRyDRcTULZZ4mVJ+hI=; 20:LrcRCaEuYmzVSbL5aQOOl5Eg/DSU8Pt+sHJGXkfgozM5/dEefehMNe72WL8wN9YgHoMzZnIAKaoTuBHYPPrfIg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2015 08:15:21.2507 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB279 Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH V2] PCM: snd_pcm_xxxx_drain() maybe blocked after suspend and resume X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP After suspend and resume, the alsa driver is stopped. But if alsa-lib run into snd_pcm_xxxx_drain(), it need to wait avail >= pcm->stop_threshold, otherwise, it will not exit the loop, so finally it is blocked at poll() of snd_pcm_wait_nocheck(pcm, -1). This patch is to add state check after snd_pcm_wait_nocheck(pcm, -1), if the state is SND_PCM_STATE_SUSPENDED, then return error. Signed-off-by: Shengjiu Wang --- changes in v2: - Add state check in beginning of drain() - Add fix for pcm_dshare() - Mov the state check to the place that is after snd_pcm_direct_clear_timer_queue(dmix). That the suspend may happen just before calling snd_pcm_direct_clear_timer_queue(dmix), which will force the next poll to wait. So move state check to new place may safty. src/pcm/pcm_dmix.c | 14 ++++++++++++++ src/pcm/pcm_dshare.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c index babde6a..91148b9 100644 --- a/src/pcm/pcm_dmix.c +++ b/src/pcm/pcm_dmix.c @@ -616,6 +616,13 @@ static int snd_pcm_dmix_drain(snd_pcm_t *pcm) snd_pcm_uframes_t stop_threshold; int err; + switch (snd_pcm_state(dmix->spcm)) { + case SND_PCM_STATE_SUSPENDED: + return -ESTRPIPE; + default: + break; + } + if (dmix->state == SND_PCM_STATE_OPEN) return -EBADFD; if (pcm->mode & SND_PCM_NONBLOCK) @@ -648,6 +655,13 @@ static int snd_pcm_dmix_drain(snd_pcm_t *pcm) snd_pcm_dmix_sync_area(pcm); snd_pcm_wait_nocheck(pcm, -1); snd_pcm_direct_clear_timer_queue(dmix); /* force poll to wait */ + + switch (snd_pcm_state(dmix->spcm)) { + case SND_PCM_STATE_SUSPENDED: + return -ESTRPIPE; + default: + break; + } } } while (dmix->state == SND_PCM_STATE_DRAINING); pcm->stop_threshold = stop_threshold; diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index 020e6f7..24975d4 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -367,6 +367,13 @@ static int snd_pcm_dshare_drain(snd_pcm_t *pcm) snd_pcm_uframes_t stop_threshold; int err; + switch (snd_pcm_state(dshare->spcm)) { + case SND_PCM_STATE_SUSPENDED: + return -ESTRPIPE; + default: + break; + } + if (dshare->state == SND_PCM_STATE_OPEN) return -EBADFD; if (pcm->mode & SND_PCM_NONBLOCK) @@ -399,6 +406,13 @@ static int snd_pcm_dshare_drain(snd_pcm_t *pcm) snd_pcm_dshare_sync_area(pcm); snd_pcm_wait_nocheck(pcm, -1); snd_pcm_direct_clear_timer_queue(dshare); /* force poll to wait */ + + switch (snd_pcm_state(dshare->spcm)) { + case SND_PCM_STATE_SUSPENDED: + return -ESTRPIPE; + default: + break; + } } } while (dshare->state == SND_PCM_STATE_DRAINING); pcm->stop_threshold = stop_threshold;