aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOder Chiou <oder_chiou@realtek.com>2017-11-08 06:21:47 -0500
committerMark Brown <broonie@kernel.org>2017-11-08 06:26:56 -0500
commitc4a71ff78e668a75a4a3cfd9ebbfbd5cbe8da5fb (patch)
tree8a8b9e7d10cf4e2532a0892b8e0cb0715d112ec3
parent28aef24d726f8d503fde24ccf8a14b214355cfb5 (diff)
ASoC: rt5514-spi: Let the buf_size to align with period_bytes
The patch lets the buf_size to align with period_bytes to prevent the buffer reading over the real size of the DSP buffer and also avoid to calculate the wrong size of remaining data. Signed-off-by: Oder Chiou <oder_chiou@realtek.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/rt5514-spi.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c
index 12f2ecf3a4fe..0896817ffc3f 100644
--- a/sound/soc/codecs/rt5514-spi.c
+++ b/sound/soc/codecs/rt5514-spi.c
@@ -147,8 +147,13 @@ done:
147 147
148static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp) 148static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp)
149{ 149{
150 size_t period_bytes;
150 u8 buf[8]; 151 u8 buf[8];
151 152
153 if (!rt5514_dsp->substream)
154 return;
155
156 period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
152 rt5514_dsp->get_size = 0; 157 rt5514_dsp->get_size = 0;
153 158
154 /** 159 /**
@@ -176,6 +181,10 @@ static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp)
176 181
177 rt5514_dsp->buf_size = rt5514_dsp->buf_limit - rt5514_dsp->buf_base; 182 rt5514_dsp->buf_size = rt5514_dsp->buf_limit - rt5514_dsp->buf_base;
178 183
184 if (rt5514_dsp->buf_size % period_bytes)
185 rt5514_dsp->buf_size = (rt5514_dsp->buf_size / period_bytes) *
186 period_bytes;
187
179 if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit && 188 if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit &&
180 rt5514_dsp->buf_rp && rt5514_dsp->buf_size) 189 rt5514_dsp->buf_rp && rt5514_dsp->buf_size)
181 schedule_delayed_work(&rt5514_dsp->copy_work, 0); 190 schedule_delayed_work(&rt5514_dsp->copy_work, 0);