From patchwork Thu Nov 17 12:16:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanchayan X-Patchwork-Id: 9434197 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 358B06047D for ; Thu, 17 Nov 2016 12:29:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 256A329407 for ; Thu, 17 Nov 2016 12:29:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 175852947A; Thu, 17 Nov 2016 12:29:42 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DC0D29407 for ; Thu, 17 Nov 2016 12:29:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c7Lme-0002rQ-9e; Thu, 17 Nov 2016 12:27:16 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c7Lli-0002O7-A8 for linux-arm-kernel@lists.infradead.org; Thu, 17 Nov 2016 12:26:19 +0000 Received: by mail-pg0-x243.google.com with SMTP id p66so17547451pga.2 for ; Thu, 17 Nov 2016 04:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=rupibNIY54F8gPM1A30jDmLaYxeFI2QsPLB3jSIalio=; b=B+y/zNvauQPXaR3cOVY/+675Z4T3mrOV80dGjyCeIaCwo/zSbYSLKK3TP4p1QZy60A fxWNwhrSplgBKcOrXV5DmLzkB5sLf2aw2/P71jW+asFQWu2zBEU+WWCgtBw6qZ/FkHZd 1CBvqZBqKncG0ZTKNf9GKD8W2UCmhYcdDvlaDTLzwhcClsSmXpfE1HkVkEboth5jPzF3 ZLstrkakI0uhpWOjObwXKiEfHus6ULB0+HDl/Vq0OC3khqJ0GB0hVNCEUDWvdRCvtLA6 /KV0zkBKv0oHFj2uk5tIz+CxnZOlka1s15AgOszCyWGYx5hDQ9BE6RxucasHM128ht1S ytYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=rupibNIY54F8gPM1A30jDmLaYxeFI2QsPLB3jSIalio=; b=Buj1rkbEHlEWwnp+QzlcKsboj8AhYQ4RS5IHFBK7mFpUtKGymGdHhSNESNDNYt0tPj ezVbSnh4Dk7jev3hhhWzg/vOK8awbkOsmD3DNCSBTReDKWKaxwVbeMHe3Ubez7bSPExD x8Xu2GiJmMma0p2RncuJpogoaGebdj3nyFCtCypXcTTZ8kScZBWoyZjVB3ZlqhdIBEv4 /d9eDQ5oeIj6AU2XOMw8/PrsmUoklpFjwUkCboKl2qHQw8amA6Xh2T2zX1sxnqZNCHyv BKHzZ/GB2toRjlPsDgDYkjWtzhybWT8EQ7Mq0IHVWP2WgTAkOdKEMBEAAvcY8yCsjZ0v tMcQ== X-Gm-Message-State: ABUngvd5Ezk2+XfBANll0dAP0E57MlFxmRPEGj4Zzr4mnOhiQ5KfR06oHEeeRcJW/TEPug== X-Received: by 10.99.115.82 with SMTP id d18mr7050175pgn.56.1479385562083; Thu, 17 Nov 2016 04:26:02 -0800 (PST) Received: from localhost ([115.115.243.34]) by smtp.gmail.com with ESMTPSA id 65sm7207969pfn.12.2016.11.17.04.26.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Nov 2016 04:26:01 -0800 (PST) From: Sanchayan Maity To: broonie@kernel.org Subject: [PATCH 4/4] spi: spi-fsl-dspi: Minor code cleanup and error path fixes Date: Thu, 17 Nov 2016 17:46:51 +0530 Message-Id: X-Mailer: git-send-email 2.10.2 In-Reply-To: References: <20161111122036.fubv7b4jc5vkdxhc@sirena.org.uk> In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161117_042618_462074_18FE1F62 X-CRM114-Status: GOOD ( 13.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sanchayan Maity , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, stefan@agner.ch, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Code cleanup for improving code readability and error path fixes and cleanup removing use of devm_kfree. Signed-off-by: Sanchayan Maity --- drivers/spi/spi-fsl-dspi.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 164e2e1..382a7f9 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -222,13 +222,18 @@ static void dspi_rx_dma_callback(void *arg) rx_word = is_double_byte_mode(dspi); - len = rx_word ? (dma->curr_xfer_len / 2) : dma->curr_xfer_len; + if (rx_word) + len = dma->curr_xfer_len / 2; + else + len = dma->curr_xfer_len; if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) { for (i = 0; i < len; i++) { d = dspi->dma->rx_dma_buf[i]; - rx_word ? (*(u16 *)dspi->rx = d) : - (*(u8 *)dspi->rx = d); + if (rx_word) + *(u16 *)dspi->rx = d; + else + *(u8 *)dspi->rx = d; dspi->rx += rx_word + 1; } } @@ -247,17 +252,27 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) tx_word = is_double_byte_mode(dspi); - len = tx_word ? (dma->curr_xfer_len / 2) : dma->curr_xfer_len; + if (tx_word) + len = dma->curr_xfer_len / 2; + else + len = dma->curr_xfer_len; for (i = 0; i < len - 1; i++) { - val = tx_word ? *(u16 *) dspi->tx : *(u8 *) dspi->tx; + if (tx_word) + val = *(u16 *) dspi->tx; + else + val = *(u8 *) dspi->tx; dspi->dma->tx_dma_buf[i] = SPI_PUSHR_TXDATA(val) | SPI_PUSHR_PCS(dspi->cs) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT; dspi->tx += tx_word + 1; } - val = tx_word ? *(u16 *) dspi->tx : *(u8 *) dspi->tx; + if (tx_word) + val = *(u16 *) dspi->tx; + else + val = *(u8 *) dspi->tx; + if (dspi->cs_change) { dspi->dma->tx_dma_buf[i] = SPI_PUSHR_TXDATA(val) | SPI_PUSHR_PCS(dspi->cs) | @@ -440,15 +455,16 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) return 0; err_slave_config: - devm_kfree(dev, dma->rx_dma_buf); + dma_free_coherent(dev, DSPI_DMA_BUFSIZE, + dma->rx_dma_buf, dma->rx_dma_phys); err_rx_dma_buf: - devm_kfree(dev, dma->tx_dma_buf); + dma_free_coherent(dev, DSPI_DMA_BUFSIZE, + dma->tx_dma_buf, dma->tx_dma_phys); err_tx_dma_buf: dma_release_channel(dma->chan_tx); err_tx_channel: dma_release_channel(dma->chan_rx); - devm_kfree(dev, dma); dspi->dma = NULL; return ret;