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);