Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1821835imm; Mon, 3 Sep 2018 10:18:42 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb3zYV9OTlxKM2pTYSByHtPXl8TPdrHu/hP2KspBDu/IJ1hu61ywuUDAyDqQVHw4FlKoA/6 X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr3512690pgq.431.1535995122030; Mon, 03 Sep 2018 10:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995122; cv=none; d=google.com; s=arc-20160816; b=YYxnwYjb5n+w07TpvQ47SvtK3Lz94Qv2ii8ffddUfSpWW7ScY0sbCou4QNA4CpA1XZ t7181uN+FzkMyclLqQ89Z9GbEFnmdN3mMweCZ91Hl9bH+OR1W0AzuBRVXrXPrQdu1s3y TwDhrFH/4+YQtOwyim38dfRWx3lJGz+6yoJy4/cgE2JIOvOOIMN4SZ0ocGp63tCPMjiE UPfpy1zq4Wp2+w5lUweOSB5ZhAhUsI66IobsLBOlTaxV1XXJhvWLm4E34bF7Ue6e9xKY X8/8SFt3N/VWsbUABfuQvwO7j3uRHPHcQjRDyzZk/SYmJDHJbDwParjjpSlX9kfzCRV1 FHQA== 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=JoU639p4gHbvtyb3rNlMzX9Qyl1MrQyslZEDBRluFE0=; b=K4BCkmwxKREmtBTD+2yFF/e60vye9btFFOleD2H2A0r1EGrQQvPw1SKV+Nai0lauza GAYz111K3DCfMpbx9l7BrHmU05TMPykmmPCh0rinUMzIkJsAORaWMqy6dY8oClWIgT/q gtFxonvgKFpE0LG18IhAjusjeM7+kX3OmVPXos/wZgxSYppRT7+wExttnzwtiypfkvvK 6aN6hYLauOMD/gHiY8h7r+NeG6ycTmmgj45psejdOJDtIJ4smUOVAimHbQWn6ENb4lUm A9wkrPOdF7Au21Px7dBWi7xM31Hxc399ZatZu5VYrcXd7PHhRXNMTp3Qq001FgfFGnZb 2u/w== 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 d1-v6si17639577pgj.353.2018.09.03.10.18.27; Mon, 03 Sep 2018 10:18:41 -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 S1730088AbeICViG (ORCPT + 99 others); Mon, 3 Sep 2018 17:38:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42688 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728207AbeICViF (ORCPT ); Mon, 3 Sep 2018 17:38:05 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 23463D09; Mon, 3 Sep 2018 17:17:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joshua Frkuska , Eugeniu Rosca , Felipe Balbi , Sasha Levin Subject: [PATCH 4.14 020/165] usb: gadget: u_audio: update hw_ptr in iso_complete after data copied Date: Mon, 3 Sep 2018 18:55:06 +0200 Message-Id: <20180903165656.049523890@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: Joshua Frkuska [ Upstream commit 6b37bd78d30c890e575a1bda22978d1d2a233362 ] In u_audio_iso_complete, the runtime hw_ptr is updated before the data is actually copied over to/from the buffer/dma area. When ALSA uses this hw_ptr, the data may not actually be available to be used. This causes trash/stale audio to play/record. This patch updates the hw_ptr after the data has been copied to avoid this. Fixes: 132fcb460839 ("usb: gadget: Add Audio Class 2.0 Driver") Signed-off-by: Joshua Frkuska 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -152,7 +152,6 @@ static void u_audio_iso_complete(struct update_alsa = true; hw_ptr = prm->hw_ptr; - prm->hw_ptr = (prm->hw_ptr + req->actual) % prm->dma_bytes; spin_unlock_irqrestore(&prm->lock, flags); @@ -177,6 +176,11 @@ static void u_audio_iso_complete(struct } } + 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; + spin_unlock_irqrestore(&prm->lock, flags); + exit: if (usb_ep_queue(ep, req, GFP_ATOMIC)) dev_err(uac->card->dev, "%d Error!\n", __LINE__);