* [PATCH] spi: Initialize variable to prevent uninitialized warning
@ 2014-08-07 4:51 Nick Krause
[not found] ` <1407387060-28992-1-git-send-email-xerofoiify-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Nick Krause @ 2014-08-07 4:51 UTC (permalink / raw)
To: Mark Brown, open list:SPI SUBSYSTEM, open list
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 <xerofoify-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/spi/spi-bfin5xx.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/spi/spi-bfin5xx.c b/drivers/spi/spi-bfin5xx.c
index ebf720b..f268bf4 100644
--- a/drivers/spi/spi-bfin5xx.c
+++ b/drivers/spi/spi-bfin5xx.c
@@ -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);
--
2.0.1
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: Initialize variable to prevent uninitialized warning
[not found] ` <1407387060-28992-1-git-send-email-xerofoiify-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-08-07 5:22 ` Guenter Roeck
[not found] ` <20140807052219.GA21124-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2014-08-07 5:22 UTC (permalink / raw)
To: Nick Krause; +Cc: Mark Brown, open list:SPI SUBSYSTEM, open list
On Thu, Aug 07, 2014 at 06:51:00AM +0200, Nick Krause wrote:
> 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 <xerofoify-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
> drivers/spi/spi-bfin5xx.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi-bfin5xx.c b/drivers/spi/spi-bfin5xx.c
> index ebf720b..f268bf4 100644
> --- a/drivers/spi/spi-bfin5xx.c
> +++ b/drivers/spi/spi-bfin5xx.c
> @@ -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;
> }
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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: Initialize variable to prevent uninitialized warning
[not found] ` <20140807052219.GA21124-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2014-08-07 9:55 ` Mark Brown
0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-08-07 9:55 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Nick Krause, open list:SPI SUBSYSTEM, open list
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
On Wed, Aug 06, 2014 at 10:22:19PM -0700, Guenter Roeck wrote:
> 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.
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.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-07 9:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-07 4:51 [PATCH] spi: Initialize variable to prevent uninitialized warning Nick Krause
[not found] ` <1407387060-28992-1-git-send-email-xerofoiify-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-08-07 5:22 ` Guenter Roeck
[not found] ` <20140807052219.GA21124-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2014-08-07 9:55 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).