Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1823635imm; Mon, 3 Sep 2018 10:21:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbClck2OimpjSI4/XL/rnOhPYZIU9UX0mqsQ8By/EYKEeQVpTlUXnalLwpgIOWh+0YKq98a X-Received: by 2002:a62:c182:: with SMTP id i124-v6mr30135137pfg.248.1535995315256; Mon, 03 Sep 2018 10:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995315; cv=none; d=google.com; s=arc-20160816; b=dUsBNoKnES/+c1oJtq+k4FPfl/MKyjqpWHfXYTonDXLM2exJnqvw+jmWeSqRNo2aKA TseMxl3U5YcDDU03VXc4o3F1Vv+aihyIuzeFwA5IXN7v7OmOAL+mpHD1onOwSTa9h/b1 Tcn5KPeEI3Dn0Wus8JqDfA+LCDEdk9MIfEg5j+X5PzE6Zf6DOYIFfGC7g3k9T9ljQx82 YKf1aLprGNKPP+/ZiUT6GFbtlUgD/Kbe0biHaE/h4R0u+I99lPAnjXyCA9OqJqGzcE1b 82oY1cwxbbGPickDapC45ttCZx/plwuK+UWvCZ/gjecewSZLmOK7oynKkEqBBSZPcRdI /F5w== 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=7KiBKinq59/se5Zz8MzE1j0z1ZtQi/YZt6wlddfEVZ0=; b=znuHXUwYb6jIVcTN4Ewm4RAT/y2DioT7ns5DJedPYKk3uBaB2a2+rXzJQmvxoA5Dkg gL8Vof/NJlCY0l2qZqhLpehXl8Drz3AyxCY0IOtNJKoUA2jmj9l6swDGw/jur+m65AwI au7idxxj1bkNLWqdIHO4IVOrpLl0EAM4To4dbDbCWncmQuZlqsHMT5wk5D1yraiqBfXs QGJdJpGLn4cjpE4nU/DDS0oT9UWpmtcmsmQdEvjYgraIW2+E99plzH0wo14jKxhpP1tC 6jU1nfSg+jGyvVBhL4CfjNuk3JaPQ2bkbYU7uTEpvT4y0ohqN9UbISKFJYTnHaHGApYi GY0w== 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 r9-v6si17691993pgh.500.2018.09.03.10.21.40; Mon, 03 Sep 2018 10:21:55 -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 S1730296AbeICVjO (ORCPT + 99 others); Mon, 3 Sep 2018 17:39:14 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42990 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729700AbeICVjN (ORCPT ); Mon, 3 Sep 2018 17:39:13 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3961BD09; Mon, 3 Sep 2018 17:18:08 +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 022/165] usb: gadget: u_audio: remove cached period bytes value Date: Mon, 3 Sep 2018 18:55:08 +0200 Message-Id: <20180903165656.142748421@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 773e53d50e227b0c03d0bb434c1636f6c49c75b2 ] Substream period size potentially can be changed in runtime, however this is not accounted in the data copying routine, the change replaces the cached value with an actual value from substream runtime. As a side effect the change also removes a potential division by zero in u_audio_iso_complete() function, if there is a race with uac_pcm_hw_free(), which sets prm->period_size to 0. 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 | 40 ++++------------------------------ 1 file changed, 5 insertions(+), 35 deletions(-) --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -49,8 +49,6 @@ struct uac_rtd_params { void *rbuf; - size_t period_size; - unsigned max_psize; /* MaxPacketSize of endpoint */ struct uac_req *ureq; @@ -92,7 +90,6 @@ static void u_audio_iso_complete(struct unsigned pending; unsigned long flags; unsigned int hw_ptr; - bool update_alsa = false; int status = req->status; struct uac_req *ur = req->context; struct snd_pcm_substream *substream; @@ -145,11 +142,6 @@ static void u_audio_iso_complete(struct req->actual = req->length; } - pending = prm->hw_ptr % prm->period_size; - pending += req->actual; - if (pending >= prm->period_size) - update_alsa = true; - hw_ptr = prm->hw_ptr; spin_unlock_irqrestore(&prm->lock, flags); @@ -180,14 +172,15 @@ 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) % runtime->dma_bytes; + hw_ptr = prm->hw_ptr; spin_unlock_irqrestore(&prm->lock, flags); + if ((hw_ptr % snd_pcm_lib_period_bytes(substream)) < req->actual) + snd_pcm_period_elapsed(substream); + exit: if (usb_ep_queue(ep, req, GFP_ATOMIC)) dev_err(uac->card->dev, "%d Error!\n", __LINE__); - - if (update_alsa) - snd_pcm_period_elapsed(substream); } static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) @@ -250,35 +243,12 @@ static snd_pcm_uframes_t uac_pcm_pointer static int uac_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { - struct snd_uac_chip *uac = snd_pcm_substream_chip(substream); - struct uac_rtd_params *prm; - int err; - - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - prm = &uac->p_prm; - else - prm = &uac->c_prm; - - err = snd_pcm_lib_malloc_pages(substream, + return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); - if (err >= 0) - prm->period_size = params_period_bytes(hw_params); - - return err; } static int uac_pcm_hw_free(struct snd_pcm_substream *substream) { - struct snd_uac_chip *uac = snd_pcm_substream_chip(substream); - struct uac_rtd_params *prm; - - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - prm = &uac->p_prm; - else - prm = &uac->c_prm; - - prm->period_size = 0; - return snd_pcm_lib_free_pages(substream); }