From patchwork Tue Jul 17 15:46:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Duncan X-Patchwork-Id: 10529997 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 363E1603ED for ; Tue, 17 Jul 2018 15:50:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21A0A29654 for ; Tue, 17 Jul 2018 15:50:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E96A29572; Tue, 17 Jul 2018 15:50:38 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DA6829672 for ; Tue, 17 Jul 2018 15:50:37 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 778E22677D1; Tue, 17 Jul 2018 17:46:43 +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 B4CC92677F2; Tue, 17 Jul 2018 17:46:41 +0200 (CEST) Received: from mx0b-0019bd01.pphosted.com (mx0b-0019bd01.pphosted.com [148.163.155.1]) by alsa0.perex.cz (Postfix) with ESMTP id C2D182677D1 for ; Tue, 17 Jul 2018 17:46:38 +0200 (CEST) Received: from pps.filterd (m0127437.ppops.net [127.0.0.1]) by mx0a-0019bd01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6HFj1J0026269; Tue, 17 Jul 2018 08:46:36 -0700 Received: from external-smtp.teslamotors.com ([209.11.133.121]) by mx0a-0019bd01.pphosted.com with ESMTP id 2k9jw4g5e7-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 17 Jul 2018 08:46:36 -0700 References: User-agent: mu4e 1.1.0; emacs 25.1.1 From: Rob Duncan To: Takashi Iwai In-Reply-To: Date: Tue, 17 Jul 2018 08:46:35 -0700 Message-ID: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-17_04:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: "alsa-devel@alsa-project.org" Subject: Re: [alsa-devel] Bug in snd_pcm_ioplug_avail_update()? 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 At 22:04 on Mon, Jul 16 2018, Takashi wrote: > The code change is similar as what I had in my mind, but... Version 2! Thanks, Rob. From 8890fbf81c27ed5fded12349b274c7c008c53249 Mon Sep 17 00:00:00 2001 From: Rob Duncan Date: Mon, 16 Jul 2018 16:35:23 -0700 Subject: [PATCH] pcm: ioplug: Transfer all available data The snd_pcm_mmap_begin() call returns the amount of contiguous data, which is less than the total available if it wraps around the buffer boundary. If we don't handle this split we leave stale data in the buffer that should have been overwritten, as well as unread data in the io_plugin that gets transferred on a subsequent call at the wrong offset. Signed-off-by: Rob Duncan --- src/pcm/pcm_ioplug.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c index 6d52c27b..881a1a85 100644 --- a/src/pcm/pcm_ioplug.c +++ b/src/pcm/pcm_ioplug.c @@ -716,6 +716,8 @@ static snd_pcm_sframes_t snd_pcm_ioplug_avail_update(snd_pcm_t *pcm) snd_pcm_ioplug_hw_ptr_update(pcm); if (io->data->state == SND_PCM_STATE_XRUN) return -EPIPE; + + avail = snd_pcm_mmap_avail(pcm); if (pcm->stream == SND_PCM_STREAM_CAPTURE && pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED && pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) { @@ -728,9 +730,19 @@ static snd_pcm_sframes_t snd_pcm_ioplug_avail_update(snd_pcm_t *pcm) result = io->data->callback->transfer(io->data, areas, offset, size); if (result < 0) return result; + + /* If the available data doesn't fit in the + contiguous area at the end of the mmap we + must transfer the remaining data to the + beginning of the mmap. */ + if (size < avail) { + result = io->data->callback->transfer(io->data, areas, + 0, avail - size); + if (result < 0) + return result; + } } } - avail = snd_pcm_mmap_avail(pcm); if (avail > io->avail_max) io->avail_max = avail; return (snd_pcm_sframes_t)avail;