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: 357574 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp984416ejs; Wed, 6 Jan 2021 05:38:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyagdLJBzqO0OPL0o1RMyt4VISOLKtRNrh7iekcqtZhPN32YHKjMeJu0iqoGXHSWN+/mCMx X-Received: by 2002:a17:907:105e:: with SMTP id oy30mr2858806ejb.495.1609940292211; Wed, 06 Jan 2021 05:38:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609940292; cv=none; d=google.com; s=arc-20160816; b=YTFg7izKDtUBDMExmJ92XkcKqD/aRLzUqbskHoH9DTd1rqO3RbnNXfKos/vH17BfTK aj3GL/A+fYMpH3fMaMyG7xEtWnQOU91dKnR5pjVbYr0ICrnWxvCKCYSmaJIfkmyuy3xD aRvYNOzY2nhy6h549T3CGlhZfT7E3vwe4e9GpAdMMX6Y6ZlfGXiZFhI3QCqAQHFLt+h8 Jiep0pwMDo4AfB/e9FWf8UdQ4kTFfEf964cWAM3G+wIrV4zofMhC9vY590CB3WygNmj/ zzjQCJzfqErsY8l96PwWc7yXz6QCrEOPwWOhs03eCp/ck2xP3oTMuVOIynxDyN7KGEg4 +6bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mTKp7Q6ON2dW5g8WxlLxPPWuU/dM5NtfKl7JdpUhkyQ=; b=w++LqK/8LuAK5Hh95jcmHihLz3WIl191vgFjgKiYm4oTMvCPz5o7b0EJ7enB8WYL8u WQOPHpthiQni7Z1EZpjZUWsd53hcLir5LiCckw73XepSv7CmZdpMdmzOccTHZgjJSXOw 3PRNalCkFBGPVXsTSbU65G0dTD4btj20WlxZXDUjM8CWY4PanoHv7nLCZqkq3Ea5wgdi mmNB8WABbzIHlf0dIjQPoo0vvKV3oF+lInEZUSOceKgBKIDUad3zNI1AyblQ4JBNu9DI lMIsqvgUSmAD0Gmdo9bGmD2zclQ12LgK0BA9UQ5SoJZ7Ri9cNd3dQSKFQKSaEDsNakrT QX+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=tg7dAOXk; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb7si910214ejc.460.2021.01.06.05.38.12; Wed, 06 Jan 2021 05:38:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=tg7dAOXk; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726824AbhAFNhu (ORCPT + 3 others); 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-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 --- drivers/usb/gadget/function/u_audio.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) -- 2.29.2 Acked-by: Felipe Balbi 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: 357576 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp984623ejs; Wed, 6 Jan 2021 05:38:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcblxnp3p8ojxEt/4+E+Eru3TD0RWWwvPBc1GEDtK8YscwT1WFtxeFMc4rzKK+yUkUsyBr X-Received: by 2002:aa7:d642:: with SMTP id v2mr2826728edr.305.1609940309756; Wed, 06 Jan 2021 05:38:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609940309; cv=none; d=google.com; s=arc-20160816; b=sCD/uUYuenbk3/FWKcj3TsvUneDrUuBQkgb+usQg/M2scLsFAMomAuQC4BfbuRbLpW 8uK1FOz7sDam8PWbQ1ovu3fBKuXUJlB7hssR3BwMpMtzfEe2UDfK8dorqu2ahMois+hj h5hjhTFQKgvueb0c6s9kFiiT/jKWvCeqzQTXPT3vl3bc1lA3fLgOzr/rJEN3BtdhGQxF wOGZeDJoBadJPz32OGsbkfYykqui7lqZhUa2GcCptUp/gtg5lNU0tMGackkKk5NsjNMh U4zIhoZghA9LlIjs/QWvfdA7vxjmYVprh0B5GN/EtvRMP15AHq13Y3On6yvEi4hsiB6C A8sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UTSIWNrCdfFZGrfLRZuDMagz0Cnd73ZK/iAZinL3Hdk=; b=PTSa86W9+JY8Wk5zz+5CV375dOmA2bpq8jJHmqMZVBQBicqhss5aky0nY4NikYaVln mMlwum8apqfSwdfMQsJOiv5oPwZilscU+DKRqNuez8FJEhmbUkkslRVdTcaUP8Ht5LOI ImZtFKV8q81RXrXexBRvUU8Au0D4uu/0ISwNm0ZM0b7xno0p/hSOwVHGdYyC+OxAZwxM O0SdJZxUnFVTokePNjgqP1gm9ogwnUw3FIQ2UBlt8KamN+zuffNR+ha1QSwolRampoFw BLNkmc7JSahXHI6AgL1gwf53h+t6YC27avxLAdo4sk0a1bZKjt9xvf9WikOYIE4AC2WG 2cDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=z4y0UhlL; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb7si910214ejc.460.2021.01.06.05.38.29; Wed, 06 Jan 2021 05:38:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=z4y0UhlL; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727002AbhAFNi2 (ORCPT + 3 others); 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-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 --- drivers/usb/gadget/function/f_uac2.c | 69 ++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 14 deletions(-) -- 2.29.2 Acked-by: Felipe Balbi 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: 357577 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp985502ejs; Wed, 6 Jan 2021 05:40:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMnI+Bl7Dl9mQ9N7ku3OUHyCitAGX7FiavmdJwlWBBmXfvyRs5rnu1MK9MzrVK86aoqcOQ X-Received: by 2002:a50:f304:: with SMTP id p4mr3868637edm.118.1609940402113; Wed, 06 Jan 2021 05:40:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609940402; cv=none; d=google.com; s=arc-20160816; b=pa8jE38K0eApRiHmSQSYpTsd9L3YYCLrdd0aRbrScBuBwdg9jY4RLuccClWtWrhLQ1 jSIGqAWE7V3dbwIZ40rihvcNL14GgKPYLCRn4yt/80HyxgRkaeYlQKY8JZdIDUKdMipn QPqGvT0fG8Mo19An+XPZpHQP68dmz8eHfpu3/mnh3NKmN/Tt+NxejzzFINEBbe3PyP7O nZl6kNi2lv7OKSSVC2ISd3RvAiz3jbuvHKXnD9zPtlv/oqszNYj3OOgWkT0WjRE6V8S1 yOGwIyQ7dUQBaDfWrMNKDC32bNxIKYR1IAm5YXLhIGH1tZgHbnV+DeG8Jz/tK0ZWN61I YjSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EeqCcTaM9uvJ+oUlpZc6QqWpLGu/QRph3nZs6qZSs40=; b=X9gaibIAx8ZT7Lj4DeG/TaWyJIhcbcBv+bLaCR8ACD9OWbmAre3jbssrKOyqVYAA15 vKl4dG232FYFVNLxX6fThijcqPq/U67wUfEQRH7YXBn/0rCrnnNvRtTe1IbRlhZ5Am+6 U2c4kYvTL2jXmnwWoiZF2UASDNDiKzT73sIQer3Tr5CDw960HQ/f5dEzSGQcqca/H2KR v+TlFdW1b2G5BN2+dDV+XDYvoVsT+o8V5/+WaKLfZchM+t7/ip+htuFxUHSl6XysGwbU zF5J+NyInsHayhRK+REUjidPeFOlTw7j/C5DUrAlH+Ys3xc+vCeas65YVkab9CJkOs52 IjSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=SYg4zbGW; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si918262ejb.640.2021.01.06.05.40.01; Wed, 06 Jan 2021 05:40:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=SYg4zbGW; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbhAFNi3 (ORCPT + 3 others); 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-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 --- drivers/usb/gadget/function/u_audio.c | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) -- 2.29.2 Acked-by: Felipe Balbi 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: 357579 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp985520ejs; Wed, 6 Jan 2021 05:40:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy25GJoYv1a+RsXKvh9OdsRlhqSTLRzGr+JCo5Ik/BL524esCdsnNlpBPiCSdA+cta/GTia X-Received: by 2002:aa7:c492:: with SMTP id m18mr3958079edq.236.1609940403435; Wed, 06 Jan 2021 05:40:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609940403; cv=none; d=google.com; s=arc-20160816; b=pqJ9Z4xWGgJzppuFCLvNrc4N01S4dUl586jZ61/0PYco89Dsnu4JNKWmspbanzwR3u SYgUcwQnMTFTsinC5gavqSsco7W/I8HRmHTtVqdSNDWDHGNzjbWgRMAHI5m5LAvSVPxT 1tzy4pvhW7+362Eytik+t7LzNVx8H7i3db/EsEwMI30a0VVFARi1XBe0UXJkhkjrW7xA kucP5rQfbyWJuz2QIg3aFz7r1r9xxNO5Tmufovffmh1xw1q9kN1ThtJKDAnNOI+3WlB4 YZOchyp+UAEP4Xc7Z/qMGK7LKFZUVPC9CagZkYLm/gmeIYmEU2hfeUEISG4lLauLP6iM dv/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W9smjvmBrXS956ZqDnNmJ0jm4AV+owA3S3+oE2oCsDc=; b=PRdTs9SPKjr0B/xwzmEVWFb1RSVDh7p6wWGzJrE/IDjyG4O6cJj5p/Ehj+J9f2Uhqg y1MnYsMWfKNZhCB1VKGRAkYbB5znm1/fwdmYMGFzGkDi+0LJ1sql9TGBEnbG/yzNxH/e mN+voT1g/mriXOZTXRCKHCmeEK7v/WYS/axUd/UhBssmLwaY6349MdNLk8KPS6wh8eUx od3yVxdNdS9LzciYcW7i4+1CvBMUGydxofsf4TCMTho3hueA2Wr8kK9C3RCq85pTzo5E vi2I/EM2CNO/n95RnTgjBgeXLodbugPz9tP7N/yxMrhFSHlIJQ35hMbEHWn7mj4AwSW6 ymVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=mVLKEpdB; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si918262ejb.640.2021.01.06.05.40.03; Wed, 06 Jan 2021 05:40:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=mVLKEpdB; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbhAFNig (ORCPT + 3 others); 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-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 --- drivers/usb/gadget/function/u_audio.c | 58 ++++++++++++--------------- 1 file changed, 26 insertions(+), 32 deletions(-) -- 2.29.2 Acked-by: Felipe Balbi 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: 357578 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp985509ejs; Wed, 6 Jan 2021 05:40:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5jz93cahGp/F58qYETtzVqadE5v5qkpnb2Yus/MbhE52LtJ115ELCqqYca4Ib41tLv1go X-Received: by 2002:a05:6402:4d6:: with SMTP id n22mr4113432edw.27.1609940402471; Wed, 06 Jan 2021 05:40:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609940402; cv=none; d=google.com; s=arc-20160816; b=QuHM21ZfNwHKSgzTwefN6ys0e/6+B6jTOlupW6U6X8LNOlA/B0s4b98YtqcXGA/Enw BjY3yA1mYQtEV/ngcEwhLfQXSk2Hg/cqqa4jjNgFdRtQQ0zPVnXgEVfQ0h+J9Mdhhjoq gMPhk0SO4WoAFPYOAJ0ujhXo5O38UN5cfn+J2UNG59mObjbSYftKMFJ3tduvrCg5G9/Q WigJuGkM9cznU0gTpIVkjWllyxr3eNqjYKQ5WIDVsv2HSQ7Fd6H4aB+zjsUuOX6xmTuG vS/dyAssLLt0m0SD3CXjKz7gZf5Zekp42AxdYDVkl49Mw1v/s6mFitffw2SVi17etiyR n9jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jMFwjDy/Cb2t1FpYK1S0P8jc5Da5ImJmRl86sM+aIPk=; b=pDgxcxtMfuKH78cR2HNbSDhS4V2E71y0ch8qZnn34vX6TO5KUgwkgsOi/oi1Q7o0+s LKO7s4j9F4rKv/bXJSpmoA1RiWnIcm41pa8VWm2lKHHD8T6mszUqRaEa2QovifCI5i/e yT9m4Y/i61rHhYR4X/zUaOsMnxeCjfwf5lyZ1FV3bvVi1IkoMsq4hblhMRUk2RNdO6D/ 6ceKezepAojvy2AVSxul+P5wGGXA/Lfk1heqHpfI3CvtOwGNugnnSP5pm8ZFDPBmB2r7 aQJEDhqg30wXUD6DnqUSSt22IxzCrLdodJfpkawzjvNapbNOqfiWMNC9LKWOJsMeNpop vMfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hcw+HELw; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si918262ejb.640.2021.01.06.05.40.02; Wed, 06 Jan 2021 05:40:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hcw+HELw; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbhAFNib (ORCPT + 3 others); 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-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 --- drivers/usb/gadget/function/u_audio.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) -- 2.29.2 Acked-by: Felipe Balbi 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);