Re: [PATCH] vt: keyboard, fix uninitialized variables warning

From: Greg KH
Date: Wed Mar 03 2021 - 07:40:48 EST


On Wed, Mar 03, 2021 at 03:33:23PM +0800, Wang, Li wrote:
>
> On 3/3/2021 3:14 PM, Greg KH wrote:
> > On Wed, Mar 03, 2021 at 12:59:32PM +0800, Li Wang wrote:
> > > drivers/tty/vt/keyboard.c: In function 'vt_do_kdgkb_ioctl':
> > > drivers/tty/vt/keyboard.c: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
> > > return ret;
> > > ^~~
> > > kernel-source/drivers/tty/vt/keyboard.c: warning: 'kbs' may be used uninitialized in this function [-Wmaybe-uninitialized]
> > > kfree(kbs);
> > > ^~~~~~~~~~
> > >
> > > Signed-off-by: Li Wang <li.wang@xxxxxxxxxxxxx>
> > > ---
> > > drivers/tty/vt/keyboard.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> > > index 7763862..3e73d55 100644
> > > --- a/drivers/tty/vt/keyboard.c
> > > +++ b/drivers/tty/vt/keyboard.c
> > > @@ -2049,8 +2049,8 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> > > {
> > > unsigned char kb_func;
> > > unsigned long flags;
> > > - char *kbs;
> > > - int ret;
> > > + char *kbs = NULL;
> > > + int ret = -EINVAL;
> > > if (get_user(kb_func, &user_kdgkb->kb_func))
> > > return -EFAULT;
> > What compiler is providing these "warnings"?
> >
> > Turns out it is impossible to hit, so this isn't actually fixing
> > anything...
>
> I tested it with gcc 8.2 for arm
>
> for runtime codes view, indeed it is impossible to hit.
>
> but for compiler view, gcc should give 'used uninitialized' warning, too.

Odd that no other compiler version does this right now, perhaps upgrade
to a newer version of gcc? 8.2 is really old :(

thanks,

greg k-h