From patchwork Mon Dec 21 17:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 346425 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4666128jai; Mon, 21 Dec 2020 10:07:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsBrtYp7FfrJ4EHAmY8NfG8o8pvxp1Ox6yHCsIiCLkr/d0h8wx0kbgE7P1WlpnWfvWQAi7 X-Received: by 2002:a17:906:7a46:: with SMTP id i6mr15966669ejo.257.1608574040779; Mon, 21 Dec 2020 10:07:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608574040; cv=none; d=google.com; s=arc-20160816; b=SyQNhN9ExeU6+V/JaAtUYs8K9Du+5/wyn/sUdu/q8B9EQ1Q697LwSB+wo0/Xndm2fW 0btJXM3rWC6ZfzPbG8citmRqODvrlizzYgT41fgrzZZ0aVjqytBXeKwIdNYIbrlIZC6X NBSWprFTUtfRvE5I474+fgkL+qjPE8wxZuyQZmeyPbW6ckIh1KeFehPzQtvoAz7Tv66k MJ/IQCN2Z8aaMfmBf7yeTJryGvnDnjtGAaTBH0ZCUZvIPtzHjwf6Q6trdGvNpVM2qHhM 5KOBE9pr6TtoO+u5ry9x4RkFjQe8qI7PDv294Fj6K77rfU/7/tri+T1efwcauKqhzjOt vfBg== 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=mMIbWvcShJRk5o13JXPsj3tejpC6Es7++52ga52SCjEEbWwihDlWUJ8807VzYqH6sL f2YE8dvlFu0autb+x57iXaD9JR80RN7t7cwepx6CETBMdCr+ccrHx5k4HrWMPHkO+oSo VVPjcLmcl56PJv7V5EnUntT4/kLtY5/XPZuoz8sHiXVUau9nAor9Eyox4EEjCHrAS9Mh m9siJ2bPOrDzWKt0ZtYMQsLnMMjhYim5dp4mpStMPBZDgTU919JOD+FsP8IfmxAVjvwc /spqQERRofwFINW2k4dlOByt0C0t15FCaAqCdaiRgbN8SPVzDA+a2zfHVe7mJl5dF4KP rwWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=HFwFklBF; 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 h24si10148228ejt.583.2020.12.21.10.07.20; Mon, 21 Dec 2020 10:07:20 -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=HFwFklBF; 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 S1726573AbgLUSGq (ORCPT + 4 others); Mon, 21 Dec 2020 13:06:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725930AbgLUSGq (ORCPT ); Mon, 21 Dec 2020 13:06:46 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC9FDC061793 for ; Mon, 21 Dec 2020 10:06:05 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id o19so25892478lfo.1 for ; Mon, 21 Dec 2020 10:06:05 -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=HFwFklBFejfRIGWkA2tHTHhTKeW2c1LNBGTqxXTKD8QsawAuLODDYMDiuRMSFan+Wm 2rKLN9+sFiXkjIMuxnrl7qH6x2o5G7XG5WNuNvEZjd8hgK8AV3mWH9yCbu+f7C3nn1Qp p1v8v+XYry0BSpgjoRfQIe+M3AyEpCLKrkkzwGR1oCndoh1xWPKmlmvKZhvvoHEbHoZ/ JyTTI2eYgMghTdci/REOKrK2r/LfuBX+gmEwdHYZ7tTT8kxocXTb4Gf01aHgSotTTdE1 hAsD/tagSBGz7mxfgE3xNyotXr7+t1E6zzx1s+2G2unQvXEt07vAx25PyBwuCVaKB0ND X+zw== 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=OPAwxOdF4/lSlfR8GCEBR3Ddv58CPtwY+uV5UwPIuLo+Z77H705QlK4H0OolQ5bZgv 21ft6AXd/wCSsA0tbWDJ7yN/GxdgVvY46XUUftiK/u6CbkIpoE9MaoxfrFeK1MfYTYNs CJ7wmakDUi1NMRQsyWBVcRWNp5pOs40kBvAGy1Q1yZeKG8lydwe+7cEGYByncGObL8Hk FM7vAwodXhZi+YE78cJedYH9u/kW6qebV+Vb+/4dG9/V3co1bYdHq3GYpdzRQxNTpggy oPdgE3IDSb1Ea1pNN7vfeqdcEUaGltHOvl3bmo9N7ajlOJIXyan0cAXbRJ50puS0wleI 4g1A== X-Gm-Message-State: AOAM5315DABgStClWaVxoadGT8+YDIIptdYYnt8UUBukq8lvPemMMfP7 jXEO28SIpj1qHYAT/pa3hyahZvqvKNt04WZk X-Received: by 2002:a17:906:e247:: with SMTP id gq7mr16632490ejb.27.1608572141971; Mon, 21 Dec 2020 09:35:41 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id dd18sm9338408ejb.53.2020.12.21.09.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 09:35:41 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] usb: gadget: f_uac2: reset wMaxPacketSize Date: Mon, 21 Dec 2020 18:35:28 +0100 Message-Id: <20201221173531.215169-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221173531.215169-1-jbrunet@baylibre.com> References: <20201221173531.215169-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 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 Mon Dec 21 17:35:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 346427 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4679121jai; Mon, 21 Dec 2020 10:26:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzjXBoFL6bvc8VW3+ZmmXnZ3B8jk9pjYlmvVATsRs+GPWXO5v1dhU/0/xrWecZZ32rTlCu X-Received: by 2002:a17:906:eb5b:: with SMTP id mc27mr16354268ejb.163.1608575174098; Mon, 21 Dec 2020 10:26:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608575174; cv=none; d=google.com; s=arc-20160816; b=yNkN5VO/u6qStBigUviSM/CrV/Z6Cy9VabdsP6qKi4feXLSwIDJuChIYZi7yfrw7KC zNg7QRcQsgLET/fDxCmrfAt7WwnINwgrs0mrfSRE02nhfa7GYC+mbB8T2UCn7IbW76YH 7M3sbS5C2Evlj2uwfl0SuvXer8UPup8ERuwJmEUA03+aJhx4afhnSC7k8mEFykmE4PxK 2Yhgccth4KDB6AQHCJyaZiXJf+m1dPfQKr80D2Drq5G8l+DkFAsB0tMIiOYG+jurahrQ jq1ZkUZb6zxqscJAkQcezoglrfCn2h/Uiqah8ff3gvJSZBan/48QigO5o0XEtSHucRe1 he9g== 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=nk1WbTku/ptwimEpWVF9T+Es0gLNCmrcP2x+3MKG7iM=; b=AQyO6C/K6L/vEBkOD6YR2BFsiv7YjMVpkGyrSO/vhLLVjK6MRWBuUFL4mpCUREblz8 ayTyre3HPWEVhP/MAZuNGlJcC46QJljjGU+Q2wbNy13+v9iHtRehDh7IvrzLH8TqmVFJ 3KMEKqyDSx1k4SBnjww9kgLi8NitoQdABW3Rrt9TBKMbWj1IhwoYNLWRvhqNgUM2yVfz CI95/TTB9I9bVN8Yy0s69+BJU5VffbrZWNC10qXhpJsRtcmPw8lZgy447E9kkxbevfbK 82CdPBjyaHv0K2wPC+/twj2Yq+q8XVLawDSh9sCf1GZE9wBlWZFh7cxK12Tx8YV0Csmc gpeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JOeMsmrM; 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 dt1si10825512ejc.558.2020.12.21.10.26.13; Mon, 21 Dec 2020 10:26:14 -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=JOeMsmrM; 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 S1726188AbgLUSZg (ORCPT + 4 others); Mon, 21 Dec 2020 13:25:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbgLUSZg (ORCPT ); Mon, 21 Dec 2020 13:25:36 -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 E32ECC061285 for ; Mon, 21 Dec 2020 10:24:49 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id b9so14827025ejy.0 for ; Mon, 21 Dec 2020 10:24:49 -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=nk1WbTku/ptwimEpWVF9T+Es0gLNCmrcP2x+3MKG7iM=; b=JOeMsmrMEqBux4BNP1j8g04oh0OzDgap7eVMEvDocXqACKFHd1t/rBIJ6RZvaHFE2i K8LYMk77pPBkHpLMbeCIx8VCOUujqfswqenZw4UNX6X7Dh2Pi53dbvmazJ0oxf81dg3t wM7nmbhAhodkQr08hkGOG1sE1gzJXdr4IxSCN//ZxoALzdZ70PY5w5BKG0/0kZ+pg4Cn gYfBETlB2MKucmYgUEohEIW9LSpz4naKpk6uuc8ssXjZR6N/oBIE+LvgN9NXW+m7vchU ZLMPmsC60u/YO1xDP14uN7BrAm+kir6WgHB4/kPyNXPU3DkJ/jPrw85UZDZIpwl3JCtK MHpA== 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=nk1WbTku/ptwimEpWVF9T+Es0gLNCmrcP2x+3MKG7iM=; b=V4sjiQn/a4Ha9jRvVj6aaA/KNOPY1AjOnswhosPCUJGOQcPFuuhCmslWZDS8neK8ar DxZJAS0KxETZLKYvyI2Biekwvci3rXfqhjAZqzQ+BERoV2763kGNfm9s9xas+ipxkjYq GKegZ8Un5gp1SoBIFWBGFrU8Wj+YDEFPo4VFTxPoVvGa69aDiaNtA3tS6G9ZqIBonZ0X HYWm4fuqcqZNxDbZ3gEaO0BjnyR8uotny5tM5lEXbtpw0wBD0Wlf27bKpkkISfFgyQVv w9I05qVNlBHqrUJacFSY+BW7NE1+ZM3k3UBbYaKZXQWtDAaAH8NIQWj0NlJ27BZkam2i GuMQ== X-Gm-Message-State: AOAM531eOPMLTdcbvsaTqJP7Hen82F7O0qiuY5fnDPeaeiENy4MDiJGf CDsWWxPTZ9S0tidxKtPzJqEcgPlcRWGIJs1P X-Received: by 2002:a17:906:ae0c:: with SMTP id le12mr16500568ejb.283.1608572142949; Mon, 21 Dec 2020 09:35:42 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id dd18sm9338408ejb.53.2020.12.21.09.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 09:35:42 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] usb: gadget: u_audio: factorize ssize to alsa fmt conversion Date: Mon, 21 Dec 2020 18:35:29 +0100 Message-Id: <20201221173531.215169-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221173531.215169-1-jbrunet@baylibre.com> References: <20201221173531.215169-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 diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 71dd9f16c246..2f69bd572ed7 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 unsigned long uac_ssize_to_fmt(int ssize) +{ + unsigned long 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 Mon Dec 21 17:35:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 346428 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4687415jai; Mon, 21 Dec 2020 10:38:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJHrBVgHjiaClWSxM1W4E0BuQXYnYZykUbcEV9+cl6I5jZDMShUWUE+8l5mcs8urlWfx0Z X-Received: by 2002:aa7:c403:: with SMTP id j3mr16818724edq.217.1608575922213; Mon, 21 Dec 2020 10:38:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608575922; cv=none; d=google.com; s=arc-20160816; b=OtMxXvOW6afaU9WaK8+yAkgIClJEet89ND1Ys3F8wbcYSsvO8kKdvRnBKI9KtNJr61 8uajoarVwvpo2U15P9hBeDX6vFq2ytV7Jg1/2ilbHD0iA8D1K5phbd6/ZUq2QJ85GUk6 i7n+mxv+CUfz9AhsAwV0Z8/LNeIPU39X62y7Dvtdsp1hG8aY03MeUZvUepUDSzZDljIK 9WuqiFNPx2v4LCasF3CxPDHQvgSMmeMqv+V5+pGvKg3/Rfadd9oBeINR9Al4MUpk8gjl qFWhJCLwKdoPzL+TZY3/wqMc3Kq91GbQCK9RBFwWN3spGLxG/pfmVIyTXCJxbJdyRSuJ e0xg== 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=Wsch7K/Hnn/3Wb4xvUK2cOpHQ53+sfVj7evWMdQyT98=; b=zzOMJ+Zwhj8zftnp7p5kE5KLBBrVThXUjGZSaCxdcBPbxgkx2X2vD80ytECYfbyzkn U0xKlMvBG3WXZwtXBbPyFxP1sDxCdxu+qxhhd+qKexsCFRgiNPET40GNA6kRwviUS+HE 6XtjWwm2dMzgOninNDEwITTpBEl57I+BiA98PCZn9lDLfiV/6g4+F7NJjzGBLkR8hwrc /xzVEkyCmp1I2wnRcJeYaF8T8IYjAl+iEX4atVoCK3ImHp9bG/p86vTYT4wRZVUs3dPO 3yHVUP1a/gkFUcCe+vv+AY5M5rJFtxqO4GYYkdOhdwyMJrfoktZzm/uwy+Yf5kUSH8Cj sbFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=aGhyvuaP; 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 cq5si10939860edb.200.2020.12.21.10.38.42; Mon, 21 Dec 2020 10:38:42 -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=aGhyvuaP; 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 S1725957AbgLUSiV (ORCPT + 4 others); Mon, 21 Dec 2020 13:38:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725785AbgLUSiV (ORCPT ); Mon, 21 Dec 2020 13:38:21 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B2CAC061257 for ; Mon, 21 Dec 2020 10:37:40 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id b73so10497804edf.13 for ; Mon, 21 Dec 2020 10:37:40 -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=Wsch7K/Hnn/3Wb4xvUK2cOpHQ53+sfVj7evWMdQyT98=; b=aGhyvuaPGOshy+8ymjZ9e8lnLphr2xwunbCdHxbj/jpEqkyvDj2GCcvQOZTqvdmN34 irF2+k1CW0+yZFna3nfQkfGX1HpCw20fc8gado+okBZDLs2J+0COsc5d5n/gyCQZCgVT aXuHHseKJAZkrKsITJkLbSjPtJ8sExFc7rFZ3zD9tiqg5Eony51rk1/fSIf66chYUvb4 6PQRBH74scYOFrEfY1yoRHREH1K6Ib+Pzh5qZNtdOet+w8F59+VJjfakp9LdDtam9lj2 B4rQtNUsIxVpisd94050zPUeqMML6RqINs5GuCvp+igA9aD7EvDVwIQ/oHrb+ldSMo49 FT2Q== 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=Wsch7K/Hnn/3Wb4xvUK2cOpHQ53+sfVj7evWMdQyT98=; b=Tu+SR0mMgUTkbPWpp2WMn2yjV0FeEUdq4PwiTBHrcj1Ps5xueDHbbc8yALZJI5Uzye a2aefe+sEbJbK3kOh0lMDCDa9TT8DQKpJ1VRmOQl/sb0IPC0/0jY4+sVo5pylYEdK2fZ n8KCd/pONuHqg4YFiXxJySwMcta85mnlP5bLOLmdaKBaNgX5wYDSQaZF4UrFNo/5e9dB 4JFS4k5kcPVfYxuI00tiUSY0iUrvGQZHfI5NDKDY0Qyqdtg3RrelgCmBV0VvtsXM4eum UxrRcRfW+D7nwFLxUtZyIIrxH3mQv1vVJ7lOnAgwvGWt8FlZzO1xVRPIVyhnrfFTICqQ qRzw== X-Gm-Message-State: AOAM533C/ySfhWXEOzw1osYb6gWEA8B7dNCCFyzzWKl5W/ICsYOsFLFs fiAzWtZjwrptUR2JSA3i5F0e8TJGefoFWE/Z X-Received: by 2002:a50:ce13:: with SMTP id y19mr16994613edi.241.1608572143950; Mon, 21 Dec 2020 09:35:43 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id dd18sm9338408ejb.53.2020.12.21.09.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 09:35:43 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] usb: gadget: u_audio: remove struct uac_req Date: Mon, 21 Dec 2020 18:35:30 +0100 Message-Id: <20201221173531.215169-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221173531.215169-1-jbrunet@baylibre.com> References: <20201221173531.215169-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 diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 2f69bd572ed7..3eba31b8ebcb 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 Mon Dec 21 17:35:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 346424 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4666036jai; Mon, 21 Dec 2020 10:07:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbWWThLJJHXJvgtMMAXsHkgYR8wwvFKhQ5CiR3B1EuGrC861fERNiFwyETUbtkc32Ftn/a X-Received: by 2002:a17:906:234d:: with SMTP id m13mr16581742eja.270.1608574034248; Mon, 21 Dec 2020 10:07:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608574034; cv=none; d=google.com; s=arc-20160816; b=QyTeAayY0pHarBSsHJmg7J+/Bp0xnQOAvZFf0VvyTkLcjBLORWXCluCbK/jxp7H3Cs HyMYy6p+XhI3Cn7RxGPXJwPBc5smsFii8hfnAodB4MbQrbklTjnIX4YLRT9e4l5UPSuO PyFgrWi8+cIhFdXYyzzYxnqQKeut1zJyCuEvFRTL/z51Q+GBllyKEslJos4/vitOUNKL Y1fpds8YL/t+AKC0iwE3+z8qirIlw1yXQPqaJzUK2+u1ZqXkSzxtx3jYGsS0aL4SRUwu jK56JCZsvb49F6QojkrePwaT/ftsypsZcF3S7/8IGROJztDxwzdl+3SgZxhVF0RkY784 mFNA== 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=jskPg/JNftDq6XGRLoJGmRDxx5qATPuCeD9qSRQFjug=; b=BYyB4vSBWIpuZb6iu8RK/j5ryqFULV/bd86n6elTnDv4YlbSpPRzVeiL6x4VCfkv2Z omvs3fwo6yQ8ibTwqVvVDuIJNCYNoJwM5m1G4jx2iutKzUEZNXtdTsuwJRbezY4kNdqy 1nkCEMaU1yCwco0qTY205BiQUx1Bz+4WdYaeHMKGDoNtT4Dfb1s+rMD81xbeMjoGBB6+ eXcK7eyiNHYGVkd6WptFJGWY14PtMAmNEB7HDzrCcJinn1lrCRF3Qk7d3/vn8tDpRAKa yI4lNqF/egj3gWVxDuXbgTTkWT54UhXNdZHblfWfGkV+cFii6X9Spkdrm7Ly+G6615xK Xd5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=HFj1AGT9; 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 h24si10148228ejt.583.2020.12.21.10.07.14; Mon, 21 Dec 2020 10:07:14 -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=HFj1AGT9; 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 S1726012AbgLUSFi (ORCPT + 4 others); Mon, 21 Dec 2020 13:05:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLUSFi (ORCPT ); Mon, 21 Dec 2020 13:05:38 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F058FC061282 for ; Mon, 21 Dec 2020 10:04:57 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id j22so14642669eja.13 for ; Mon, 21 Dec 2020 10:04:57 -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=jskPg/JNftDq6XGRLoJGmRDxx5qATPuCeD9qSRQFjug=; b=HFj1AGT9hr83R33/pq3M9sZqzZboMYoDL/RrYGKB3LRz4TMVZDhjI63rlO2Nz/EVyM U41AgCq9qRnaYXyxAW8LFLev5ndgijD6e+xObtmPU3CBF2K1UbovnT6hUS91ekn4HQMR KYfyxYTSUnz0VlZbvcBloy0yRzUfrsvBT2A784juRtbCJjZ0LT+xUWLZFP29189KLSWZ RNuZs8izX6Rh3YFzruI/b0nwMuUhl9w16gOwczBFWXtbKpybwX/0mWut3FkdeUBFQh9l 6u3pGhALYxb0WXjY/j0uWgfqtQl6Rd6fNTi2nwMmVVjNf7Tx9z1DD3I2bYVSOU7yoHMv CEKw== 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=jskPg/JNftDq6XGRLoJGmRDxx5qATPuCeD9qSRQFjug=; b=J13YceAUoKYhej3ccFlfRAjvitfOguYWX23OGAJL7KzEqTe/kwqQnbtmef8GxtF0oq NBcYbFqfolhsV8MIvEBVgtj+9J1fTO/nfxdyk3Hg9uF57u2tu8/21E31X2S1CEcngRYw eXzLq4Ucoi0RdMoeeELIcu5FoQvJ8LOdgg4tngRWtgOYCsYigaoajIe21FphTzSTtrRx ObFoCoRtjGxsABiuMTTLrCdS+PP1Cpug1pggjO7wTi0KUENcNzS9jmwwAYSZE22I4gm/ V3D6S5otMvGrbZXPVwn4F+2vahi4jD3sczTKVh4EEKV7TVDPC6tcGjutyXJ6D5EoSXyx LnDQ== X-Gm-Message-State: AOAM531je2E3mwIQvJEu1SnYYn2ShSv7rNhesHLIXS/rkA282d03QyGC dr4jKdEAJAC4c1i4wsFEaWOA4jcDM7oPVYlX X-Received: by 2002:a50:eb97:: with SMTP id y23mr16939005edr.29.1608572144956; Mon, 21 Dec 2020 09:35:44 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id dd18sm9338408ejb.53.2020.12.21.09.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 09:35:44 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] usb: gadget: u_audio: clean up locking Date: Mon, 21 Dec 2020 18:35:31 +0100 Message-Id: <20201221173531.215169-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221173531.215169-1-jbrunet@baylibre.com> References: <20201221173531.215169-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 diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 3eba31b8ebcb..d94f95edca40 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);