mtd: spi-nor: stm32-quadspi: avoid unintialized return code
Subsystems (3)
PATCH 1/1 mtd: spi-nor: stm32-quadspi: avoid unintialized return code
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
--- drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/stm32-quadspi.c +1 -1
@@ -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;
Signature · 1 line
2.9.0
hi Arnd
thx Arnd for compilation warning (gcc <= 4.6)
PS: at runtime stm32_qspi_tx_poll can't be call, because stm32_qspi_tx check if there is tx data available
if (!cmd->tx_data) return 0;
BR
Ludo
Quoted 33 lines · Arnd Bergmann
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
-EINVALif it ever gets called with a zero length buffer.https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
Signed-off-by Arnd Bergmann <[email protected]>--- drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi-nor/stm32-quadspi.c +1
-1@@ -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;
Hi Arnd,
Quoted 24 lines · Arnd Bergmann
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
-EINVALif it ever gets called with a zero length buffer.https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
Signed-off-by Arnd Bergmann <[email protected]>--- drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi-nor/stm32-quadspi.c +0
-0
drivers/mtd/spi-nor/stm32-quadspi.c static int stm32_qspi_tx_poll(struct stm32_qspi *qspi, · line 233
Quoted 8 lines
drivers/mtd/spi-nor/stm32-quadspi.c +1
-1@@ -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/)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
hi Arnd, Geert
Quoted 33 lines · Geert Uytterhoeven
Hi Arnd,
Quoted 30 lines · Arnd Bergmann
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
-EINVALif it ever gets called with a zero length buffer.https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
Signed-off-by Arnd Bergmann <[email protected]>--- drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi-nor/stm32-quadspi.c +1
-1@@ -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 ;
Quoted 6 lines
drivers/mtd/spi-nor/stm32-quadspi.c static int stm32_qspi_tx_poll(struct stm32_qspi *qspi, · line 233
Quoted 2 lines
drivers/mtd/spi-nor/stm32-quadspi.c +0
-0if (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."
Quoted 12 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.orgIn 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
Hi Ludovic,
Quoted 43 lines · Ludovic BARRE
Quoted 34 lines · Geert Uytterhoeven
Quoted 33 lines · Arnd Bergmann
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
-EINVALif it ever gets called with a zero length buffer.https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
Signed-off-by Arnd Bergmann <[email protected]>--- drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi-nor/stm32-quadspi.c +1
-1@@ -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 ;Quoted 7 lines
Quoted 2 lines
drivers/mtd/spi-nor/stm32-quadspi.c +0
-0if (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/)
Quoted 7 lines
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."
If you pre-initialize ret at the top, you loose the ability of the compiler to detect at compile-time if ret is never written to later. It will just return -EINVAL at runtime.
With my version, if the code is modified later and another "return ret" is added, the compiler will detect if there's a code path that forgets to assign a value to ret.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
Quoted 54 lines · Geert Uytterhoeven
Hi Ludovic,
Quoted 43 lines · Ludovic BARRE
Quoted 34 lines · Geert Uytterhoeven
Quoted 33 lines · Arnd Bergmann
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
-EINVALif it ever gets called with a zero length buffer.https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
Signed-off-by Arnd Bergmann <[email protected]>--- drivers/mtd/spi-nor/stm32-quadspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi-nor/stm32-quadspi.c +1
-1@@ -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 ;Quoted 7 lines
Quoted 2 lines
drivers/mtd/spi-nor/stm32-quadspi.c +0
-0if (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/)Quoted 7 lines
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."
Quoted 7 lines
If you pre-initialize ret at the top, you loose the ability of the compiler to detect at compile-time if ret is never written to later. It will just return
-EINVALat runtime.With my version, if the code is modified later and another "return ret" is added, the compiler will detect if there's a code path that forgets to assign a value to ret.
Ok, it's clear for me.
I favor geert's solution.
Arnd what do you think ?
Quoted 12 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.orgIn 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
Quoted 26 lines · Ludovic BARRE
Quoted 23 lines · Geert Uytterhoeven
Hi Ludovic,
Quoted 10 lines · Ludovic BARRE
On 09/14/2017 03:38 PM, Geert Uytterhoeven wrote:
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."
If you pre-initialize ret at the top, you loose the ability of the compiler
to detect at compile-time if ret is never written to later. It will just return-EINVALat runtime.
Quoted 7 lines
Quoted 3 lines
With my version, if the code is modified later and another "return ret" is added, the compiler will detect if there's a code path that forgets to assign a value to ret.
Ok, it's clear for me.
I favor geert's solution.
Arnd what do you think ?
I usually follow the same rule that Geert explained (and quote
https://rusty.ozlabs.org/?p=232 when I do so). In this case, there did not seem to be much value as the variable is not used afterwards, and I kept the 'single return statement' guideline.
In the end, either version seems totally fine to me here, so please use Geert's if you prefer that.
Arnd
Quoted 35 lines · Arnd Bergmann
Quoted 26 lines · Ludovic BARRE
Quoted 23 lines · Geert Uytterhoeven
Hi Ludovic,
Quoted 10 lines · Ludovic BARRE
On 09/14/2017 03:38 PM, Geert Uytterhoeven wrote:
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."
If you pre-initialize ret at the top, you loose the ability of the compiler
to detect at compile-time if ret is never written to later. It will just return-EINVALat runtime.Quoted 7 lines
Quoted 3 lines
With my version, if the code is modified later and another "return ret" is added, the compiler will detect if there's a code path that forgets to assign a value to ret.
Ok, it's clear for me.
I favor geert's solution.
Arnd what do you think ?
Quoted 7 lines
I usually follow the same rule that Geert explained (and quote
https://rusty.ozlabs.org/?p=232 when I do so). In this case, there did not seem to be much value as the variable is not used afterwards, and I kept the 'single return statement' guideline.In the end, either version seems totally fine to me here, so please use Geert's if you prefer that.
thank Arnd for your answer, great link :-)
we take geert's patch.
Geert: I will acked your patch.
thanks everybody
Quoted 3 lines
Arnd