Commit 0b8053fe authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

serial: ifx6x60: avoid uninitialized variable use

gcc warns about a potential use of an uninitialized variable in this driver:

drivers/tty/serial/ifx6x60.c: In function 'ifx_spi_complete':
drivers/tty/serial/ifx6x60.c:713:6: warning: 'more' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (more || ifx_dev->spi_more || queue_length > 0 ||

Unlike a lot of other such warnings, this one is correct and describes
an actual problem in the handling of the "IFX_SPI_HEADER_F" result code.

This appears to be a result from a restructuring of the driver that
dates back to before it was merged in the kernel, so it's impossible
to know where it went wrong. I also don't know what that result code
means, so I have no idea if setting 'more' to zero is the correct
solution, but at least it makes the behavior reproducible rather than
depending on whatever happens to be on the kernel stack.

This patch initializes the 'more' variable to zero in each of the
three code paths that could result in undefined behavior before,
which is more explicit than initializing it at the start of the
function.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2958ccee
...@@ -395,8 +395,10 @@ static int ifx_spi_decode_spi_header(unsigned char *buffer, int *length, ...@@ -395,8 +395,10 @@ static int ifx_spi_decode_spi_header(unsigned char *buffer, int *length,
if (h1 == 0 && h2 == 0) { if (h1 == 0 && h2 == 0) {
*received_cts = 0; *received_cts = 0;
*more = 0;
return IFX_SPI_HEADER_0; return IFX_SPI_HEADER_0;
} else if (h1 == 0xffff && h2 == 0xffff) { } else if (h1 == 0xffff && h2 == 0xffff) {
*more = 0;
/* spi_slave_cts remains as it was */ /* spi_slave_cts remains as it was */
return IFX_SPI_HEADER_F; return IFX_SPI_HEADER_F;
} }
...@@ -688,6 +690,7 @@ static void ifx_spi_complete(void *ctx) ...@@ -688,6 +690,7 @@ static void ifx_spi_complete(void *ctx)
ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD, ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD,
(size_t)actual_length); (size_t)actual_length);
} else { } else {
more = 0;
dev_dbg(&ifx_dev->spi_dev->dev, "SPI transfer error %d", dev_dbg(&ifx_dev->spi_dev->dev, "SPI transfer error %d",
ifx_dev->spi_msg.status); ifx_dev->spi_msg.status);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment