treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
[sfrench/cifs-2.6.git] / sound / soc / codecs / rt5677-spi.c
index 84b6bd8b50e18a8dfeee74b16820b34aacbb0829..d1694b7e165508f5905173df0d146b6a3236141d 100644 (file)
@@ -1,12 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * rt5677-spi.c  --  RT5677 ALSA SoC audio codec driver
  *
  * Copyright 2013 Realtek Semiconductor Corp.
  * Author: Oder Chiou <oder_chiou@realtek.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #include <linux/module.h>
@@ -101,7 +98,7 @@ static void rt5677_spi_reverse(u8 *dst, u32 dstlen, const u8 *src, u32 srclen)
        u32 word_size = min_t(u32, dstlen, 8);
 
        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;
                        dst[w + i] = si < srclen ? src[si] : 0;
                }
@@ -152,8 +149,9 @@ int rt5677_spi_read(u32 addr, void *rxbuf, size_t len)
                status |= spi_sync(g_spi, &m);
                mutex_unlock(&spi_mutex);
 
+
                /* 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;
 }