From patchwork Fri Jul 21 08:00:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oder Chiou X-Patchwork-Id: 9856295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1BDFE601C0 for ; Fri, 21 Jul 2017 08:07:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094152877C for ; Fri, 21 Jul 2017 08:07:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1ED428781; Fri, 21 Jul 2017 08:07:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 118592877C for ; Fri, 21 Jul 2017 08:07:10 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C18612674BB; Fri, 21 Jul 2017 10:01:00 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6D01E2674BD; Fri, 21 Jul 2017 10:00:59 +0200 (CEST) Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by alsa0.perex.cz (Postfix) with ESMTP id 287CB266C39 for ; Fri, 21 Jul 2017 10:00:55 +0200 (CEST) Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.60 with qID v6L80rPm008395, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtitcas11.realtek.com.tw [172.21.6.12]) by rtits2.realtek.com.tw (8.15.2/2.56/5.77) with ESMTP id v6L80rPm008395; Fri, 21 Jul 2017 16:00:53 +0800 Received: from RTITCASV01.realtek.com.tw (172.21.6.18) by RTITCAS11.realtek.com.tw (172.21.6.12) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 21 Jul 2017 16:00:52 +0800 Received: from localhost.localdomain (172.21.85.85) by RTITCASV01.realtek.com.tw (172.21.6.18) with Microsoft SMTP Server id 14.3.294.0; Fri, 21 Jul 2017 16:00:52 +0800 From: Oder Chiou To: , Date: Fri, 21 Jul 2017 16:00:47 +0800 Message-ID: <1500624047-21492-1-git-send-email-oder_chiou@realtek.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [172.21.85.85] Cc: Oder Chiou , jack.yu@realtek.com, alsa-devel@alsa-project.org, hychao@google.com, albertchen@realtek.com, shumingf@realtek.com, bardliao@realtek.com, flove@realtek.com Subject: [alsa-devel] [PATCH] ASoC: rt5514: Use the local variable to get the data from SPI device X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The patch uses the local variable to get the data from SPI device to prevent to get all zero data. Signed-off-by: Oder Chiou --- sound/soc/codecs/rt5514-spi.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 950d1ff..e693204 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -289,7 +289,7 @@ int rt5514_spi_burst_read(unsigned int addr, u8 *rxbuf, size_t len) { u8 spi_cmd = RT5514_SPI_CMD_BURST_READ; int status; - u8 write_buf[8]; + u8 write_buf[8], read_buf[RT5514_SPI_BUF_LEN]; unsigned int i, end, offset = 0; struct spi_message message; @@ -319,7 +319,7 @@ int rt5514_spi_burst_read(unsigned int addr, u8 *rxbuf, size_t len) spi_message_add_tail(&x[1], &message); x[2].len = end; - x[2].rx_buf = rxbuf + offset; + x[2].rx_buf = read_buf; spi_message_add_tail(&x[2], &message); status = spi_sync(rt5514_spi, &message); @@ -327,6 +327,8 @@ int rt5514_spi_burst_read(unsigned int addr, u8 *rxbuf, size_t len) if (status) return false; + memcpy(rxbuf + offset, read_buf, end); + offset += RT5514_SPI_BUF_LEN; } @@ -365,14 +367,9 @@ int rt5514_spi_burst_read(unsigned int addr, u8 *rxbuf, size_t len) int rt5514_spi_burst_write(u32 addr, const u8 *txbuf, size_t len) { u8 spi_cmd = RT5514_SPI_CMD_BURST_WRITE; - u8 *write_buf; + u8 write_buf[RT5514_SPI_BUF_LEN + 6]; unsigned int i, end, offset = 0; - write_buf = kmalloc(RT5514_SPI_BUF_LEN + 6, GFP_KERNEL); - - if (write_buf == NULL) - return -ENOMEM; - while (offset < len) { if (offset + RT5514_SPI_BUF_LEN <= len) end = RT5514_SPI_BUF_LEN; @@ -403,8 +400,6 @@ int rt5514_spi_burst_write(u32 addr, const u8 *txbuf, size_t len) offset += RT5514_SPI_BUF_LEN; } - kfree(write_buf); - return 0; } EXPORT_SYMBOL_GPL(rt5514_spi_burst_write);