From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Tomasz Figa <tfiga@chromium.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] media: v4l2-ctrls: add more NULL pointer checks
Date: Thu, 16 Apr 2020 20:32:49 +0900 [thread overview]
Message-ID: <20200416113249.GG30641@jagdpanzerIV.localdomain> (raw)
In-Reply-To: <c83c137b-b801-a06b-e324-09dd3bbc9daf@xs4all.nl>
On (20/04/16 10:53), Hans Verkuil wrote:
[..]
> > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> > @@ -2869,6 +2869,9 @@ EXPORT_SYMBOL(v4l2_ctrl_add_handler);
> >
> > bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl)
> > {
> > + if (WARN_ON(!ctrl))
> > + return false;
> > +
> > if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
> > return true;
> > if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX)
> > @@ -3794,7 +3797,9 @@ s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl)
> > struct v4l2_ext_control c;
> >
> > /* It's a driver bug if this happens. */
> > - WARN_ON(!ctrl->is_int);
> > + if (WARN_ON(!ctrl || !ctrl->is_int))
> > + return -EINVAL;
>
> Just return 0 here. The return value is the control's value, not an error code.
> So all you can do here is return 0 in the absence of anything better.
OK.
> > +
> > c.value = 0;
> > get_ctrl(ctrl, &c);
> > return c.value;
> > @@ -4212,6 +4217,9 @@ EXPORT_SYMBOL(v4l2_s_ctrl);
> >
> > int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
> > {
> > + if (!ctrl)
>
> Change this to 'if (WARN_ON(!ctrl))'
>
> I don't think NULL pointers should be silently ignored: it really
> indicates a driver bug. It it certainly a good idea to WARN instead.
Should WARN_ON() be only in unlocked versions of ctrl API? It probably
would make sense to add WARNs to both - e.g. to v4l2_ctrl_s_ctrl() and
to __v4l2_ctrl_s_ctrl(). By the way, why don't locked and unlocked
versions live together in v4l2-ctrls.c file? Any reason for, e.g.,
v4l2_ctrl_s_ctrl() to be in header and __v4l2_ctrl_s_ctrl() to be C-file?
> The same is true for the functions below.
OK.
-ss
next prev parent reply other threads:[~2020-04-16 11:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-10 10:35 Sergey Senozhatsky
2020-04-16 8:53 ` Hans Verkuil
2020-04-16 11:32 ` Sergey Senozhatsky [this message]
2020-04-16 12:13 ` Hans Verkuil
2020-04-17 8:13 ` Hans Verkuil
2020-04-16 12:59 ` Ezequiel Garcia
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=20200416113249.GG30641@jagdpanzerIV.localdomain \
--to=sergey.senozhatsky@gmail.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=tfiga@chromium.org \
/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
all inboxes | Powered by JetHome®