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