diff mbox

spi: fsl-lpspi: Pre-initialize ret in fsl_lpspi_transfer_one_msg()

Message ID 1481714455-14224-1-git-send-email-geert@linux-m68k.org (mailing list archive)
State Accepted
Commit cc4a7ffe02c95f537541c91e9842e3710decae6e
Headers show

Commit Message

Geert Uytterhoeven Dec. 14, 2016, 11:20 a.m. UTC
With gcc 4.1.2:

    drivers/spi/spi-fsl-lpspi.c: In function ‘fsl_lpspi_transfer_one_msg’:
    drivers/spi/spi-fsl-lpspi.c:369: warning: ‘ret’ may be used uninitialized in this function

If the message contains no transfers, the function will set the
message's status to an uninitialized value, and will return that
uninitialized value.

While __spi_validate() should have been called in all paths leading to
this, and thus have rejected such messages, we better pre-initialize ret
to be safe for future modifications (spi_transfer_one_message() also
does this).

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/spi/spi-fsl-lpspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Gao Pan Dec. 14, 2016, 12:05 p.m. UTC | #1
> From: Geert Uytterhoeven [mailto:geert@linux-m68k.org]

> Sent: Wednesday, December 14, 2016 7:21 PM

> To: Mark Brown <broonie@kernel.org>; Pandy Gao

> <pandy.gao@nxp.com>

> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Geert

> Uytterhoeven <geert@linux-m68k.org>

> Subject: [PATCH] spi: fsl-lpspi: Pre-initialize ret in

> fsl_lpspi_transfer_one_msg()

> 

> With gcc 4.1.2:

> 

>     drivers/spi/spi-fsl-lpspi.c: In function ‘fsl_lpspi_transfer_one_msg’:

>     drivers/spi/spi-fsl-lpspi.c:369: warning: ‘ret’ may be used uninitialized

> in this function

> 

> If the message contains no transfers, the function will set the message's

> status to an uninitialized value, and will return that uninitialized value.

> 

> While __spi_validate() should have been called in all paths leading to this,

> and thus have rejected such messages, we better pre-initialize ret to be

> safe for future modifications (spi_transfer_one_message() also does this).

> 

> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

> ---


Acked-by: Gao Pan <pandy.gao@nxp.com>


Best Regards
Pandy
diff mbox

Patch

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 52551f6d0c7ddf71..2b93bc605b91c5ec 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -366,7 +366,7 @@  static int fsl_lpspi_transfer_one_msg(struct spi_master *master,
 	struct spi_transfer *xfer;
 	bool is_first_xfer = true;
 	u32 temp;
-	int ret;
+	int ret = 0;
 
 	msg->status = 0;
 	msg->actual_length = 0;