spi: initialize ret variable
Subsystems (2)
PATCH 1/1 spi: initialize ret variable
From: Tom Rix <[email protected]>
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.
--- drivers/spi/spi-sunplus-sp7021.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-sunplus-sp7021.c +1 -1
@@ -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) {
Signature · 1 line
2.26.3
Mark Brown
maintainerQuoted 9 lines · On Wed, Feb 09, 2022 at 08:30:29AM -0800, [email protected] wrote:
From: Tom Rix <[email protected]>
Clang build fails with spi-sunplus-sp7021.c:405:2: error: variable 'ret' is used
uninitialized whenever switch default is takendefault: ^~~~~~~Restore initializing ret.
Are you sure this is a good fix and that the compiler hasn't instead identifed that we should be returning an error in the default case?
Quoted 9 lines · Mark Brown
Quoted 8 lines · On Wed, Feb 09, 2022 at 08:30:29AM -0800, [email protected] wrote:
From: Tom Rix <[email protected]>
Clang build fails with spi-sunplus-sp7021.c:405:2: error: variable 'ret' is used
uninitialized whenever switch default is takendefault: ^~~~~~~
Quoted 3 lines
Quoted 1 line
Restore initializing ret.
Are you sure this is a good fix and that the compiler hasn't instead identifed that we should be returning an error in the default case?
If setting mode to idle is not really a valid state, then default should return an error.
The old behavior returned 0 and I am treating this as a regression.
Tom
Mark Brown
maintainerQuoted 9 lines · Tom Rix
Quoted 7 lines · Mark Brown
Quoted 5 lines · On Wed, Feb 09, 2022 at 08:30:29AM -0800, [email protected] wrote:
Clang build fails with spi-sunplus-sp7021.c:405:2: error: variable 'ret' is used
uninitialized whenever switch default is takendefault: ^~~~~~~
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Restore initializing ret.
Are you sure this is a good fix and that the compiler hasn't instead identifed that we should be returning an error in the default case?
If setting mode to idle is not really a valid state, then default should return an error.
Yes, that's what I'm asking.
Quoted 1 line
The old behavior returned 0 and I am treating this as a regression.
The goal here isn't just to shut up warnings, it's to fix any problems that they identify. Unconditionally initialising return values is a common way of fixing warnings while leaving real problems in place.
A message that is not in the archive (sent off-list or not yet received): CAGcXWkyCQ4JExvHv3cEL7vLMOcq_iPu0vOyOmnfzbQmMxHEp=Q@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
郭力豪
maintainerQuoted 12 lines
Yes, that's what I'm asking.
The original setting was ret=0; I just wanted to remove it when defining
the ret, but it looks like it's required.
Yes, it should return error at default
Quoted 6 lines
I will submit new patch for this.
The old behavior returned 0 and I am treating this as a regression.
The goal here isn't just to shut up warnings, it's to fix any problems that they identify. Unconditionally initialising return values is a common way of fixing warnings while leaving real problems in place.
The original setting was ret=0; I just wanted to remove it when defining
the ret, but it looks like it's required.
Yes, it should return error at default
I will submit new patch for this.