Skip to content

Commit 96afb54

Browse files
Vladimir ZapolskiyFelipe Balbi
Vladimir Zapolskiy
authored and
Felipe Balbi
committed
usb: gadget: u_audio: remove caching of stream buffer parameters
There is no necessity to copy PCM stream ring buffer area and size properties to UAC private data structure, these values can be got from substream itself. The change gives more control on substream and avoid stale caching. Fixes: 132fcb4 ("usb: gadget: Add Audio Class 2.0 Driver") Signed-off-by: Vladimir Zapolskiy <[email protected]> Signed-off-by: Eugeniu Rosca <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 6b37bd7 commit 96afb54

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

drivers/usb/gadget/function/u_audio.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ struct uac_req {
3232
struct uac_rtd_params {
3333
struct snd_uac_chip *uac; /* parent chip */
3434
bool ep_enabled; /* if the ep is enabled */
35-
/* Size of the ring buffer */
36-
size_t dma_bytes;
37-
unsigned char *dma_area;
3835

3936
struct snd_pcm_substream *ss;
4037

@@ -90,6 +87,7 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
9087
int status = req->status;
9188
struct uac_req *ur = req->context;
9289
struct snd_pcm_substream *substream;
90+
struct snd_pcm_runtime *runtime;
9391
struct uac_rtd_params *prm = ur->pp;
9492
struct snd_uac_chip *uac = prm->uac;
9593

@@ -111,6 +109,7 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
111109
if (!substream)
112110
goto exit;
113111

112+
runtime = substream->runtime;
114113
spin_lock_irqsave(&prm->lock, flags);
115114

116115
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
@@ -147,29 +146,31 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
147146
spin_unlock_irqrestore(&prm->lock, flags);
148147

149148
/* Pack USB load in ALSA ring buffer */
150-
pending = prm->dma_bytes - hw_ptr;
149+
pending = runtime->dma_bytes - hw_ptr;
151150

152151
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
153152
if (unlikely(pending < req->actual)) {
154-
memcpy(req->buf, prm->dma_area + hw_ptr, pending);
155-
memcpy(req->buf + pending, prm->dma_area,
153+
memcpy(req->buf, runtime->dma_area + hw_ptr, pending);
154+
memcpy(req->buf + pending, runtime->dma_area,
156155
req->actual - pending);
157156
} else {
158-
memcpy(req->buf, prm->dma_area + hw_ptr, req->actual);
157+
memcpy(req->buf, runtime->dma_area + hw_ptr,
158+
req->actual);
159159
}
160160
} else {
161161
if (unlikely(pending < req->actual)) {
162-
memcpy(prm->dma_area + hw_ptr, req->buf, pending);
163-
memcpy(prm->dma_area, req->buf + pending,
162+
memcpy(runtime->dma_area + hw_ptr, req->buf, pending);
163+
memcpy(runtime->dma_area, req->buf + pending,
164164
req->actual - pending);
165165
} else {
166-
memcpy(prm->dma_area + hw_ptr, req->buf, req->actual);
166+
memcpy(runtime->dma_area + hw_ptr, req->buf,
167+
req->actual);
167168
}
168169
}
169170

170171
spin_lock_irqsave(&prm->lock, flags);
171172
/* update hw_ptr after data is copied to memory */
172-
prm->hw_ptr = (hw_ptr + req->actual) % prm->dma_bytes;
173+
prm->hw_ptr = (hw_ptr + req->actual) % runtime->dma_bytes;
173174
spin_unlock_irqrestore(&prm->lock, flags);
174175

175176
exit:
@@ -251,11 +252,8 @@ static int uac_pcm_hw_params(struct snd_pcm_substream *substream,
251252

252253
err = snd_pcm_lib_malloc_pages(substream,
253254
params_buffer_bytes(hw_params));
254-
if (err >= 0) {
255-
prm->dma_bytes = substream->runtime->dma_bytes;
256-
prm->dma_area = substream->runtime->dma_area;
255+
if (err >= 0)
257256
prm->period_size = params_period_bytes(hw_params);
258-
}
259257

260258
return err;
261259
}
@@ -270,8 +268,6 @@ static int uac_pcm_hw_free(struct snd_pcm_substream *substream)
270268
else
271269
prm = &uac->c_prm;
272270

273-
prm->dma_area = NULL;
274-
prm->dma_bytes = 0;
275271
prm->period_size = 0;
276272

277273
return snd_pcm_lib_free_pages(substream);

0 commit comments

Comments
 (0)