Commit 7b8164c1 authored by Curtis Malainey's avatar Curtis Malainey Committed by Mark Brown

ASoC: rt5677-spi: Handle over reading when flipping bytes

There is a case when a we want to read a large number of bytes that
require a burst but is not a multiple of the word size (8). When this
happens rt5677_spi_reverse will run off the end of the buffer. The
solution is to tell spi_reverse the actual size of the destination and
stop if we reach it even if we have data left that we read.

Cc: Ben Zhang <benzh@chromium.org>
Signed-off-by: default avatarCurtis Malainey <cujomalainey@chromium.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent f7c4842a
...@@ -101,7 +101,7 @@ static void rt5677_spi_reverse(u8 *dst, u32 dstlen, const u8 *src, u32 srclen) ...@@ -101,7 +101,7 @@ static void rt5677_spi_reverse(u8 *dst, u32 dstlen, const u8 *src, u32 srclen)
u32 word_size = min_t(u32, dstlen, 8); u32 word_size = min_t(u32, dstlen, 8);
for (w = 0; w < dstlen; w += word_size) { for (w = 0; w < dstlen; w += word_size) {
for (i = 0; i < word_size; i++) { for (i = 0; i < word_size && i + w < dstlen; i++) {
si = w + word_size - i - 1; si = w + word_size - i - 1;
dst[w + i] = si < srclen ? src[si] : 0; dst[w + i] = si < srclen ? src[si] : 0;
} }
...@@ -152,8 +152,9 @@ int rt5677_spi_read(u32 addr, void *rxbuf, size_t len) ...@@ -152,8 +152,9 @@ int rt5677_spi_read(u32 addr, void *rxbuf, size_t len)
status |= spi_sync(g_spi, &m); status |= spi_sync(g_spi, &m);
mutex_unlock(&spi_mutex); mutex_unlock(&spi_mutex);
/* Copy data back to caller buffer */ /* Copy data back to caller buffer */
rt5677_spi_reverse(cb + offset, t[1].len, body, t[1].len); rt5677_spi_reverse(cb + offset, len - offset, body, t[1].len);
} }
return status; return status;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment