linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lionel Koenig <lionel.koenig@gmail.com>
To: linux-usb@vger.kernel.org
Cc: Felipe Balbi <balbi@kernel.org>, Takashi Iwai <tiwai@suse.de>,
	Jonas Stenvall <jonas.stenvall.umea@gmail.com>
Subject: [PATCH] USB: gadget: u_audio: Initialize capture memory
Date: Mon, 9 Dec 2019 11:34:35 +0100	[thread overview]
Message-ID: <20191209103435.GA55498@google.com> (raw)

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


             reply	other threads:[~2019-12-09 10:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-09 10:34 Lionel Koenig [this message]
2019-12-09 13:07 ` [PATCH] USB: gadget: u_audio: Initialize capture memory Takashi Iwai
2019-12-10 12:47   ` Lionel Koenig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191209103435.GA55498@google.com \
    --to=lionel.koenig@gmail.com \
    --cc=balbi@kernel.org \
    --cc=jonas.stenvall.umea@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).