All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: kernel test robot <lkp@intel.com>,
	Daniel Starke <daniel.starke@siemens.com>,
	llvm@lists.linux.dev, kbuild-all@lists.01.org,
	linux-serial@vger.kernel.org
Subject: Re: [tty:tty-linus 23/26] drivers/tty/n_gsm.c:939:13: warning: variable 'size' is used uninitialized whenever 'if' condition is false
Date: Sun, 24 Apr 2022 15:02:54 -0700	[thread overview]
Message-ID: <YmXJDmMWBKwDKSmf@dev-arch.thelio-3990X> (raw)
In-Reply-To: <YmO7C2dZTVxSNUQe@kroah.com>

On Sat, Apr 23, 2022 at 10:38:35AM +0200, Greg Kroah-Hartman wrote:
> On Sat, Apr 23, 2022 at 07:42:41AM +0800, kernel test robot wrote:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-linus
> > head:   637674fa40059cddcc3ad2212728965072f62ea3
> > commit: c19ffe00fed6bb423d81406d2a7e5793074c7d83 [23/26] tty: n_gsm: fix invalid use of MSC in advanced option
> > config: hexagon-randconfig-r035-20220422 (https://download.01.org/0day-ci/archive/20220423/202204230704.5MxboEEo-lkp@intel.com/config)
> > compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5bd87350a5ae429baf8f373cb226a57b62f87280)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?id=c19ffe00fed6bb423d81406d2a7e5793074c7d83
> >         git remote add tty https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
> >         git fetch --no-tags tty tty-linus
> >         git checkout c19ffe00fed6bb423d81406d2a7e5793074c7d83
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/tty/
> > 
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > All warnings (new ones prefixed by >>):
> > 
> > >> drivers/tty/n_gsm.c:939:13: warning: variable 'size' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> >            } else if (dlci->adaption == 2) {
> >                       ^~~~~~~~~~~~~~~~~~~
> >    drivers/tty/n_gsm.c:948:40: note: uninitialized use occurs here
> >            msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
> >                                                  ^~~~
> >    drivers/tty/n_gsm.c:939:9: note: remove the 'if' if its condition is always true
> >            } else if (dlci->adaption == 2) {
> >                   ^~~~~~~~~~~~~~~~~~~~~~~~~
> >    drivers/tty/n_gsm.c:934:10: note: initialize the variable 'size' to silence this warning
> >            int size;
> >                    ^
> >                     = 0
> >    1 warning generated.
> > 
> 
> It's not obvious, but this should be fine as adaption is only 1 or 2
> from what I can tell.
> 
> To make the compiler understand this easier, this should probably be an
> enum and use switch statements.  Daniel, want to make that change?

Alternatively, 'return -EINVAL' or something similar in the 'else'
branch of the first if statement? The error message makes it seem like
the function shouldn't continue but it does.

Cheers,
Nathan

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Chancellor <nathan@kernel.org>
To: kbuild-all@lists.01.org
Subject: Re: [tty:tty-linus 23/26] drivers/tty/n_gsm.c:939:13: warning: variable 'size' is used uninitialized whenever 'if' condition is false
Date: Sun, 24 Apr 2022 15:02:54 -0700	[thread overview]
Message-ID: <YmXJDmMWBKwDKSmf@dev-arch.thelio-3990X> (raw)
In-Reply-To: <YmO7C2dZTVxSNUQe@kroah.com>

[-- Attachment #1: Type: text/plain, Size: 2889 bytes --]

On Sat, Apr 23, 2022 at 10:38:35AM +0200, Greg Kroah-Hartman wrote:
> On Sat, Apr 23, 2022 at 07:42:41AM +0800, kernel test robot wrote:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-linus
> > head:   637674fa40059cddcc3ad2212728965072f62ea3
> > commit: c19ffe00fed6bb423d81406d2a7e5793074c7d83 [23/26] tty: n_gsm: fix invalid use of MSC in advanced option
> > config: hexagon-randconfig-r035-20220422 (https://download.01.org/0day-ci/archive/20220423/202204230704.5MxboEEo-lkp(a)intel.com/config)
> > compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5bd87350a5ae429baf8f373cb226a57b62f87280)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?id=c19ffe00fed6bb423d81406d2a7e5793074c7d83
> >         git remote add tty https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
> >         git fetch --no-tags tty tty-linus
> >         git checkout c19ffe00fed6bb423d81406d2a7e5793074c7d83
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/tty/
> > 
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > All warnings (new ones prefixed by >>):
> > 
> > >> drivers/tty/n_gsm.c:939:13: warning: variable 'size' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> >            } else if (dlci->adaption == 2) {
> >                       ^~~~~~~~~~~~~~~~~~~
> >    drivers/tty/n_gsm.c:948:40: note: uninitialized use occurs here
> >            msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
> >                                                  ^~~~
> >    drivers/tty/n_gsm.c:939:9: note: remove the 'if' if its condition is always true
> >            } else if (dlci->adaption == 2) {
> >                   ^~~~~~~~~~~~~~~~~~~~~~~~~
> >    drivers/tty/n_gsm.c:934:10: note: initialize the variable 'size' to silence this warning
> >            int size;
> >                    ^
> >                     = 0
> >    1 warning generated.
> > 
> 
> It's not obvious, but this should be fine as adaption is only 1 or 2
> from what I can tell.
> 
> To make the compiler understand this easier, this should probably be an
> enum and use switch statements.  Daniel, want to make that change?

Alternatively, 'return -EINVAL' or something similar in the 'else'
branch of the first if statement? The error message makes it seem like
the function shouldn't continue but it does.

Cheers,
Nathan

  reply	other threads:[~2022-04-24 22:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 23:42 [tty:tty-linus 23/26] drivers/tty/n_gsm.c:939:13: warning: variable 'size' is used uninitialized whenever 'if' condition is false kernel test robot
2022-04-23  8:38 ` Greg Kroah-Hartman
2022-04-23  8:38   ` Greg Kroah-Hartman
2022-04-24 22:02   ` Nathan Chancellor [this message]
2022-04-24 22:02     ` Nathan Chancellor
2022-04-25  7:04 Starke, Daniel
2022-04-25  7:04 Starke, Daniel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YmXJDmMWBKwDKSmf@dev-arch.thelio-3990X \
    --to=nathan@kernel.org \
    --cc=daniel.starke@siemens.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.