lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 13 Feb 2022 11:11:19 -0700
From:   Nathan Chancellor <nathan@...nel.org>
To:     Lh Kuo 郭力豪 <lh.Kuo@...plus.com>
Cc:     Tom Rix <trix@...hat.com>, Mark Brown <broonie@...nel.org>,
        Li-hao Kuo <lhjeff911@...il.com>,
        "linux-spi@...r.kernel.org" <linux-spi@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Wells Lu 呂芳騰 <wells.lu@...plus.com>
Subject: Re: [PATCH] spi: Fix warning for Clang build

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ