mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Li-hao Kuo <lhjeff911@gmail.com>
To: broonie@kernel.org, linux-spi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: wells.lu@sunplus.com, lh.kuo@sunplus.com, nathan@kernel.org,
	trix@redhat.com, Li-hao Kuo <lhjeff911@gmail.com>
Subject: [PATCH] spi: Fix warning for Clang build and simplify code
Date: Mon, 14 Feb 2022 10:20:11 +0800	[thread overview]
Message-ID: <7d91e6ce29f9a8df2c53a47b4b977664020e237a.1644805060.git.lhjeff911@gmail.com> (raw)

Clang build fails with
spi-sunplus-sp7021.c:405:2: error: variable 'ret' is used
  uninitialized whenever switch default is taken
        default:

simplify code

Restore initializing ret. and add return error at default

Fixes: 47e8fe57a66f ("spi: Modify irq request position and modify parameters")
Reported-by: Tom Rix <trix@redhat.com>
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Nathan Chancellor <nathan@kernel.org>
Reported-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Li-hao Kuo <lhjeff911@gmail.com>
---
 drivers/spi/spi-sunplus-sp7021.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

diff --git a/drivers/spi/spi-sunplus-sp7021.c b/drivers/spi/spi-sunplus-sp7021.c
index ba5ed9f..ade7a0f 100644
--- a/drivers/spi/spi-sunplus-sp7021.c
+++ b/drivers/spi/spi-sunplus-sp7021.c
@@ -69,12 +69,6 @@
 #define SP7021_SPI_DATA_SIZE		(255)
 #define SP7021_FIFO_DATA_LEN		(16)
 
-enum SP_SPI_MODE {
-	SP7021_SLAVE_READ = 0,
-	SP7021_SLAVE_WRITE = 1,
-	SP7021_SPI_IDLE = 2,
-};
-
 enum {
 	SP7021_MASTER_MODE = 0,
 	SP7021_SLAVE_MODE = 1,
@@ -375,40 +369,26 @@ static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi
 {
 	struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr);
 	struct device *dev = pspim->dev;
-	int mode, ret;
+	int ret;
 
-	mode = SP7021_SPI_IDLE;
-	if (xfer->tx_buf && xfer->rx_buf) {
-		dev_dbg(&ctlr->dev, "%s() wrong command\n", __func__);
-		return -EINVAL;
-	} else if (xfer->tx_buf) {
+	if (xfer->tx_buf && !xfer->rx_buf) {
 		xfer->tx_dma = dma_map_single(dev, (void *)xfer->tx_buf,
 					      xfer->len, DMA_TO_DEVICE);
 		if (dma_mapping_error(dev, xfer->tx_dma))
 			return -ENOMEM;
-		mode = SP7021_SLAVE_WRITE;
-	} else if (xfer->rx_buf) {
+		 ret = sp7021_spi_slave_tx(spi, xfer);
+		 dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+	} else if (xfer->rx_buf && !xfer->tx_buf) {
 		xfer->rx_dma = dma_map_single(dev, xfer->rx_buf, xfer->len,
 					      DMA_FROM_DEVICE);
 		if (dma_mapping_error(dev, xfer->rx_dma))
 			return -ENOMEM;
-		mode = SP7021_SLAVE_READ;
-	}
-
-	switch (mode) {
-	case SP7021_SLAVE_WRITE:
-		ret = sp7021_spi_slave_tx(spi, xfer);
-		break;
-	case SP7021_SLAVE_READ:
 		ret = sp7021_spi_slave_rx(spi, xfer);
-		break;
-	default:
-		break;
-	}
-	if (xfer->tx_buf)
-		dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
-	if (xfer->rx_buf)
 		dma_unmap_single(dev, xfer->rx_dma, xfer->len, DMA_FROM_DEVICE);
+	} else {
+		dev_dbg(&ctlr->dev, "%s() wrong command\n", __func__);
+		return -EINVAL;
+	}
 
 	spi_finalize_current_transfer(ctlr);
 	return ret;
-- 
2.7.4


             reply	other threads:[~2022-02-14  2:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14  2:20 Li-hao Kuo [this message]
2022-02-14 15:23 ` Nathan Chancellor
2022-02-15 12:55 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7d91e6ce29f9a8df2c53a47b4b977664020e237a.1644805060.git.lhjeff911@gmail.com \
    --to=lhjeff911@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lh.kuo@sunplus.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=trix@redhat.com \
    --cc=wells.lu@sunplus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®