spi: Initialize variable to prevent uninitialized warning
PATCH 1/1 spi: Initialize variable to prevent uninitialized warning
While compiling we see the following waring
drivers/spi/spi-bfin5xx.c: In function 'bfin_spi_pump_transfers':drivers/spi/spi-bfin5xx.c:695:6: warning: 'cr_width' may be used uninitialized in this function [-Wuninitialized]
Initialize it to prevent the above warning
--- drivers/spi/spi-bfin5xx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-bfin5xx.c +1 -2
@@ -559,7 +559,7 @@ static void bfin_spi_pump_transfers(unsigned long data)struct spi_transfer *previous =NULL ;struct bfin_spi_slave_data *chip =NULL ;unsigned int bits_per_word; -u16 cr, cr_width, dma_width, dma_config; +u16 cr, cr_width =0 , dma_width, dma_config;u32 tranf_success =1 ;u8 full_duplex =0 ;
@@ -648,7 +648,6 @@ static void bfin_spi_pump_transfers(unsigned long data) }else if (bits_per_word ==8 ) { drv_data->n_bytes = bits_per_word/8 ; drv_data->len = transfer->len; - cr_width =0 ; drv_data->ops = &bfin_bfin_spi_transfer_ops_u8; } cr =bfin_read (&drv_data->regs->ctl) & ~(BIT_CTL_TIMOD |BIT_CTL_WORDSIZE );
Signature · 1 line
2.0.1
Quoted 27 lines · Nick Krause
While compiling we see the following waring
drivers/spi/spi-bfin5xx.c: In function 'bfin_spi_pump_transfers':drivers/spi/spi-bfin5xx.c:695:6: warning: 'cr_width' may be used uninitialized in this function [-Wuninitialized]Initialize it to prevent the above warning
Signed-off-by Nick Krause <[email protected]>--- drivers/spi/spi-bfin5xx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/spi/spi-bfin5xx.c +1
-1@@ -559,7 +559,7 @@ static void bfin_spi_pump_transfers(unsigned long data)struct spi_transfer *previous =NULL ;struct bfin_spi_slave_data *chip =NULL ;unsigned int bits_per_word; -u16 cr, cr_width, dma_width, dma_config; +u16 cr, cr_width =0 , dma_width, dma_config;u32 tranf_success =1 ;u8 full_duplex =0 ;
drivers/spi/spi-bfin5xx.c static void bfin_spi_pump_transfers(unsigned long data) · line 652
Quoted 6 lines
drivers/spi/spi-bfin5xx.c +0
-1@@ -648,7 +648,6 @@ static void bfin_spi_pump_transfers(unsigned long data) }else if (bits_per_word ==8 ) { drv_data->n_bytes = bits_per_word/8 ; drv_data->len = transfer->len; - cr_width =0 ; drv_data->ops = &bfin_bfin_spi_transfer_ops_u8; }
So if we ever hit that uninitialized case, where bits_per_word is neither 8 nor 16, we'll have ops set to NULL and end up wondering why the kernel crashes a bit further down in the code. Not really sure if that is an improvement.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
maintainerQuoted 4 lines · Guenter Roeck
So if we ever hit that uninitialized case, where
bits_per_wordis neither 8 nor 16, we'll have ops set to NULL and end up wondering why the kernel crashes a bit further down in the code. Not really sure if that is an improvement.
It's not. The goal isn't to fix the warning, it's to fix the problem the compiler is telling you about - initialising to the wrong value is just as bad as not being initialised at all.