linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: sh-sci: fix uninitialized variable warning
@ 2019-06-13 18:08 Charles
  2019-06-13 20:13 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Charles @ 2019-06-13 18:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-kernel, rodrigosiqueiramelo

Avoid following compiler warning on uninitialized variable

In file included from ./include/linux/rwsem.h:16:0,
                 from ./include/linux/notifier.h:15,
                 from ./include/linux/clk.h:17,
                 from drivers/tty/serial/sh-sci.c:24:
drivers/tty/serial/sh-sci.c: In function ‘sci_dma_rx_submit’:
./include/linux/spinlock.h:288:3: warning: ‘flags’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
   _raw_spin_unlock_irqrestore(lock, flags); \
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/tty/serial/sh-sci.c:1353:16: note: ‘flags’ was declared here
  unsigned long flags;
                ^~~~~

Signed-off-by: Charles Oliveira <18oliveira.charles@gmail.com>
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index abc705716aa0..a6af73eaec11 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1350,7 +1350,7 @@ static int sci_dma_rx_submit(struct sci_port *s, bool port_lock_held)
 {
 	struct dma_chan *chan = s->chan_rx;
 	struct uart_port *port = &s->port;
-	unsigned long flags;
+	unsigned long uninitialized_var(flags);
 	int i;
 
 	for (i = 0; i < 2; i++) {
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] serial: sh-sci: fix uninitialized variable warning
  2019-06-13 18:08 [PATCH] serial: sh-sci: fix uninitialized variable warning Charles
@ 2019-06-13 20:13 ` Geert Uytterhoeven
  2019-06-18  7:38 ` Greg Kroah-Hartman
  2020-06-20  3:38 ` Kees Cook
  2 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2019-06-13 20:13 UTC (permalink / raw)
  To: Charles
  Cc: Greg Kroah-Hartman, Jiri Slaby, open list:SERIAL DRIVERS,
	Linux Kernel Mailing List, rodrigosiqueiramelo

Hi Charles,

On Thu, Jun 13, 2019 at 8:09 PM Charles <18oliveira.charles@gmail.com> wrote:
> Avoid following compiler warning on uninitialized variable
>
> In file included from ./include/linux/rwsem.h:16:0,
>                  from ./include/linux/notifier.h:15,
>                  from ./include/linux/clk.h:17,
>                  from drivers/tty/serial/sh-sci.c:24:
> drivers/tty/serial/sh-sci.c: In function ‘sci_dma_rx_submit’:
> ./include/linux/spinlock.h:288:3: warning: ‘flags’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>    _raw_spin_unlock_irqrestore(lock, flags); \
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/tty/serial/sh-sci.c:1353:16: note: ‘flags’ was declared here
>   unsigned long flags;
>                 ^~~~~
>
> Signed-off-by: Charles Oliveira <18oliveira.charles@gmail.com>

Thanks for your patch, but this is a false positive: the compiler is not
smart enough to realize that both initialization and use depend on
the same condition.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] serial: sh-sci: fix uninitialized variable warning
  2019-06-13 18:08 [PATCH] serial: sh-sci: fix uninitialized variable warning Charles
  2019-06-13 20:13 ` Geert Uytterhoeven
@ 2019-06-18  7:38 ` Greg Kroah-Hartman
  2019-06-18 19:35   ` Charles Oliveira
  2020-06-20  3:38 ` Kees Cook
  2 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-18  7:38 UTC (permalink / raw)
  To: Charles; +Cc: Jiri Slaby, linux-serial, linux-kernel, rodrigosiqueiramelo

On Thu, Jun 13, 2019 at 03:08:24PM -0300, Charles wrote:
> Avoid following compiler warning on uninitialized variable
> 
> In file included from ./include/linux/rwsem.h:16:0,
>                  from ./include/linux/notifier.h:15,
>                  from ./include/linux/clk.h:17,
>                  from drivers/tty/serial/sh-sci.c:24:
> drivers/tty/serial/sh-sci.c: In function ‘sci_dma_rx_submit’:
> ./include/linux/spinlock.h:288:3: warning: ‘flags’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>    _raw_spin_unlock_irqrestore(lock, flags); \
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/tty/serial/sh-sci.c:1353:16: note: ‘flags’ was declared here
>   unsigned long flags;
>                 ^~~~~

What version of gcc is doing this?  It should be smarter than that,
perhaps you should just upgrade.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] serial: sh-sci: fix uninitialized variable warning
  2019-06-18  7:38 ` Greg Kroah-Hartman
@ 2019-06-18 19:35   ` Charles Oliveira
  0 siblings, 0 replies; 5+ messages in thread
From: Charles Oliveira @ 2019-06-18 19:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby, linux-serial, linux-kernel, Rodrigo Siqueira

On Tue, Jun 18, 2019 at 4:38 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Thu, Jun 13, 2019 at 03:08:24PM -0300, Charles wrote:
> > Avoid following compiler warning on uninitialized variable
> >
> > In file included from ./include/linux/rwsem.h:16:0,
> >                  from ./include/linux/notifier.h:15,
> >                  from ./include/linux/clk.h:17,
> >                  from drivers/tty/serial/sh-sci.c:24:
> > drivers/tty/serial/sh-sci.c: In function ‘sci_dma_rx_submit’:
> > ./include/linux/spinlock.h:288:3: warning: ‘flags’ may be used
> > uninitialized in this function [-Wmaybe-uninitialized]
> >    _raw_spin_unlock_irqrestore(lock, flags); \
> >    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> > drivers/tty/serial/sh-sci.c:1353:16: note: ‘flags’ was declared here
> >   unsigned long flags;
> >                 ^~~~~
>
> What version of gcc is doing this?  It should be smarter than that,
> perhaps you should just upgrade.

Yep, worked like a charm. I was running gcc 6.3.0, just updated to 8.3.0
and got rid of that warning.

Thanks, Greg
>
> thanks,
>
> greg k-h



-- 
Charles

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] serial: sh-sci: fix uninitialized variable warning
  2019-06-13 18:08 [PATCH] serial: sh-sci: fix uninitialized variable warning Charles
  2019-06-13 20:13 ` Geert Uytterhoeven
  2019-06-18  7:38 ` Greg Kroah-Hartman
@ 2020-06-20  3:38 ` Kees Cook
  2 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2020-06-20  3:38 UTC (permalink / raw)
  To: Charles
  Cc: Greg Kroah-Hartman, Andrew Morton, Jiri Slaby, linux-serial,
	linux-kernel, rodrigosiqueiramelo

On Thu, Jun 13, 2019 at 03:08:24PM -0300, Charles wrote:
> Avoid following compiler warning on uninitialized variable
> 
> In file included from ./include/linux/rwsem.h:16:0,
>                  from ./include/linux/notifier.h:15,
>                  from ./include/linux/clk.h:17,
>                  from drivers/tty/serial/sh-sci.c:24:
> drivers/tty/serial/sh-sci.c: In function ‘sci_dma_rx_submit’:
> ./include/linux/spinlock.h:288:3: warning: ‘flags’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>    _raw_spin_unlock_irqrestore(lock, flags); \
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/tty/serial/sh-sci.c:1353:16: note: ‘flags’ was declared here
>   unsigned long flags;
>                 ^~~~~
> 
> Signed-off-by: Charles Oliveira <18oliveira.charles@gmail.com>
> ---
>  drivers/tty/serial/sh-sci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index abc705716aa0..a6af73eaec11 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -1350,7 +1350,7 @@ static int sci_dma_rx_submit(struct sci_port *s, bool port_lock_held)
>  {
>  	struct dma_chan *chan = s->chan_rx;
>  	struct uart_port *port = &s->port;
> -	unsigned long flags;
> +	unsigned long uninitialized_var(flags);

akpm made this same change in -mm, and it's not the right
solution[1]. Please just initialize it to 0 if the compiler can't figure
it out. :)

-Kees

[1] https://lore.kernel.org/lkml/20200620033007.1444705-2-keescook@chromium.org/

>  	int i;
>  
>  	for (i = 0; i < 2; i++) {
> -- 
> 2.11.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-20  3:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13 18:08 [PATCH] serial: sh-sci: fix uninitialized variable warning Charles
2019-06-13 20:13 ` Geert Uytterhoeven
2019-06-18  7:38 ` Greg Kroah-Hartman
2019-06-18 19:35   ` Charles Oliveira
2020-06-20  3:38 ` Kees Cook

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).