Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1823125imm; Mon, 3 Sep 2018 10:21:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ/Wm73tyiuNaWBaP0/yJOvZtfKxGuwqra9vf5QlWrCsuyxFaHb4QwI5cM7IElBOmxZDHZ3 X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr27011507pgd.372.1535995263962; Mon, 03 Sep 2018 10:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995263; cv=none; d=google.com; s=arc-20160816; b=T3mGsBJqBNKf3+Cmti4sF7DvdNfESxB2A+hQNqwBQXxu+O7CAHK7/ZF5EOmiqJRFHa E7iCmFDTJkPqcRmuSzaXgJxuF8oDuD14OR5Kt6ZcPLAPoX9yz8rlUgrdFQaJIn1+ebDq l57A5wJQPzWW5OENbP8wOvuG4MDbD+zl4ekDEtblgfVe21C6t7IDSGaw8v5LLtOonasF N/ZyMw/RLno+rDOD8EQovqQKker3pLksPDvOlL80gqne3pUzux+vM3HHoKfB3V/xb33c mb8mnhOz1/h+8K3priJocONO/7iqQnP/m5Ux9rp4wMho4PQfCzUDWwf89K3ihrIMNRmC A6uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8ln7ksaxpqp6C7yxLlp948mhWFYnFcl3vPicCJ6mW1E=; b=jB8pNCLQM2IBob634jnmRObAy6L66csDVAxjm44oxa+CGZc7x4oVIjeXPpfwRGxytZ f/WZc8NOzNYYncIJG4BRcfiaTkOIdoovO/vYIbviURNgvf4GcFl1l9YT1H+B2LhuiLUi M4Mm272MuUkY695o4wKNPOjzFpjQylgiS56os6WGpxr/J/3s4cSA+69qQh0S2RBxC07B L83aVSS1Q64kKUZinNy9KeD6fPpK0PgGe6i0sYcGKEC3dGmHh0DazdqKeJuM7Nx2DyMb UgLIUy+S0zJrFAqaGO2oVwj0HASkbD37I9bihUtdixJmFp3USAiK3Xdi/uk03xlPM8Sq 2gvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s196-v6si19431332pgc.448.2018.09.03.10.20.48; Mon, 03 Sep 2018 10:21:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730196AbeICVio (ORCPT + 99 others); Mon, 3 Sep 2018 17:38:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42850 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728685AbeICVim (ORCPT ); Mon, 3 Sep 2018 17:38:42 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 87E75D12; Mon, 3 Sep 2018 17:17:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Zapolskiy , Eugeniu Rosca , Felipe Balbi , Sasha Levin Subject: [PATCH 4.14 021/165] usb: gadget: u_audio: remove caching of stream buffer parameters Date: Mon, 3 Sep 2018 18:55:07 +0200 Message-Id: <20180903165656.098169851@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vladimir Zapolskiy [ Upstream commit 96afb54ece0ee903d23a7ac04ddc461413b972c4 ] There is no necessity to copy PCM stream ring buffer area and size properties to UAC private data structure, these values can be got from substream itself. The change gives more control on substream and avoid stale caching. Fixes: 132fcb460839 ("usb: gadget: Add Audio Class 2.0 Driver") Signed-off-by: Vladimir Zapolskiy Signed-off-by: Eugeniu Rosca Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/u_audio.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -41,9 +41,6 @@ struct uac_req { struct uac_rtd_params { struct snd_uac_chip *uac; /* parent chip */ bool ep_enabled; /* if the ep is enabled */ - /* Size of the ring buffer */ - size_t dma_bytes; - unsigned char *dma_area; struct snd_pcm_substream *ss; @@ -99,6 +96,7 @@ static void u_audio_iso_complete(struct int status = req->status; struct uac_req *ur = req->context; struct snd_pcm_substream *substream; + struct snd_pcm_runtime *runtime; struct uac_rtd_params *prm = ur->pp; struct snd_uac_chip *uac = prm->uac; @@ -120,6 +118,7 @@ static void u_audio_iso_complete(struct if (!substream) goto exit; + runtime = substream->runtime; spin_lock_irqsave(&prm->lock, flags); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { @@ -156,29 +155,31 @@ static void u_audio_iso_complete(struct spin_unlock_irqrestore(&prm->lock, flags); /* Pack USB load in ALSA ring buffer */ - pending = prm->dma_bytes - hw_ptr; + pending = runtime->dma_bytes - hw_ptr; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (unlikely(pending < req->actual)) { - memcpy(req->buf, prm->dma_area + hw_ptr, pending); - memcpy(req->buf + pending, prm->dma_area, + memcpy(req->buf, runtime->dma_area + hw_ptr, pending); + memcpy(req->buf + pending, runtime->dma_area, req->actual - pending); } else { - memcpy(req->buf, prm->dma_area + hw_ptr, req->actual); + memcpy(req->buf, runtime->dma_area + hw_ptr, + req->actual); } } else { if (unlikely(pending < req->actual)) { - memcpy(prm->dma_area + hw_ptr, req->buf, pending); - memcpy(prm->dma_area, req->buf + pending, + memcpy(runtime->dma_area + hw_ptr, req->buf, pending); + memcpy(runtime->dma_area, req->buf + pending, req->actual - pending); } else { - memcpy(prm->dma_area + hw_ptr, req->buf, req->actual); + memcpy(runtime->dma_area + hw_ptr, req->buf, + req->actual); } } spin_lock_irqsave(&prm->lock, flags); /* update hw_ptr after data is copied to memory */ - prm->hw_ptr = (hw_ptr + req->actual) % prm->dma_bytes; + prm->hw_ptr = (hw_ptr + req->actual) % runtime->dma_bytes; spin_unlock_irqrestore(&prm->lock, flags); exit: @@ -260,11 +261,8 @@ static int uac_pcm_hw_params(struct snd_ err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); - if (err >= 0) { - prm->dma_bytes = substream->runtime->dma_bytes; - prm->dma_area = substream->runtime->dma_area; + if (err >= 0) prm->period_size = params_period_bytes(hw_params); - } return err; } @@ -279,8 +277,6 @@ static int uac_pcm_hw_free(struct snd_pc else prm = &uac->c_prm; - prm->dma_area = NULL; - prm->dma_bytes = 0; prm->period_size = 0; return snd_pcm_lib_free_pages(substream);