* [PATCH] spi: Fix warning for Clang build
@ 2022-02-10 2:36 Li-hao Kuo
2022-02-10 11:17 ` Mark Brown
0 siblings, 1 reply; 8+ messages in thread
From: Li-hao Kuo @ 2022-02-10 2:36 UTC (permalink / raw)
To: broonie, linux-spi, linux-kernel; +Cc: wells.lu, lh.kuo, 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:
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>
Signed-off-by: Li-hao Kuo <lhjeff911@gmail.com>
---
drivers/spi/spi-sunplus-sp7021.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-sunplus-sp7021.c b/drivers/spi/spi-sunplus-sp7021.c
index ba5ed9f..460993a 100644
--- a/drivers/spi/spi-sunplus-sp7021.c
+++ b/drivers/spi/spi-sunplus-sp7021.c
@@ -375,7 +375,7 @@ 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 mode, ret = 0;
mode = SP7021_SPI_IDLE;
if (xfer->tx_buf && xfer->rx_buf) {
@@ -403,7 +403,7 @@ static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi
ret = sp7021_spi_slave_rx(spi, xfer);
break;
default:
- break;
+ return -EINVAL;
}
if (xfer->tx_buf)
dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] spi: Fix warning for Clang build 2022-02-10 2:36 [PATCH] spi: Fix warning for Clang build Li-hao Kuo @ 2022-02-10 11:17 ` Mark Brown 2022-02-11 3:32 ` Lh Kuo 郭力豪 0 siblings, 1 reply; 8+ messages in thread From: Mark Brown @ 2022-02-10 11:17 UTC (permalink / raw) To: Li-hao Kuo; +Cc: linux-spi, linux-kernel, wells.lu, lh.kuo, trix [-- Attachment #1: Type: text/plain, Size: 540 bytes --] On Thu, Feb 10, 2022 at 10:36:56AM +0800, Li-hao Kuo wrote: > - int mode, ret; > + int mode, ret = 0; > > mode = SP7021_SPI_IDLE; > if (xfer->tx_buf && xfer->rx_buf) { > @@ -403,7 +403,7 @@ static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi > ret = sp7021_spi_slave_rx(spi, xfer); > break; > default: > - break; > + return -EINVAL; The return here means that the initialization is now redundant and will stop the compiler spotting any future similar issues which isn't ideal. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] spi: Fix warning for Clang build 2022-02-10 11:17 ` Mark Brown @ 2022-02-11 3:32 ` Lh Kuo 郭力豪 2022-02-11 4:49 ` Tom Rix 0 siblings, 1 reply; 8+ messages in thread From: Lh Kuo 郭力豪 @ 2022-02-11 3:32 UTC (permalink / raw) To: Mark Brown, Li-hao Kuo Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Wells Lu 呂芳騰, trix@redhat.com > > The return here means that the initialization is now redundant and will stop the compiler spotting any > future similar issues which isn't ideal. I got it, so do I need to submit a new patch? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] spi: Fix warning for Clang build 2022-02-11 3:32 ` Lh Kuo 郭力豪 @ 2022-02-11 4:49 ` Tom Rix 2022-02-11 4:59 ` Lh Kuo 郭力豪 0 siblings, 1 reply; 8+ messages in thread From: Tom Rix @ 2022-02-11 4:49 UTC (permalink / raw) To: Lh Kuo 郭力豪, Mark Brown, Li-hao Kuo Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Wells Lu 呂芳騰 On 2/10/22 7:32 PM, Lh Kuo 郭力豪 wrote: >> The return here means that the initialization is now redundant and will stop the compiler spotting any >> future similar issues which isn't ideal. > I got it, so do I need to submit a new patch? Assuming yes, so something else.. Looking again at the function, there are 3 sets of if-check blocks these could be combined into the first one. The later two are variations on is this an rx or a tx, the first check does that. T > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] spi: Fix warning for Clang build 2022-02-11 4:49 ` Tom Rix @ 2022-02-11 4:59 ` Lh Kuo 郭力豪 2022-02-11 11:57 ` Mark Brown 2022-02-13 18:11 ` Nathan Chancellor 0 siblings, 2 replies; 8+ messages in thread From: Lh Kuo 郭力豪 @ 2022-02-11 4:59 UTC (permalink / raw) To: Tom Rix, Mark Brown, Li-hao Kuo Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Wells Lu 呂芳騰 Yes. I think the function can be simplified as follows static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi_device *spi, struct spi_transfer *xfer) { struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr); struct device *dev = pspim->dev; 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) { 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; ret = sp7021_spi_slave_tx(spi, xfer); } else if (xfer->rx_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; ret = sp7021_spi_slave_rx(spi, xfer); } 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); spi_finalize_current_transfer(ctlr); return ret; } ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] spi: Fix warning for Clang build 2022-02-11 4:59 ` Lh Kuo 郭力豪 @ 2022-02-11 11:57 ` Mark Brown 2022-02-13 18:11 ` Nathan Chancellor 1 sibling, 0 replies; 8+ messages in thread From: Mark Brown @ 2022-02-11 11:57 UTC (permalink / raw) To: Lh Kuo 郭力豪 Cc: Tom Rix, Li-hao Kuo, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Wells Lu 呂芳騰 [-- Attachment #1: Type: text/plain, Size: 1399 bytes --] On Fri, Feb 11, 2022 at 04:59:00AM +0000, Lh Kuo 郭力豪 wrote: > Yes. I think the function can be simplified as follows > static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi_device *spi, > struct spi_transfer *xfer) > { > struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr); > struct device *dev = pspim->dev; > int ret; > > mode = SP7021_SPI_IDLE; > if (xfer->tx_buf && xfer->rx_buf) { > dev_dbg(&ctlr->dev, "%s() wrong command\n", __func__); > return -EINVAL; Since only unidirectional transfers are supported... > } else if (xfer->tx_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; > ret = sp7021_spi_slave_tx(spi, xfer); > } else if (xfer->rx_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; > ret = sp7021_spi_slave_rx(spi, xfer); > } > > 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); ...you could even fold the unmapping into the if/else tree above. Otherwise this looks good to me, please send a patch. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] spi: Fix warning for Clang build 2022-02-11 4:59 ` Lh Kuo 郭力豪 2022-02-11 11:57 ` Mark Brown @ 2022-02-13 18:11 ` Nathan Chancellor 2022-02-14 2:23 ` Lh Kuo 郭力豪 1 sibling, 1 reply; 8+ messages in thread From: Nathan Chancellor @ 2022-02-13 18:11 UTC (permalink / raw) To: Lh Kuo 郭力豪 Cc: Tom Rix, Mark Brown, Li-hao Kuo, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Wells Lu 呂芳騰 On Fri, Feb 11, 2022 at 04:59:00AM +0000, Lh Kuo 郭力豪 wrote: > Yes. I think the function can be simplified as follows > > static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi_device *spi, > struct spi_transfer *xfer) > { > struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr); > struct device *dev = pspim->dev; > 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) { > 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; > ret = sp7021_spi_slave_tx(spi, xfer); > } else if (xfer->rx_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; > ret = sp7021_spi_slave_rx(spi, xfer); > } > > 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); > > spi_finalize_current_transfer(ctlr); > return ret; > } Clang will still warn that ret is uninitialized when the else if branches are not taken. How about something like: static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi_device *spi, struct spi_transfer *xfer) { struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr); struct device *dev = pspim->dev; int ret; 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; 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; ret = sp7021_spi_slave_rx(spi, xfer); 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; } ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] spi: Fix warning for Clang build 2022-02-13 18:11 ` Nathan Chancellor @ 2022-02-14 2:23 ` Lh Kuo 郭力豪 0 siblings, 0 replies; 8+ messages in thread From: Lh Kuo 郭力豪 @ 2022-02-14 2:23 UTC (permalink / raw) To: Nathan Chancellor Cc: Tom Rix, Mark Brown, Li-hao Kuo, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Wells Lu 呂芳騰 Thank you, I will revise it to the next submit based on these suggestions ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-02-14 2:23 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-02-10 2:36 [PATCH] spi: Fix warning for Clang build Li-hao Kuo 2022-02-10 11:17 ` Mark Brown 2022-02-11 3:32 ` Lh Kuo 郭力豪 2022-02-11 4:49 ` Tom Rix 2022-02-11 4:59 ` Lh Kuo 郭力豪 2022-02-11 11:57 ` Mark Brown 2022-02-13 18:11 ` Nathan Chancellor 2022-02-14 2:23 ` Lh Kuo 郭力豪
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).