From: Johan Hovold <johan@kernel.org>
To: Ajay Garg <ajaygargnsit@gmail.com>
Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org,
andriy.shevchenko@linux.intel.com, kernel@esmil.dk,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
paskripkin@gmail.com
Subject: Re: [PATCH v4] tty: vt: keyboard: add default switch-case, to handle smatch-warnings in method vt_do_kdgkb_ioctl
Date: Mon, 8 Nov 2021 10:41:46 +0100 [thread overview]
Message-ID: <YYjw2mRIhy1SoIb+@hovoldconsulting.com> (raw)
In-Reply-To: <20211107031721.4734-1-ajaygargnsit@gmail.com>
First, please fix your patch Subject which is way too verbose. You
should aim at less than 72 chars including prefix. Something like
"vt: keyboard: suppress smatch warning in vt_do_kdgkb_ioctl"
should do.
On Sun, Nov 07, 2021 at 08:47:21AM +0530, Ajay Garg wrote:
> smatch-kchecker gives the following warnings when run on keyboard.c :
>
> vt_do_kdgkb_ioctl() error: uninitialized symbol 'kbs'.
> vt_do_kdgkb_ioctl() error: uninitialized symbol 'ret'.
>
> This usually happens when switch has no default case and static
> analyzers and even sometimes compilers can’t prove that all possible
> values are covered.
>
> Thus, the default switch-case has been added, which sets the values
> for the two variables :
>
> * kbs as NULL, which also nicely fits in with kfree.
>
> * ret as -ENOIOCTLCMD (on same lines if there is no cmd
> match in "vt_do_kdskled" method).
Not sure how far we want to take the suppression of false-positive
warnings but at least this isn't the right way to do it.
> Many thanks to the following for review of previous versions :
>
> * Pavel Skripkin <paskripkin@gmail.com>
> * Andy Shevchenko <andy.shevchenko@gmail.com>
>
>
> Signed-off-by: Ajay Garg <ajaygargnsit@gmail.com>
> ---
>
>
> There were discussions previously, and the current patch is the
> result.
>
> v1 :
> https://lore.kernel.org/linux-serial/YYZN30qfaKMskVwE@kroah.com/T/#t
>
> v2 :
> https://lore.kernel.org/linux-serial/CAHP4M8Vdj4Eb8q773BeHvsW9n6t=3n1WznuXAR4fZCNi1J6rOg@mail.gmail.com/T/#m18f45676feaba6b1f01ddd5fe607997b190ef4b9
>
> v3 :
> https://lore.kernel.org/linux-serial/20211106220315.392842-1-ajaygargnsit@gmail.com/T/#u
>
> Changes in v2 :
>
> * Changes as required by scripts/checkpatch.pl
>
> * Checking whether kbs is not NULL before kfree is not required,
> as kfree(NULL) is safe. So, dropped the check.
>
> Changes in v3 :
>
> * Using default-switch case, and setting the variables
> when there is no matching cmd.
>
> Changes in v4 :
>
> * Removed braces for the default switch-case.
>
>
> drivers/tty/vt/keyboard.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
>
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index c7fbbcdcc346..f66c32fe7ef1 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -2090,6 +2090,10 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
>
> ret = 0;
> break;
> + default:
> + kbs = NULL;
> + ret = -ENOIOCTLCMD;
> + break;
> }
>
> kfree(kbs);
Instead, move the kfree() into the two cases blocks and initialise ret
to 0 as is done in several other vt helpers in case a driver bug ever
causes them to be called for the wrong cmds (e.g. instead of sprinkling
WARN_ON(1) in all those functions).
You may want to mention that the kfree warning was introduced by
07edff926520 ("vt: keyboard, reorder user buffer handling in vt_do_kdgkb_ioctl")
which moved the shared allocation into the switch statement, and perhaps
also mention
4e1404a5cd04 ("vt: keyboard, extract and simplify vt_kdskbsent")
for the ret warning.
Johan
next prev parent reply other threads:[~2021-11-08 9:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-07 3:17 [PATCH v4] tty: vt: keyboard: add default switch-case, to handle smatch-warnings in method vt_do_kdgkb_ioctl Ajay Garg
2021-11-08 7:03 ` Jiri Slaby
2021-11-08 8:36 ` Andy Shevchenko
2021-11-08 8:55 ` Ajay Garg
2021-11-08 9:41 ` Johan Hovold [this message]
2021-11-08 13:51 ` Ajay Garg
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=YYjw2mRIhy1SoIb+@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=ajaygargnsit@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kernel@esmil.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=paskripkin@gmail.com \
/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 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).