From: Nathan Chancellor <nathan@kernel.org>
To: "Lh Kuo 郭力豪" <lh.Kuo@sunplus.com>
Cc: "Tom Rix" <trix@redhat.com>, "Mark Brown" <broonie@kernel.org>,
"Li-hao Kuo" <lhjeff911@gmail.com>,
"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Wells Lu 呂芳騰" <wells.lu@sunplus.com>
Subject: Re: [PATCH] spi: Fix warning for Clang build
Date: Sun, 13 Feb 2022 11:11:19 -0700 [thread overview]
Message-ID: <YglJx3kgSFUH7nqX@dev-arch.archlinux-ax161> (raw)
In-Reply-To: <0b71842ec1b946729e74d73cbd354162@sphcmbx02.sunplus.com.tw>
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;
}
next prev parent reply other threads:[~2022-02-13 18:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2022-02-14 2:23 ` Lh Kuo 郭力豪
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=YglJx3kgSFUH7nqX@dev-arch.archlinux-ax161 \
--to=nathan@kernel.org \
--cc=broonie@kernel.org \
--cc=lh.Kuo@sunplus.com \
--cc=lhjeff911@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.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;
as well as URLs for NNTP newsgroup(s).