提交 29865117 编写于 作者: J Jerome Brunet 提交者: Greg Kroah-Hartman

usb: gadget: u_audio: remove struct uac_req

'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: NFelipe Balbi <balbi@kernel.org>
Signed-off-by: NJerome Brunet <jbrunet@baylibre.com>
Link: https://lore.kernel.org/r/20210118084642.322510-4-jbrunet@baylibre.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 25dbd75d
...@@ -23,11 +23,6 @@ ...@@ -23,11 +23,6 @@
#define PRD_SIZE_MAX PAGE_SIZE #define PRD_SIZE_MAX PAGE_SIZE
#define MIN_PERIODS 4 #define MIN_PERIODS 4
struct uac_req {
struct uac_rtd_params *pp; /* parent param */
struct usb_request *req;
};
/* Runtime data params for one stream */ /* Runtime data params for one stream */
struct uac_rtd_params { struct uac_rtd_params {
struct snd_uac_chip *uac; /* parent chip */ struct snd_uac_chip *uac; /* parent chip */
...@@ -41,7 +36,7 @@ struct uac_rtd_params { ...@@ -41,7 +36,7 @@ struct uac_rtd_params {
void *rbuf; void *rbuf;
unsigned int max_psize; /* MaxPacketSize of endpoint */ unsigned int max_psize; /* MaxPacketSize of endpoint */
struct uac_req *ureq; struct usb_request **reqs;
spinlock_t lock; spinlock_t lock;
}; };
...@@ -82,10 +77,9 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) ...@@ -82,10 +77,9 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
unsigned long flags, flags2; unsigned long flags, flags2;
unsigned int hw_ptr; unsigned int hw_ptr;
int status = req->status; int status = req->status;
struct uac_req *ur = req->context;
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
struct snd_pcm_runtime *runtime; 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; struct snd_uac_chip *uac = prm->uac;
/* i/f shutting down */ /* i/f shutting down */
...@@ -339,16 +333,16 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep) ...@@ -339,16 +333,16 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep)
params = &audio_dev->params; params = &audio_dev->params;
for (i = 0; i < params->req_number; i++) { for (i = 0; i < params->req_number; i++) {
if (prm->ureq[i].req) { if (prm->reqs[i]) {
if (usb_ep_dequeue(ep, prm->ureq[i].req)) if (usb_ep_dequeue(ep, prm->reqs[i]))
usb_ep_free_request(ep, prm->ureq[i].req); usb_ep_free_request(ep, prm->reqs[i]);
/* /*
* If usb_ep_dequeue() cannot successfully dequeue the * If usb_ep_dequeue() cannot successfully dequeue the
* request, the request will be freed by the completion * request, the request will be freed by the completion
* callback. * callback.
*/ */
prm->ureq[i].req = NULL; prm->reqs[i] = NULL;
} }
} }
...@@ -377,22 +371,21 @@ int u_audio_start_capture(struct g_audio *audio_dev) ...@@ -377,22 +371,21 @@ int u_audio_start_capture(struct g_audio *audio_dev)
usb_ep_enable(ep); usb_ep_enable(ep);
for (i = 0; i < params->req_number; i++) { 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); req = usb_ep_alloc_request(ep, GFP_ATOMIC);
if (req == NULL) if (req == NULL)
return -ENOMEM; return -ENOMEM;
prm->ureq[i].req = req; prm->reqs[i] = req;
prm->ureq[i].pp = prm;
req->zero = 0; req->zero = 0;
req->context = &prm->ureq[i]; req->context = prm;
req->length = req_len; req->length = req_len;
req->complete = u_audio_iso_complete; req->complete = u_audio_iso_complete;
req->buf = prm->rbuf + i * ep->maxpacket; 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__); dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
} }
...@@ -455,22 +448,21 @@ int u_audio_start_playback(struct g_audio *audio_dev) ...@@ -455,22 +448,21 @@ int u_audio_start_playback(struct g_audio *audio_dev)
usb_ep_enable(ep); usb_ep_enable(ep);
for (i = 0; i < params->req_number; i++) { 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); req = usb_ep_alloc_request(ep, GFP_ATOMIC);
if (req == NULL) if (req == NULL)
return -ENOMEM; return -ENOMEM;
prm->ureq[i].req = req; prm->reqs[i] = req;
prm->ureq[i].pp = prm;
req->zero = 0; req->zero = 0;
req->context = &prm->ureq[i]; req->context = prm;
req->length = req_len; req->length = req_len;
req->complete = u_audio_iso_complete; req->complete = u_audio_iso_complete;
req->buf = prm->rbuf + i * ep->maxpacket; 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__); 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, ...@@ -515,9 +507,10 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
uac->c_prm.uac = uac; uac->c_prm.uac = uac;
prm->max_psize = g_audio->out_ep_maxpsize; prm->max_psize = g_audio->out_ep_maxpsize;
prm->ureq = kcalloc(params->req_number, sizeof(struct uac_req), prm->reqs = kcalloc(params->req_number,
GFP_KERNEL); sizeof(struct usb_request *),
if (!prm->ureq) { GFP_KERNEL);
if (!prm->reqs) {
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
} }
...@@ -537,9 +530,10 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, ...@@ -537,9 +530,10 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
uac->p_prm.uac = uac; uac->p_prm.uac = uac;
prm->max_psize = g_audio->in_ep_maxpsize; prm->max_psize = g_audio->in_ep_maxpsize;
prm->ureq = kcalloc(params->req_number, sizeof(struct uac_req), prm->reqs = kcalloc(params->req_number,
GFP_KERNEL); sizeof(struct usb_request *),
if (!prm->ureq) { GFP_KERNEL);
if (!prm->reqs) {
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
} }
...@@ -592,8 +586,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, ...@@ -592,8 +586,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
snd_fail: snd_fail:
snd_card_free(card); snd_card_free(card);
fail: fail:
kfree(uac->p_prm.ureq); kfree(uac->p_prm.reqs);
kfree(uac->c_prm.ureq); kfree(uac->c_prm.reqs);
kfree(uac->p_prm.rbuf); kfree(uac->p_prm.rbuf);
kfree(uac->c_prm.rbuf); kfree(uac->c_prm.rbuf);
kfree(uac); kfree(uac);
...@@ -615,8 +609,8 @@ void g_audio_cleanup(struct g_audio *g_audio) ...@@ -615,8 +609,8 @@ void g_audio_cleanup(struct g_audio *g_audio)
if (card) if (card)
snd_card_free(card); snd_card_free(card);
kfree(uac->p_prm.ureq); kfree(uac->p_prm.reqs);
kfree(uac->c_prm.ureq); kfree(uac->c_prm.reqs);
kfree(uac->p_prm.rbuf); kfree(uac->p_prm.rbuf);
kfree(uac->c_prm.rbuf); kfree(uac->c_prm.rbuf);
kfree(uac); kfree(uac);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册