linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: gadget: u_audio: Initialize capture memory
@ 2019-12-09 10:34 Lionel Koenig
  2019-12-09 13:07 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Lionel Koenig @ 2019-12-09 10:34 UTC (permalink / raw)
  To: linux-usb; +Cc: Felipe Balbi, Takashi Iwai, Jonas Stenvall

Using USB audio gadget in capture mode with an non blocking API may
result in getting uninitialized memory samples. That ensure that the
memory is initialized to 0 when the stream is prepared.

Signed-off-by: Lionel Koenig <lionel.koenig@gmail.com>
---
 drivers/usb/gadget/function/u_audio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index 7ec6a996af26..6d708494ca77 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -317,6 +317,14 @@ static int uac_pcm_open(struct snd_pcm_substream *substream)
 	return 0;
 }
 
+static int uac_pcm_prepare(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	memset(runtime->dma_area,  0, runtime->dma_bytes);
+	return 0;
+}
+
 /* ALSA cries without these function pointers */
 static int uac_pcm_null(struct snd_pcm_substream *substream)
 {
@@ -331,7 +339,7 @@ static const struct snd_pcm_ops uac_pcm_ops = {
 	.hw_free = uac_pcm_hw_free,
 	.trigger = uac_pcm_trigger,
 	.pointer = uac_pcm_pointer,
-	.prepare = uac_pcm_null,
+	.prepare = uac_pcm_prepare,
 };
 
 static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep)
-- 
2.24.0.393.g34dc348eaf-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-10 12:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-09 10:34 [PATCH] USB: gadget: u_audio: Initialize capture memory Lionel Koenig
2019-12-09 13:07 ` Takashi Iwai
2019-12-10 12:47   ` Lionel Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).