From patchwork Wed Jan 6 13:36:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12001641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82068C433E6 for ; Wed, 6 Jan 2021 13:38:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5451F2311C for ; Wed, 6 Jan 2021 13:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726824AbhAFNhu (ORCPT ); Wed, 6 Jan 2021 08:37:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726808AbhAFNhs (ORCPT ); Wed, 6 Jan 2021 08:37:48 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 442D7C061357 for ; Wed, 6 Jan 2021 05:37:08 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id c7so4403811edv.6 for ; Wed, 06 Jan 2021 05:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mTKp7Q6ON2dW5g8WxlLxPPWuU/dM5NtfKl7JdpUhkyQ=; b=tg7dAOXk4CYwqY0t8U52DZtiOl5U0NCSq3yA1LUuUEG1E8pNyB30rU35PWIk9DGFvU O4q1x6tqEv6EyeSh2neLePQgVjOD/oPoTBMAQd6TM8oZlFkvWYqu+b+rhu7Jv3mGCS95 MVuGunVtzjU+ci4mQe6zVySG6jfz0alNjuSNdCdNt5lLr+N08TYdC9zUhxMbccB2tjlE snW5RoUMvd5/ZpeW4DQ2ANsLcQy6NhXrmxTwh7fGZZrCyiWssFaBv+t4zCX3JFvnRtgD VIUoOCdUTqfDtsnD6es+pTFw8UptiXnP5OojO6DcDw/xN2WQhr0NvCwGdMam5in5xj1M OLkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mTKp7Q6ON2dW5g8WxlLxPPWuU/dM5NtfKl7JdpUhkyQ=; b=pTST+qSkARG9ZSrFFSJiFYA1B1tJsZjacWwHdyMkhXZ+E8JcoQwo6mhpJp/fKxNHCb GV4BQ1Wg5jEQwZGEJYIza2jrXoHooyu5kGsskdBZiZzH0vV7+hqft/NZa5VIFFrJyOux 08GqrOGaoLMOV7zZh6osRsiS59xkvs3JZO9Jst5uMljFigmt9Nhzasrz2WUV0HekCmJj CRlZBWnglPOaYAYBHOyzkmrSD5FIF0pcvkx0WhYDf7o3s78rKJpz6HOdDIH5Zppg4oFH yFnIVyD4r3OKH8Pc3F1uilF2dFWBIwzvepn/1qe25P+7nMKGgtr8M4oIbR4FbKBKu9Ko Wtkg== X-Gm-Message-State: AOAM530BiCj8pULlYedSojX08vPSNs1NvoVbQ/hpRM/bQ+REE9M87Kw2 HlgzAxeEkGsnGfCYSW13NbGaFw== X-Google-Smtp-Source: ABdhPJxJsn3ynxCdwwuAtQAgpObVIwXnASNQNPImD0uKNhZ3vTlasph4oiIihP2pnaIjq57WyrzwFQ== X-Received: by 2002:a50:e8c4:: with SMTP id l4mr3903622edn.337.1609940226992; Wed, 06 Jan 2021 05:37:06 -0800 (PST) Received: from localhost.localdomain (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id n20sm1259275ejo.83.2021.01.06.05.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 05:37:06 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jack Pham , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Ferry Toth , Peter Chen , Jerome Brunet Subject: [PATCH v2 1/5] usb: gadget: u_audio: Free requests only after callback Date: Wed, 6 Jan 2021 14:36:48 +0100 Message-Id: <20210106133652.512178-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106133652.512178-1-jbrunet@baylibre.com> References: <20210106133652.512178-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Jack Pham As per the kernel doc for usb_ep_dequeue(), it states that "this routine is asynchronous, that is, it may return before the completion routine runs". And indeed since v5.0 the dwc3 gadget driver updated its behavior to place dequeued requests on to a cancelled list to be given back later after the endpoint is stopped. The free_ep() was incorrectly assuming that a request was ready to be freed after calling dequeue which results in a use-after-free in dwc3 when it traverses its cancelled list. Fix this by moving the usb_ep_free_request() call to the callback itself in case the ep is disabled. Fixes: eb9fecb9e69b0 ("usb: gadget: f_uac2: split out audio core") Reported-and-tested-by: Ferry Toth Reviewed-and-tested-by: Peter Chen Signed-off-by: Jack Pham Signed-off-by: Jerome Brunet Acked-by: Felipe Balbi --- drivers/usb/gadget/function/u_audio.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index e6d32c536781..71dd9f16c246 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -89,7 +89,12 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) struct snd_uac_chip *uac = prm->uac; /* i/f shutting down */ - if (!prm->ep_enabled || req->status == -ESHUTDOWN) + if (!prm->ep_enabled) { + usb_ep_free_request(ep, req); + return; + } + + if (req->status == -ESHUTDOWN) return; /* @@ -336,8 +341,9 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep) for (i = 0; i < params->req_number; i++) { if (prm->ureq[i].req) { - usb_ep_dequeue(ep, prm->ureq[i].req); - usb_ep_free_request(ep, prm->ureq[i].req); + if (usb_ep_dequeue(ep, prm->ureq[i].req)) + usb_ep_free_request(ep, prm->ureq[i].req); + /* else will be freed in u_audio_iso_complete() */ prm->ureq[i].req = NULL; } } From patchwork Wed Jan 6 13:36:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12001645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CDF5C433E0 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D384D23124 for ; Wed, 6 Jan 2021 13:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727002AbhAFNi2 (ORCPT ); Wed, 6 Jan 2021 08:38:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbhAFNi2 (ORCPT ); Wed, 6 Jan 2021 08:38:28 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 453C9C06135A for ; Wed, 6 Jan 2021 05:37:09 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id j16so4468188edr.0 for ; Wed, 06 Jan 2021 05:37:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UTSIWNrCdfFZGrfLRZuDMagz0Cnd73ZK/iAZinL3Hdk=; b=z4y0UhlLkVRbZwM3AYQ8WT/PFQO5q/ewfILqGNVWDDSMNZ3Dr694H0d6AwNfgq+ISL FdSNQMMAd0pT0ZKv3rBEBj9s5p1d/TBNyPHUpQe0Z73m+HSZJAq86rGi4NbhDsMJmlBf xt32C+2TcJPryWI7lUZBIucFO8LIuFBGBQGsRDRpm4I5kF5Z1qFOC1XFeoC/PO5SHU3E 6M321HF23UdseRxzEJYX3DeJdDCy44rJgNUdxHrubStKupfWATezQ04igbAJekVSFdy5 4kwsTwcjTEWkozYqZZGv4hV3qMn5BMZyqBq8+5kIEKRWq90/NIyqM91iN5MC+ZvFokk/ CCbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UTSIWNrCdfFZGrfLRZuDMagz0Cnd73ZK/iAZinL3Hdk=; b=t6iy7sfNQYia/8jLcLsrtkgibPQ6Yxemu1o+Ezop9aC76bUYo9mTH2qcQv8AdRIovK nuczzFdfz7OMks5TRNr1TEFusclwMZJ5VOYPTMFto78dXRWVEPPt7RgCj+mRHj+aGOUb 3PXqnOr7ANR/dR78pmtQZERbaPAkMBTud8WSN5gVoYW+BPGK0S3hXsNRUntxeSXgZaeV Bs467WxIK2nxDYdMPRj3niUtBS7hFKC5SyKqZoTAMPTXUABvm8Fyqj69PsKuzsy1DL3V 76Dokrd6A+MW5asCwcoH7G/tS6kJPd9hiS3ITynplcPMITbUyu9vy4dioG446C6SnDei X3+Q== X-Gm-Message-State: AOAM532QexAkjOCkx6M87Bu0G6ahNUzGf0g0B+epoMSGIiUSM1/BdqFp 6M+r1kwO6VLFuV704fAo7D0cBA== X-Google-Smtp-Source: ABdhPJxTST/UKEVGGXaHxa8sUjQ9TOJ57dlm4hVgN3wyZhrouwJGt0HYUWmDq8U+NVaEhXraKxMb6w== X-Received: by 2002:a50:bac4:: with SMTP id x62mr3927427ede.59.1609940228024; Wed, 06 Jan 2021 05:37:08 -0800 (PST) Received: from localhost.localdomain (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id n20sm1259275ejo.83.2021.01.06.05.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 05:37:07 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] usb: gadget: f_uac2: reset wMaxPacketSize Date: Wed, 6 Jan 2021 14:36:49 +0100 Message-Id: <20210106133652.512178-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106133652.512178-1-jbrunet@baylibre.com> References: <20210106133652.512178-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org With commit 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth") wMaxPacketSize is computed dynamically but the value is never reset. Because of this, the actual maximum packet size can only decrease each time the audio gadget is instantiated. Reset the endpoint maximum packet size and mark wMaxPacketSize as dynamic to solve the problem. Fixes: 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth") Signed-off-by: Jerome Brunet Acked-by: Felipe Balbi --- drivers/usb/gadget/function/f_uac2.c | 69 ++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 3633df6d7610..5d960b6603b6 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -271,7 +271,7 @@ static struct usb_endpoint_descriptor fs_epout_desc = { .bEndpointAddress = USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1023), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 1, }; @@ -280,7 +280,7 @@ static struct usb_endpoint_descriptor hs_epout_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1024), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 4, }; @@ -348,7 +348,7 @@ static struct usb_endpoint_descriptor fs_epin_desc = { .bEndpointAddress = USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1023), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 1, }; @@ -357,7 +357,7 @@ static struct usb_endpoint_descriptor hs_epin_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1024), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 4, }; @@ -444,12 +444,28 @@ struct cntrl_range_lay3 { __le32 dRES; } __packed; -static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts, +static int set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts, struct usb_endpoint_descriptor *ep_desc, - unsigned int factor, bool is_playback) + enum usb_device_speed speed, bool is_playback) { int chmask, srate, ssize; - u16 max_packet_size; + u16 max_size_bw, max_size_ep; + unsigned int factor; + + switch (speed) { + case USB_SPEED_FULL: + max_size_ep = 1023; + factor = 1000; + break; + + case USB_SPEED_HIGH: + max_size_ep = 1024; + factor = 8000; + break; + + default: + return -EINVAL; + } if (is_playback) { chmask = uac2_opts->p_chmask; @@ -461,10 +477,12 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts, ssize = uac2_opts->c_ssize; } - max_packet_size = num_channels(chmask) * ssize * + max_size_bw = num_channels(chmask) * ssize * DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1))); - ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_packet_size, - le16_to_cpu(ep_desc->wMaxPacketSize))); + ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_size_bw, + max_size_ep)); + + return 0; } /* Use macro to overcome line length limitation */ @@ -670,10 +688,33 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) } /* Calculate wMaxPacketSize according to audio bandwidth */ - set_ep_max_packet_size(uac2_opts, &fs_epin_desc, 1000, true); - set_ep_max_packet_size(uac2_opts, &fs_epout_desc, 1000, false); - set_ep_max_packet_size(uac2_opts, &hs_epin_desc, 8000, true); - set_ep_max_packet_size(uac2_opts, &hs_epout_desc, 8000, false); + ret = set_ep_max_packet_size(uac2_opts, &fs_epin_desc, USB_SPEED_FULL, + true); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } + + ret = set_ep_max_packet_size(uac2_opts, &fs_epout_desc, USB_SPEED_FULL, + false); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } + + ret = set_ep_max_packet_size(uac2_opts, &hs_epin_desc, USB_SPEED_HIGH, + true); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } + + ret = set_ep_max_packet_size(uac2_opts, &hs_epout_desc, USB_SPEED_HIGH, + false); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } if (EPOUT_EN(uac2_opts)) { agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); From patchwork Wed Jan 6 13:36:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12001651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90545C4332B for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59D262311F for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbhAFNi3 (ORCPT ); Wed, 6 Jan 2021 08:38:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbhAFNi2 (ORCPT ); Wed, 6 Jan 2021 08:38:28 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E14DC06135B for ; Wed, 6 Jan 2021 05:37:10 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id ce23so5020215ejb.8 for ; Wed, 06 Jan 2021 05:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EeqCcTaM9uvJ+oUlpZc6QqWpLGu/QRph3nZs6qZSs40=; b=SYg4zbGWg3hS7QGGgC6xByH65gg9gDp3bagriZ4Qy2fVe4+8PuT8FdnWmdC+11XeQI bBKpAWPMsL+qwm/mLQ2KzrNLRrKWD468oOnpHN17cX0HFGV8JFmwNUIuDW+8pgtV/9BI onh7FoeC7kXzwF9w3MogcxQf+zmhmCEFyVYqG4E/+XNOZ0VtHQz/mQXB0M7jv7/bbZ+Z t+bcaqaBeh/vlFyjSHHfcho/j1La8TWGyjG0jnn0dBQN3OTz407pq+Umk+Zb0YOdElAk VQRCVFWg6+kioOAclDx89+7L/h4in3iLkJpE+lw85MzPMO7oH9BqlRw01yKtnl/gXKl0 +V7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EeqCcTaM9uvJ+oUlpZc6QqWpLGu/QRph3nZs6qZSs40=; b=eP4QbPVLjaErmlv5KmSMxHNZ/400/PkitEfPg2+eMcmytCol84JiLMOjzVcIAOjChr 8GI9ZbBXAV/Y/f3DMyEtxOF91uuT4l7s/kEE77RDHNrCmspOHu/FtloZSfkmiwdDD9aa hVdTYH7CkD4SdrsBwsF6+JkNZfTpudAr/TwfPQ1cp1sRZ5t2vhSgF49TvOxwz+Cn3CfR X2Ejo6i2qJKUkurKxIeTNK65WKsFjB2fFd8AXs2s8Ic/1pZtjfhts8JpFiiIiCexbbkK WbNRTQqi0y5glbdriXkR+ngikc1CT7QWwfak8jVKLcy/IjeXJJIWorzvmd7QzuW3uPz2 OqoQ== X-Gm-Message-State: AOAM532gr1HgWTCisWh4nIrQRwrXRgXPoxFzN4VLDE/hFMO0OgPTJpQ1 yIiMnPqNOvYRQbB9rWha1NIm/A== X-Google-Smtp-Source: ABdhPJwC9ki5CDdYpvYkHbirBbP2qKR4RcLxWRZRHQSIpcoH71TJ7ccWEfKFjVefbUPsSqgWGpEiEg== X-Received: by 2002:a17:906:4d47:: with SMTP id b7mr2798016ejv.420.1609940229125; Wed, 06 Jan 2021 05:37:09 -0800 (PST) Received: from localhost.localdomain (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id n20sm1259275ejo.83.2021.01.06.05.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 05:37:08 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] usb: gadget: u_audio: factorize ssize to alsa fmt conversion Date: Wed, 6 Jan 2021 14:36:50 +0100 Message-Id: <20210106133652.512178-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106133652.512178-1-jbrunet@baylibre.com> References: <20210106133652.512178-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Factorize format related code common to the capture and playback path. Signed-off-by: Jerome Brunet Acked-by: Felipe Balbi --- drivers/usb/gadget/function/u_audio.c | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 71dd9f16c246..045f237472a7 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -244,6 +244,25 @@ static snd_pcm_uframes_t uac_pcm_pointer(struct snd_pcm_substream *substream) return bytes_to_frames(substream->runtime, prm->hw_ptr); } +static u64 uac_ssize_to_fmt(int ssize) +{ + u64 ret; + + switch (ssize) { + case 3: + ret = SNDRV_PCM_FMTBIT_S24_3LE; + break; + case 4: + ret = SNDRV_PCM_FMTBIT_S32_LE; + break; + default: + ret = SNDRV_PCM_FMTBIT_S16_LE; + break; + } + + return ret; +} + static int uac_pcm_open(struct snd_pcm_substream *substream) { struct snd_uac_chip *uac = snd_pcm_substream_chip(substream); @@ -269,34 +288,14 @@ static int uac_pcm_open(struct snd_pcm_substream *substream) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { spin_lock_init(&uac->p_prm.lock); runtime->hw.rate_min = p_srate; - switch (p_ssize) { - case 3: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE; - break; - case 4: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; - break; - default: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; - break; - } + runtime->hw.formats = uac_ssize_to_fmt(p_ssize); runtime->hw.channels_min = num_channels(p_chmask); runtime->hw.period_bytes_min = 2 * uac->p_prm.max_psize / runtime->hw.periods_min; } else { spin_lock_init(&uac->c_prm.lock); runtime->hw.rate_min = c_srate; - switch (c_ssize) { - case 3: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE; - break; - case 4: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; - break; - default: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; - break; - } + runtime->hw.formats = uac_ssize_to_fmt(c_ssize); runtime->hw.channels_min = num_channels(c_chmask); runtime->hw.period_bytes_min = 2 * uac->c_prm.max_psize / runtime->hw.periods_min; From patchwork Wed Jan 6 13:36:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12001647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62F83C433E6 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AE2E23136 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbhAFNig (ORCPT ); Wed, 6 Jan 2021 08:38:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbhAFNi3 (ORCPT ); Wed, 6 Jan 2021 08:38:29 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD6CC06135E for ; Wed, 6 Jan 2021 05:37:11 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id ga15so5080761ejb.4 for ; Wed, 06 Jan 2021 05:37:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W9smjvmBrXS956ZqDnNmJ0jm4AV+owA3S3+oE2oCsDc=; b=mVLKEpdBbpPhnWhJ1Fg67spUEXzH9vbPYksVD5A9g/p8rNULEVaFO8Nsmntljq9aQ6 +UtH/0mz0Agr7If7rd4x5F/3hgGeuKqM5sYwE2OCWTX3FICeUSaN280NDpgsdt06Xg/G C3pO3I7QdP4S7HjdvbxwhkYEPo5Z07OL6Wflm4UEM1rS+Tiz9IPlB4LT4ztr6VhBxQmi 7JZHZzuh4etylydOc9R8DKvM6A3Rz6yYNTek8QxoHWqD9ee9PGTxpWgK+nUDHanleGHh Hwq+ieSkR7hBh61a6VxDzDr4RQBGGvTQNa0Ua2CDKlypGbSxCY92LdzrumcyyCUdUfuG de4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W9smjvmBrXS956ZqDnNmJ0jm4AV+owA3S3+oE2oCsDc=; b=agvL9KQuYiDbshLInuuNMWf4bGeUrPXnLXf7/zRF99eXsU82P1SxMkJwK7f8ZhfYrh 3xghDA4l7ZPEtm4rDD4+ixyhhz0aQv4j8J7Ngbph5mn52GHxM3IJCHGGHG7iGU7QIEr3 5Rt6w48rsRRzFdMyqT0HwrdkrM8pEkZ2mJSuSMHEsm5buQ/d0qlAlMOIk1lREEjtDfA+ kp/Z/cwoj+iX8yaRk4Lnk+wTsWcGNl5qgtaruGELqLeLSCqHFfdygoaj1LpQ3EilOKOB UgxkD2aWJs6kVyLn1m5v9tGCW+7o6XQGV4AHnoC1dgL+0lXGOnrRSAA+vgv2maY1DDl7 gRVQ== X-Gm-Message-State: AOAM531/PNQrHIYVfFE24E9LizyQodtv6t86KVbqdF6+66ScHESxDtG7 LTs1+1d+WLJrd8Hd9ELTbObEhQ== X-Google-Smtp-Source: ABdhPJwUM8ViGRlmjo3b0dkpWRCB0Qwg1XcWV/GSMOF6D4xI9X2ewpG8JuLaLBPqMjUL6Ji4CLKJ8g== X-Received: by 2002:a17:906:3b55:: with SMTP id h21mr2939265ejf.184.1609940230302; Wed, 06 Jan 2021 05:37:10 -0800 (PST) Received: from localhost.localdomain (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id n20sm1259275ejo.83.2021.01.06.05.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 05:37:09 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] usb: gadget: u_audio: remove struct uac_req Date: Wed, 6 Jan 2021 14:36:51 +0100 Message-Id: <20210106133652.512178-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106133652.512178-1-jbrunet@baylibre.com> References: <20210106133652.512178-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 'struct uac_req' purpose is to link 'struct usb_request' to the corresponding 'struct uac_rtd_params'. However member req is never used. Using the context of the usb request, we can keep track of the corresponding 'struct uac_rtd_params' just as well, without allocating extra memory. Signed-off-by: Jerome Brunet Acked-by: Felipe Balbi --- drivers/usb/gadget/function/u_audio.c | 58 ++++++++++++--------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 045f237472a7..1d12657b3b73 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -23,11 +23,6 @@ #define PRD_SIZE_MAX PAGE_SIZE #define MIN_PERIODS 4 -struct uac_req { - struct uac_rtd_params *pp; /* parent param */ - struct usb_request *req; -}; - /* Runtime data params for one stream */ struct uac_rtd_params { struct snd_uac_chip *uac; /* parent chip */ @@ -41,7 +36,7 @@ struct uac_rtd_params { void *rbuf; unsigned int max_psize; /* MaxPacketSize of endpoint */ - struct uac_req *ureq; + struct usb_request **reqs; spinlock_t lock; }; @@ -82,10 +77,9 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) unsigned long flags, flags2; unsigned int hw_ptr; 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 uac_rtd_params *prm = req->context; struct snd_uac_chip *uac = prm->uac; /* i/f shutting down */ @@ -339,11 +333,11 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep) params = &audio_dev->params; for (i = 0; i < params->req_number; i++) { - if (prm->ureq[i].req) { - if (usb_ep_dequeue(ep, prm->ureq[i].req)) - usb_ep_free_request(ep, prm->ureq[i].req); + if (prm->reqs[i]) { + if (usb_ep_dequeue(ep, prm->reqs[i])) + usb_ep_free_request(ep, prm->reqs[i]); /* else will be freed in u_audio_iso_complete() */ - prm->ureq[i].req = NULL; + prm->reqs[i] = NULL; } } @@ -372,22 +366,21 @@ int u_audio_start_capture(struct g_audio *audio_dev) usb_ep_enable(ep); for (i = 0; i < params->req_number; i++) { - if (!prm->ureq[i].req) { + if (!prm->reqs[i]) { req = usb_ep_alloc_request(ep, GFP_ATOMIC); if (req == NULL) return -ENOMEM; - prm->ureq[i].req = req; - prm->ureq[i].pp = prm; + prm->reqs[i] = req; req->zero = 0; - req->context = &prm->ureq[i]; + req->context = prm; req->length = req_len; req->complete = u_audio_iso_complete; req->buf = prm->rbuf + i * ep->maxpacket; } - if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC)) + if (usb_ep_queue(ep, prm->reqs[i], GFP_ATOMIC)) dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); } @@ -450,22 +443,21 @@ int u_audio_start_playback(struct g_audio *audio_dev) usb_ep_enable(ep); for (i = 0; i < params->req_number; i++) { - if (!prm->ureq[i].req) { + if (!prm->reqs[i]) { req = usb_ep_alloc_request(ep, GFP_ATOMIC); if (req == NULL) return -ENOMEM; - prm->ureq[i].req = req; - prm->ureq[i].pp = prm; + prm->reqs[i] = req; req->zero = 0; - req->context = &prm->ureq[i]; + req->context = prm; req->length = req_len; req->complete = u_audio_iso_complete; req->buf = prm->rbuf + i * ep->maxpacket; } - if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC)) + if (usb_ep_queue(ep, prm->reqs[i], GFP_ATOMIC)) dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); } @@ -510,9 +502,10 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, uac->c_prm.uac = uac; prm->max_psize = g_audio->out_ep_maxpsize; - prm->ureq = kcalloc(params->req_number, sizeof(struct uac_req), - GFP_KERNEL); - if (!prm->ureq) { + prm->reqs = kcalloc(params->req_number, + sizeof(struct usb_request *), + GFP_KERNEL); + if (!prm->reqs) { err = -ENOMEM; goto fail; } @@ -532,9 +525,10 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, uac->p_prm.uac = uac; prm->max_psize = g_audio->in_ep_maxpsize; - prm->ureq = kcalloc(params->req_number, sizeof(struct uac_req), - GFP_KERNEL); - if (!prm->ureq) { + prm->reqs = kcalloc(params->req_number, + sizeof(struct usb_request *), + GFP_KERNEL); + if (!prm->reqs) { err = -ENOMEM; goto fail; } @@ -587,8 +581,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, snd_fail: snd_card_free(card); fail: - kfree(uac->p_prm.ureq); - kfree(uac->c_prm.ureq); + kfree(uac->p_prm.reqs); + kfree(uac->c_prm.reqs); kfree(uac->p_prm.rbuf); kfree(uac->c_prm.rbuf); kfree(uac); @@ -610,8 +604,8 @@ void g_audio_cleanup(struct g_audio *g_audio) if (card) snd_card_free(card); - kfree(uac->p_prm.ureq); - kfree(uac->c_prm.ureq); + kfree(uac->p_prm.reqs); + kfree(uac->c_prm.reqs); kfree(uac->p_prm.rbuf); kfree(uac->c_prm.rbuf); kfree(uac); From patchwork Wed Jan 6 13:36:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12001649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AD06C43381 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26B2B23121 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbhAFNib (ORCPT ); Wed, 6 Jan 2021 08:38:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbhAFNi3 (ORCPT ); Wed, 6 Jan 2021 08:38:29 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7034C06135F for ; Wed, 6 Jan 2021 05:37:12 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id qw4so4967127ejb.12 for ; Wed, 06 Jan 2021 05:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jMFwjDy/Cb2t1FpYK1S0P8jc5Da5ImJmRl86sM+aIPk=; b=hcw+HELw6+n621TvSxRMA6A84EGzFGLBubtMuoWWoBQK2ra4z+kYXSgFsrJ9QlgfSO T+JoKmnIfj4coHADMramA+JIL0jAMfJMf66p6Sn/NZWj3+F/R7Ipl4iTz89qp97SbjRo lAXG4jYm9ktwhZAEkW7qCelPEQYbfE902wSYGOMXunoEzJ2dUgQSWUQEdRRHjvzLcvJ2 vSJk7cjLUonMBxS0On49z9BFvKtroadzDU9Iz2umCncnzZiX8ACBcBTmJo/5TYm8jTHU 7kH+G13texDDVEqoUWWgC2hRBXMoFds78AQsiynF3KN+1g5ap4lcbGVRD5oTFlKU4jgB 39ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jMFwjDy/Cb2t1FpYK1S0P8jc5Da5ImJmRl86sM+aIPk=; b=ir/MzBbmuxxwSN7riCp66geiZ3AQBExNL2ZAVkCgWNhcYtQT5/RNxozPgg93wF+bNK L6CSvS7Ea63uPzxe2xVKYMizS8qmVLjMzrOfxBbTKRwUbYngOGjb3eFNRH09CLZ2PV97 upt+Nu8FyVQ9QFR+ElPdP06NZo+30XUqvFqoZ535XDe0dTv2Ck77tXr57VfgffMxPv1v E6m0eLCLj3YnPvzhhWtBebU7LdL9CO9t1PT/0tiJT12CfIMesaa9llsiAfnxxdxOJ8ov wDisiWw/bQRqbWgGqXrWvEAm6aT5bVvMEMEHb21cOqRCAaQjy9Bo+TYyXA+7w0yhtpus 8XmQ== X-Gm-Message-State: AOAM530ugQUDEJU/hx8nv0owqShgpNEryjv2uPk3s8f5XVkiqQTnkYHH 7AV/dgIRQFVfAXmrilpF7XprzA== X-Google-Smtp-Source: ABdhPJzPjr2phle+6BlSN3F/cEU/QBwoLNEZacKP2OTz7iuHYHYfQv8QqRVdKmHF9oxvROZmevrfhg== X-Received: by 2002:a17:906:5f97:: with SMTP id a23mr3027841eju.128.1609940231514; Wed, 06 Jan 2021 05:37:11 -0800 (PST) Received: from localhost.localdomain (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id n20sm1259275ejo.83.2021.01.06.05.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 05:37:10 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] usb: gadget: u_audio: clean up locking Date: Wed, 6 Jan 2021 14:36:52 +0100 Message-Id: <20210106133652.512178-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106133652.512178-1-jbrunet@baylibre.com> References: <20210106133652.512178-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org snd_pcm_stream_lock() is held when the ALSA .trigger() callback is called. The lock of 'struct uac_rtd_params' is not necessary since all its locking operation are done under the snd_pcm_stream_lock() too. Also, usb_request .complete() is called with irqs disabled, so saving and restoring the irqs is not necessary. Signed-off-by: Jerome Brunet Acked-by: Felipe Balbi --- drivers/usb/gadget/function/u_audio.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 1d12657b3b73..e985630fbe6e 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -36,9 +36,8 @@ struct uac_rtd_params { void *rbuf; unsigned int max_psize; /* MaxPacketSize of endpoint */ - struct usb_request **reqs; - spinlock_t lock; + struct usb_request **reqs; }; struct snd_uac_chip { @@ -74,7 +73,6 @@ static const struct snd_pcm_hardware uac_pcm_hardware = { static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) { unsigned int pending; - unsigned long flags, flags2; unsigned int hw_ptr; int status = req->status; struct snd_pcm_substream *substream; @@ -105,16 +103,14 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) if (!substream) goto exit; - snd_pcm_stream_lock_irqsave(substream, flags2); + snd_pcm_stream_lock(substream); runtime = substream->runtime; if (!runtime || !snd_pcm_running(substream)) { - snd_pcm_stream_unlock_irqrestore(substream, flags2); + snd_pcm_stream_unlock(substream); goto exit; } - spin_lock_irqsave(&prm->lock, flags); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { /* * For each IN packet, take the quotient of the current data @@ -141,8 +137,6 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) hw_ptr = prm->hw_ptr; - spin_unlock_irqrestore(&prm->lock, flags); - /* Pack USB load in ALSA ring buffer */ pending = runtime->dma_bytes - hw_ptr; @@ -166,12 +160,10 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) } } - 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); - snd_pcm_stream_unlock_irqrestore(substream, flags2); + snd_pcm_stream_unlock(substream); if ((hw_ptr % snd_pcm_lib_period_bytes(substream)) < req->actual) snd_pcm_period_elapsed(substream); @@ -187,7 +179,6 @@ static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) struct uac_rtd_params *prm; struct g_audio *audio_dev; struct uac_params *params; - unsigned long flags; int err = 0; audio_dev = uac->audio_dev; @@ -198,8 +189,6 @@ static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) else prm = &uac->c_prm; - spin_lock_irqsave(&prm->lock, flags); - /* Reset */ prm->hw_ptr = 0; @@ -216,8 +205,6 @@ static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) err = -EINVAL; } - spin_unlock_irqrestore(&prm->lock, flags); - /* Clear buffer after Play stops */ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !prm->ss) memset(prm->rbuf, 0, prm->max_psize * params->req_number); @@ -280,14 +267,12 @@ static int uac_pcm_open(struct snd_pcm_substream *substream) runtime->hw = uac_pcm_hardware; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - spin_lock_init(&uac->p_prm.lock); runtime->hw.rate_min = p_srate; runtime->hw.formats = uac_ssize_to_fmt(p_ssize); runtime->hw.channels_min = num_channels(p_chmask); runtime->hw.period_bytes_min = 2 * uac->p_prm.max_psize / runtime->hw.periods_min; } else { - spin_lock_init(&uac->c_prm.lock); runtime->hw.rate_min = c_srate; runtime->hw.formats = uac_ssize_to_fmt(c_ssize); runtime->hw.channels_min = num_channels(c_chmask);