Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1343475 > unrolled thread
| Started by | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| First post | 2016-02-25 21:50 +0100 |
| Last post | 2016-02-26 15:00 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] serial: ifx6x60: avoid uninitialized variable use Arnd Bergmann <arnd@arndb.de> - 2016-02-25 21:50 +0100
Re: [PATCH] serial: ifx6x60: avoid uninitialized variable use One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2016-02-26 01:10 +0100
Re: [PATCH] serial: ifx6x60: avoid uninitialized variable use Arnd Bergmann <arnd@arndb.de> - 2016-02-26 15:00 +0100
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2016-02-25 21:50 +0100 |
| Subject | [PATCH] serial: ifx6x60: avoid uninitialized variable use |
| Message-ID | <r6b1f-Rb-7@gated-at.bofh.it> |
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: Arnd Bergmann <arnd@arndb.de>
---
drivers/tty/serial/ifx6x60.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/tty/serial/ifx6x60.c b/drivers/tty/serial/ifx6x60.c
index 88246f7e435a..2085a6cfa44b 100644
--- a/drivers/tty/serial/ifx6x60.c
+++ b/drivers/tty/serial/ifx6x60.c
@@ -395,8 +395,10 @@ static int ifx_spi_decode_spi_header(unsigned char *buffer, int *length,
if (h1 == 0 && h2 == 0) {
*received_cts = 0;
+ *more = 0;
return IFX_SPI_HEADER_0;
} else if (h1 == 0xffff && h2 == 0xffff) {
+ *more = 0;
/* spi_slave_cts remains as it was */
return IFX_SPI_HEADER_F;
}
@@ -688,6 +690,7 @@ static void ifx_spi_complete(void *ctx)
ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD,
(size_t)actual_length);
} else {
+ more = 0;
dev_dbg(&ifx_dev->spi_dev->dev, "SPI transfer error %d",
ifx_dev->spi_msg.status);
}
--
2.7.0
[toc] | [next] | [standalone]
| From | One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> |
|---|---|
| Date | 2016-02-26 01:10 +0100 |
| Message-ID | <r6e8O-3hS-19@gated-at.bofh.it> |
| In reply to | #1343475 |
On Thu, 25 Feb 2016 21:47:57 +0100 Arnd Bergmann <arnd@arndb.de> wrote: > 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. Would it not be far simpler just to set more = 0 at the top of ifx_spi_complete ?
[toc] | [prev] | [next] | [standalone]
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2016-02-26 15:00 +0100 |
| Message-ID | <r6r62-44C-21@gated-at.bofh.it> |
| In reply to | #1343601 |
On Friday 26 February 2016 00:06:51 One Thousand Gnomes wrote: > On Thu, 25 Feb 2016 21:47:57 +0100 > Arnd Bergmann <arnd@arndb.de> wrote: > > > 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. > > Would it not be far simpler just to set more = 0 at the top of > ifx_spi_complete ? > > That would be simpler, but I generally don't like to do that, because it makes it less obvious where the value is coming from. In this case, it's still not obvious, as I was just guessing what the original intention might have been. Arnd
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web