Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1343475

[PATCH] serial: ifx6x60: avoid uninitialized variable use

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject [PATCH] serial: ifx6x60: avoid uninitialized variable use
Date Thu, 25 Feb 2016 21:50:01 +0100
Message-ID <r6b1f-Rb-7@gated-at.bofh.it> (permalink)
X-Mailer git-send-email 2.7.0
X-Provags-ID V03:K0:sIPplRCxfLNYIiDahwOuc2yPp+1M7BG7MT5glXBveIHnKVGEyUd HpDwpmwmZSkbTIgCIZ6jsaKxiBjcnvEFCyBuArWw5jPZqH9QWx8GFiJMo5wxCztElZquc0l 0PVVrQGnHq1KVLAohFt5okHfZGhz4o5IEOoERd9jTPDBbb1rnMAzhm2NChtqe3T7+03qo/W iEbIooXVPQsuVnfEAaz0w==
X-Ui-Out-Filterresults notjunk:1;V01:K0:XNolTJCjITQ=:/J/dQ94hXk0m9XQ/ze3ieR 5n5wDlUaHj8qAZMv6wgAfTTTbJaGjLQQLCzhFSM0lwafBIT80tSub6RwokKCiM8I5Cbl9eaNk 1KDq3eKOrF5xcwO9nmb3WgXFZdNs+1MdLkhb92/PJ3chaanZKxRocKd2ASyelQgse6rGvyc/4 AsPWbIeijt1C2vMATpRL1BKA5nibwsfyNH/o4QKhCmZQ9eZ2Qke9G6ldqUKXxymngPk2RoN6p ocVdAIOyEliZW79enmFRREguf38LAR+FLLp7kPxJkTnH1mZZopR8s3kXeiKALJ/XdleDmI/Cl Vr5G8CYbU3i9EGuySj2AnAkRWfNxtncIUIz/yGdx/sbr+1b//PeKcMBvDg97GJ1/oU1J34ehH X0SW7EXafGY/w9TOHrTRTNkLQit8kHVtLpgqzeNqeuxfcoQEQsSj+mIlOQopyNq9plyY5lkoL r3m0iolnU3ojRpwfDqQnYGxRerT0xxgu0TZ3PMyDruzM7cv1ds8BxYehEuXtojieEIU06/8HE 2d1TNmPObz9dPFyu+yv2wmSqMkMS7z0F9qRSlHVHTlu+iPawNcpZIeEBqp2clAttNosz/ZlpP bjOyhlu3qnGFp+1fSOZC7ESGZuffpgnCpJqEl+GLMS54p3XUKlb66b7cQGmTWY77Pa5yDTiu4 xn21OA1A18DD4qszNyOF2f0uMgdBtoK2t142FFT3L1euSi9kq66DyL4SGsXsGRuMD1AY=
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 51
Organization linux.* mail to news gateway
X-Original-Cc linux-arm-kernel@lists.infradead.org, Russ Gorby <richardx.r.gorby@intel.com>, Alan Cox <alan@linux.intel.com>, Arnd Bergmann <arnd@arndb.de>, Jiri Slaby <jslaby@suse.com>, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
X-Original-Date Thu, 25 Feb 2016 21:47:57 +0100
X-Original-Message-ID <1456433283-3761559-1-git-send-email-arnd@arndb.de>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1343475

Show key headers only | View raw


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

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[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

csiph-web