linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: Fix warning for Clang build and simplify code
@ 2022-02-14  2:20 Li-hao Kuo
  2022-02-14 15:23 ` Nathan Chancellor
  2022-02-15 12:55 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Li-hao Kuo @ 2022-02-14  2:20 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel
  Cc: wells.lu, lh.kuo, nathan, trix, Li-hao Kuo

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: Fix warning for Clang build and simplify code
  2022-02-14  2:20 [PATCH] spi: Fix warning for Clang build and simplify code Li-hao Kuo
@ 2022-02-14 15:23 ` Nathan Chancellor
  2022-02-15 12:55 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2022-02-14 15:23 UTC (permalink / raw)
  To: Li-hao Kuo; +Cc: broonie, linux-spi, linux-kernel, wells.lu, lh.kuo, trix

On Mon, Feb 14, 2022 at 10:20:11AM +0800, Li-hao Kuo wrote:
> 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

This part of the commit message does not really match what the change
does anymore and I think that the "simplify code" part of the message
could be flushed out a little bit more, maybe something like:

"Hoist the calls to sp7021_spi_slave_tx() and sp7021_spi_slave_rx() into
the if statments and rewrite the if statements to explicitly allow only
unidirectional transfers."

?

> 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>

Regardless, the actual change itself looks fine. Feel free to carry
this tag on future revisions:

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: Fix warning for Clang build and simplify code
  2022-02-14  2:20 [PATCH] spi: Fix warning for Clang build and simplify code Li-hao Kuo
  2022-02-14 15:23 ` Nathan Chancellor
@ 2022-02-15 12:55 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2022-02-15 12:55 UTC (permalink / raw)
  To: linux-spi, linux-kernel, Li-hao Kuo; +Cc: lh.kuo, trix, nathan, wells.lu

On Mon, 14 Feb 2022 10:20:11 +0800, Li-hao Kuo wrote:
> Clang build fails with
> spi-sunplus-sp7021.c:405:2: error: variable 'ret' is used
>   uninitialized whenever switch default is taken
>         default:
> 
> simplify code
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: Fix warning for Clang build and simplify code
      commit: 5790597d7113faabb1714d3d1efa268e36eb4811

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-15 12:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14  2:20 [PATCH] spi: Fix warning for Clang build and simplify code Li-hao Kuo
2022-02-14 15:23 ` Nathan Chancellor
2022-02-15 12:55 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).