Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751420AbdINPOF (ORCPT ); Thu, 14 Sep 2017 11:14:05 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:52937 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751131AbdINPOE (ORCPT ); Thu, 14 Sep 2017 11:14:04 -0400 Subject: Re: [PATCH] mtd: spi-nor: stm32-quadspi: avoid unintialized return code To: Geert Uytterhoeven , Arnd Bergmann CC: Cyrille Pitchen , Marek Vasut , Boris Brezillon , Alexandre Torgue , Richard Weinberger , "linux-kernel@vger.kernel.org" , MTD Maling List , "linux-arm-kernel@lists.infradead.org" , Maxime Coquelin , Brian Norris , David Woodhouse References: <20170914110709.3591691-1-arnd@arndb.de> From: Ludovic BARRE Message-ID: Date: Thu, 14 Sep 2017 17:13:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) To SFHDAG6NODE1.st.com (10.75.127.16) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-09-14_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2295 Lines: 64 hi Arnd, Geert On 09/14/2017 03:38 PM, Geert Uytterhoeven wrote: > Hi Arnd, > > On Thu, Sep 14, 2017 at 1:06 PM, Arnd Bergmann wrote: >> If we send zero-length data to stm32_qspi_tx_poll() on older >> compiler versions such as gcc-4.6, we get warned that the >> return code is uninitialized: >> >> drivers/mtd/spi-nor/stm32-quadspi.c:248:2: error: ‘ret’ may be used uninitialized in this function [-Werror=uninitialized] >> >> On newer compiler versions, the return code is always zero >> in this case, as the local variable gets optimized away and >> is assumed to be zero after the loop completes without error. >> >> This changes the function to instead return -EINVAL if it >> ever gets called with a zero length buffer. >> >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203 >> Signed-off-by: Arnd Bergmann >> --- >> drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/spi-nor/stm32-quadspi.c b/drivers/mtd/spi-nor/stm32-quadspi.c >> index 86c0931543c5..711cfe7aa4bf 100644 >> --- a/drivers/mtd/spi-nor/stm32-quadspi.c >> +++ b/drivers/mtd/spi-nor/stm32-quadspi.c >> @@ -227,7 +227,7 @@ static int stm32_qspi_tx_poll(struct stm32_qspi *qspi, >> void (*tx_fifo)(u8 *, void __iomem *); >> u32 len = cmd->len, sr; >> u8 *buf = cmd->buf; >> - int ret; >> + int ret = -EINVAL; >> >> if (cmd->qspimode == CCR_FMODE_INDW) >> tx_fifo = stm32_qspi_write_fifo; > > See also "[PATCH] mtd: spi-nor: stm32-quadspi: Fix uninitialized error > return code" > (https://patchwork.kernel.org/patch/9842173/) hi Arnd, Geert sorry, I was forgot this thread while my holidays Geert: what do you mean like "similar bugs in the future" in "If you initialized ret at the beginning, you lose the ability to catch newly introduced similar bugs in the future." > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds >