From patchwork Tue Jun 27 15:45:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 9812707 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 9337D603F2 for ; Tue, 27 Jun 2017 15:48:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 847B528696 for ; Tue, 27 Jun 2017 15:48:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7928C286E0; Tue, 27 Jun 2017 15:48:10 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E36B286DC for ; Tue, 27 Jun 2017 15:48:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752042AbdF0Prp (ORCPT ); Tue, 27 Jun 2017 11:47:45 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:38494 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752249AbdF0PqK (ORCPT ); Tue, 27 Jun 2017 11:46:10 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v5RFi4Is007652; Tue, 27 Jun 2017 17:45:41 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 2battv0d7j-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 27 Jun 2017 17:45:41 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7586434; Tue, 27 Jun 2017 15:45:40 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4BB5B2571; Tue, 27 Jun 2017 15:45:40 +0000 (GMT) Received: from localhost (10.201.23.160) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Tue, 27 Jun 2017 17:45:40 +0200 From: Amelie Delaunay To: Mark Brown , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue CC: , , , , Amelie Delaunay Subject: [PATCHv2 5/9] spi: stm32: use normal conditional statements instead of ternary operator Date: Tue, 27 Jun 2017 17:45:17 +0200 Message-ID: <1498578321-13980-6-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498578321-13980-1-git-send-email-amelie.delaunay@st.com> References: <1498578321-13980-1-git-send-email-amelie.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.160] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-27_09:, , signatures=0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch replace ternary operator use by normal condition statements to ease code reading. It also removes redundant !!. Signed-off-by: Amelie Delaunay --- drivers/spi/spi-stm32.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 0997d6d..72efc63 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -267,7 +267,10 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz) return -EINVAL; /* Determine the first power of 2 greater than or equal to div */ - mbrdiv = (div & (div - 1)) ? fls(div) : fls(div) - 1; + if (div & (div - 1)) + mbrdiv = fls(div); + else + mbrdiv = fls(div) - 1; spi->cur_speed = spi->clk_rate / (1 << mbrdiv); @@ -285,9 +288,12 @@ static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi) /* data packet should not exceed 1/2 of fifo space */ half_fifo = (spi->fifo_size / 2); - fthlv = (spi->cur_bpw <= 8) ? half_fifo : - (spi->cur_bpw <= 16) ? (half_fifo / 2) : - (half_fifo / 4); + if (spi->cur_bpw <= 8) + fthlv = half_fifo; + else if (spi->cur_bpw <= 16) + fthlv = half_fifo / 2; + else + fthlv = half_fifo / 4; /* align packet size with data registers access */ if (spi->cur_bpw > 8) @@ -462,9 +468,9 @@ static bool stm32_spi_can_dma(struct spi_master *master, struct stm32_spi *spi = spi_master_get_devdata(master); dev_dbg(spi->dev, "%s: %s\n", __func__, - (!!(transfer->len > spi->fifo_size)) ? "true" : "false"); + (transfer->len > spi->fifo_size) ? "true" : "false"); - return !!(transfer->len > spi->fifo_size); + return (transfer->len > spi->fifo_size); } /** @@ -493,7 +499,8 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) * Full-Duplex, need to poll RXP event to know if there are remaining * data, before disabling SPI. */ - mask |= ((spi->rx_buf && !spi->cur_usedma) ? SPI_SR_RXP : 0); + if (spi->rx_buf && !spi->cur_usedma) + mask |= SPI_SR_RXP; if (!(sr & mask)) { dev_dbg(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n", @@ -656,12 +663,18 @@ static void stm32_spi_dma_config(struct stm32_spi *spi, enum dma_slave_buswidth buswidth; u32 maxburst; - buswidth = (spi->cur_bpw <= 8) ? DMA_SLAVE_BUSWIDTH_1_BYTE : - (spi->cur_bpw <= 16) ? DMA_SLAVE_BUSWIDTH_2_BYTES : - DMA_SLAVE_BUSWIDTH_4_BYTES; + if (spi->cur_bpw <= 8) + buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; + else if (spi->cur_bpw <= 16) + buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; + else + buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; /* Valid for DMA Half or Full Fifo threshold */ - maxburst = (spi->cur_fthlv == 2) ? 1 : spi->cur_fthlv; + if (spi->cur_fthlv == 2) + maxburst = 1; + else + maxburst = spi->cur_fthlv; memset(dma_conf, 0, sizeof(struct dma_slave_config)); dma_conf->direction = dir; @@ -920,9 +933,12 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi, ~cfg2_clrb) | cfg2_setb, spi->base + STM32_SPI_CFG2); - nb_words = DIV_ROUND_UP(transfer->len * 8, - (spi->cur_bpw <= 8) ? 8 : - (spi->cur_bpw <= 16) ? 16 : 32); + if (spi->cur_bpw <= 8) + nb_words = transfer->len; + else if (spi->cur_bpw <= 16) + nb_words = DIV_ROUND_UP(transfer->len * 8, 16); + else + nb_words = DIV_ROUND_UP(transfer->len * 8, 32); nb_words <<= SPI_CR2_TSIZE_SHIFT; if (nb_words <= SPI_CR2_TSIZE) {