From 455b1ecb86e021311bba0cba32aa7046800171e8 Mon Sep 17 00:00:00 2001 From: Laxminath Kasam Date: Thu, 9 Jul 2020 19:36:36 +0530 Subject: [PATCH] asoc: Reset the buffer if size is partial or zero Sometimes during device switch in recording, observe size 0 is return from DSP due to EOS handling. For ALSA pcm_read to unblock, buffer appl_ptr is elapsed without actually updating the buffer. And userspace copies the stale data(old buffer) causing issue sometimes. Reset the buffer for that period_size in such cases instead of transfer stale data. Change-Id: I0d3ac133a8d95fad0710586e3e947410a41c9c5a Signed-off-by: Laxminath Kasam --- asoc/msm-pcm-q6-v2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/asoc/msm-pcm-q6-v2.c b/asoc/msm-pcm-q6-v2.c index d59148992f86..4fd6d64547d1 100644 --- a/asoc/msm-pcm-q6-v2.c +++ b/asoc/msm-pcm-q6-v2.c @@ -1008,6 +1008,11 @@ static int msm_pcm_capture_copy(struct snd_pcm_substream *substream, xfer = size; offset = prtd->in_frame_info[idx].offset; pr_debug("Offset value = %d\n", offset); + if (size == 0 || size < fbytes) { + memset(bufptr + offset + size, 0, fbytes - size); + size = xfer = fbytes; + } + if (copy_to_user(buf, bufptr+offset, xfer)) { pr_err("Failed to copy buf to user\n"); ret = -EFAULT;