From patchwork Mon Jan 18 08:46:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 365490 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp2060468jap; Mon, 18 Jan 2021 00:49:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzm6lXLNiZ3RK/HLPZWx5psB/tjsxlFRXD2yJx4aHu2xHbqtZIEWxgGP075z3e4htH2CLbl X-Received: by 2002:a17:906:3792:: with SMTP id n18mr712996ejc.47.1610959759212; Mon, 18 Jan 2021 00:49:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610959759; cv=none; d=google.com; s=arc-20160816; b=BaMpE+8bJL3rkpwpMtPrCgBxRMhNy+NKOThSKuUtYUEpfmOBMqqwutQqc1X6NKdMfk 3nRi7Aa2V7j9t+G25LraK4pJtYH4H9JgiX5YG3U2dvhKCmjAdGyMaRVcH5gTYOHoUkU9 908RuVNkenpGhg+YjxVX9K8oSUO5elBVjj4GHHVzZKHFpwJMqOwErgQkYRu1o/+GGBb6 NtGGrH/Z32jEBIITPkSc778n9C8NEirGWlAmeWqe5WJh9Uj3sAUZB8yzDB3zaG8iTEsV 2YhtaGXoXo1K8p1MW5MULYL6hlMkF7PW5bUY2hchjco17WZYxYQUTXWy777L/2KaTkzb i79g== 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=Sr6l15TWUkoLpe2YUMRX8nPBc3XsL3PtVca29QVV2RU=; b=vk3gRaax0OUeDYEpw9fIcd/JiR05ZXffUCe884M3GISMnB9DJ5GXf6ZDYDIgNeH74m 0nXVu7HLdRsKJBr3Y/4r5hpoQyivhMR3z4IV5xyvetzQ7VhJSyuzskV7axSKKLEUE6wb bfoFD0CKXD0ogYcEv++Eg0pMqSZChHbO445MIBHS+HHDKgIiB1zuTC0vZCffSOOyOAkx HFNoJtqY2aO+pIPqvl7LFabSIDPX3nZZJnrhqWR8qshGHaiUbaR0k1JB+T/Oej6+W8Uz VP+kpEdHU1rFujWBtUdjJPSvmeDGtPkK+h0xwhUh+qtcXju9TprOuVQLcQMgAIb2buOO Ok1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=d1wWOpKt; 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 t14si7889997edd.161.2021.01.18.00.49.19; Mon, 18 Jan 2021 00:49:19 -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=d1wWOpKt; 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 S2387999AbhARIsh (ORCPT + 3 others); Mon, 18 Jan 2021 03:48:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387977AbhARIsZ (ORCPT ); Mon, 18 Jan 2021 03:48:25 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48971C0613D6 for ; Mon, 18 Jan 2021 00:47:06 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id v15so11938591wrx.4 for ; Mon, 18 Jan 2021 00:47:06 -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=Sr6l15TWUkoLpe2YUMRX8nPBc3XsL3PtVca29QVV2RU=; b=d1wWOpKtxL3bQFme34xvxo9phvPySOvA/REPdrSa14GAR33OV+e1KcU73HrjkYNyJh G6HARgNhlDDZ0bxFn3Oa3LfCQxoXHrdndaxkFFQnkcypuSnt6wOqThsFffQ309MC7w+u o7zhxp94hZ1y3B1UJq7W3cfscuT6NxIfVmuLHjfQe5hPmIbXcIvLPmozeQ/oj5L1EDcP GDp8a/wdSIV/iO0Mpeo07Zasw+kfL+tijj6VlxELcrcoJlTQiBWBcoO0ikSF7JfqVDsD mP2nUCi/361OhHiMh4fDVUYWUd8cQ0pEYBdQeMhYsiuMKHV0J9bOd/oDsQmr1JhF64f9 xpqQ== 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=Sr6l15TWUkoLpe2YUMRX8nPBc3XsL3PtVca29QVV2RU=; b=bWF1blDTcHXKyWeNgrFQ4xBEuXLS2uIQlLmdkLhMyI3O2yWmXYW+wt4x2AtZyuElrZ BdFWPqQqQbieI3rhe/yu2lWUJfmvQ0Kidhrxpw76agUto4L/dGVt3vxaPtRFt7cV+qX+ BcxNNBm+SIfAXei+hosQ+OAhOcMcUqsIUtwABUgoo1uhSVwsH8lxmfJrXP3muTmm5vqa Y6FeD+oyq07DzV4p3eX6rFcFo08jlIRea/PhEnlj6g3PbPu48HloHj02IdSzFJcbVyeP T8vah63hvZuHQkI5+eE1W1sOkzbGQc3OiUThJRn4lAFCDdny2RIHrvqPMTCHYlwIozhH JOvQ== X-Gm-Message-State: AOAM530Omsk0TvCKkclBMA7p8kl3EXKoTeE43HpMTTsD6QlIY+j3BOfT 2Pw+/yJxKiYPgI47ur4XuK6ISg== X-Received: by 2002:adf:9e47:: with SMTP id v7mr24337382wre.185.1610959625003; Mon, 18 Jan 2021 00:47:05 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id y63sm26224518wmd.21.2021.01.18.00.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 00:47:04 -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 v3 3/4] usb: gadget: u_audio: remove struct uac_req Date: Mon, 18 Jan 2021 09:46:41 +0100 Message-Id: <20210118084642.322510-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118084642.322510-1-jbrunet@baylibre.com> References: <20210118084642.322510-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. Acked-by: Felipe Balbi 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 27f941f71a9d..a1a1f4c8685c 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,16 +333,16 @@ 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]); /* * If usb_ep_dequeue() cannot successfully dequeue the * request, the request will be freed by the completion * callback. */ - prm->ureq[i].req = NULL; + prm->reqs[i] = NULL; } } @@ -377,22 +371,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__); } @@ -455,22 +448,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__); } @@ -515,9 +507,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; } @@ -537,9 +530,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; } @@ -592,8 +586,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); @@ -615,8 +609,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);