linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: initialize ret variable
@ 2022-02-09 16:30 trix
  2022-02-09 16:33 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: trix @ 2022-02-09 16:30 UTC (permalink / raw)
  To: lhjeff911, broonie, nathan, ndesaulniers
  Cc: linux-spi, linux-kernel, llvm, Tom Rix

From: Tom Rix <trix@redhat.com>

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.

Fixes: 47e8fe57a66f ("spi: Modify irq request position and modify parameters")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/spi/spi-sunplus-sp7021.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-sunplus-sp7021.c b/drivers/spi/spi-sunplus-sp7021.c
index ba5ed9f7277a3..fc61578ce5c47 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) {
-- 
2.26.3


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

* Re: [PATCH] spi: initialize ret variable
  2022-02-09 16:30 [PATCH] spi: initialize ret variable trix
@ 2022-02-09 16:33 ` Mark Brown
  2022-02-09 16:44   ` Tom Rix
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2022-02-09 16:33 UTC (permalink / raw)
  To: trix; +Cc: lhjeff911, nathan, ndesaulniers, linux-spi, linux-kernel, llvm

[-- Attachment #1: Type: text/plain, Size: 457 bytes --]

On Wed, Feb 09, 2022 at 08:30:29AM -0800, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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.

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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] spi: initialize ret variable
  2022-02-09 16:33 ` Mark Brown
@ 2022-02-09 16:44   ` Tom Rix
  2022-02-09 17:04     ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Rix @ 2022-02-09 16:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: lhjeff911, nathan, ndesaulniers, linux-spi, linux-kernel, llvm


On 2/9/22 8:33 AM, Mark Brown wrote:
> On Wed, Feb 09, 2022 at 08:30:29AM -0800, trix@redhat.com wrote:
>> From: Tom Rix <trix@redhat.com>
>>
>> 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.
> 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


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

* Re: [PATCH] spi: initialize ret variable
  2022-02-09 16:44   ` Tom Rix
@ 2022-02-09 17:04     ` Mark Brown
       [not found]       ` <CAGcXWkyCQ4JExvHv3cEL7vLMOcq_iPu0vOyOmnfzbQmMxHEp=Q@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2022-02-09 17:04 UTC (permalink / raw)
  To: Tom Rix; +Cc: lhjeff911, nathan, ndesaulniers, linux-spi, linux-kernel, llvm

[-- Attachment #1: Type: text/plain, Size: 946 bytes --]

On Wed, Feb 09, 2022 at 08:44:21AM -0800, Tom Rix wrote:
> On 2/9/22 8:33 AM, Mark Brown wrote:
> > On Wed, Feb 09, 2022 at 08:30:29AM -0800, trix@redhat.com wrote:

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

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

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] spi: initialize ret variable
       [not found]         ` <27a1822d798641f5bba33d7529ec02c0@sphcmbx02.sunplus.com.tw>
@ 2022-02-10  2:45           ` 郭力豪
  0 siblings, 0 replies; 5+ messages in thread
From: 郭力豪 @ 2022-02-10  2:45 UTC (permalink / raw)
  To: Lh Kuo 郭力豪
  Cc: Tom Rix, nathan, ndesaulniers, linux-spi, linux-kernel, llvm, Mark Brown

>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



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

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

end of thread, other threads:[~2022-02-10  2:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 16:30 [PATCH] spi: initialize ret variable trix
2022-02-09 16:33 ` Mark Brown
2022-02-09 16:44   ` Tom Rix
2022-02-09 17:04     ` Mark Brown
     [not found]       ` <CAGcXWkyCQ4JExvHv3cEL7vLMOcq_iPu0vOyOmnfzbQmMxHEp=Q@mail.gmail.com>
     [not found]         ` <27a1822d798641f5bba33d7529ec02c0@sphcmbx02.sunplus.com.tw>
2022-02-10  2:45           ` 郭力豪

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