From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: Ricardo Ribalda <ribalda@chromium.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Hans Verkuil <hverkuil@kernel.org>,
Nas Chung <nas.chung@chipsnmedia.com>,
Jackson Lee <jackson.lee@chipsnmedia.com>,
Bingbu Cao <bingbu.cao@intel.com>,
Tianshu Qiu <tian.shu.qiu@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Keke Li <keke.li@amlogic.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-staging@lists.linux.dev
Subject: Re: [PATCH 1/6] media: v4l2-dev: Add range check for vdev->minor
Date: Wed, 29 Apr 2026 11:52:22 +0300 [thread overview]
Message-ID: <afHGxs-reZLVABTd@kekkonen.localdomain> (raw)
In-Reply-To: <40d31660-73c1-417b-a00c-1a83079943e5@kernel.org>
Hi Hans,
On Wed, Apr 29, 2026 at 09:53:41AM +0200, Hans Verkuil wrote:
> On 29/04/2026 09:43, Sakari Ailus wrote:
> > Hi Ricardo,
> >
> > On Tue, Apr 28, 2026 at 12:41:07PM +0000, Ricardo Ribalda wrote:
> >> If the fixed minor ranges are not properly set we could end up in a
> >> situation where the calculated minor is invalid. Add a check for this in
> >> the code.
> >>
> >> This check also fixes the following smatch warning:
> >>
> >> drivers/media/v4l2-core/v4l2-dev.c:1036 __video_register_device() error: buffer overflow 'video_devices' 256 <= 288
> >> drivers/media/v4l2-core/v4l2-dev.c:1043 __video_register_device() error: buffer overflow 'video_devices' 256 <= 288
> >> drivers/media/v4l2-core/v4l2-dev.c:1101 __video_register_device() error: buffer overflow 'video_devices' 256 <= 288
> >>
> >> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> >> ---
> >> drivers/media/v4l2-core/v4l2-dev.c | 6 ++++++
> >> 1 file changed, 6 insertions(+)
> >>
> >> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> >> index 6ce623a1245a..a731ffdb91ee 100644
> >> --- a/drivers/media/v4l2-core/v4l2-dev.c
> >> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> >> @@ -1032,6 +1032,12 @@ int __video_register_device(struct video_device *vdev,
> >> vdev->minor = i + minor_offset;
> >> vdev->num = nr;
> >>
> >> + if (WARN_ON(vdev->minor >= VIDEO_NUM_DEVICES)) {
> >
> > Could this be combined with the should-not-happen case below? The error
> > handling is the same (releasing the mutex) and the error code could be as
> > well. I think the message can be just as well removed as we have a
> > WARN_ON() here anyway.
> >
> > I wonder what Hans thinks.
>
> I actually prefer to keep it separate. If you combine it, then it is hard
> to see which of the two possibilities is actually wrong (out of range or
> minor in use). And this function sits at the core of V4L2, so it's OK to
Not if they're on different lines as you get the line number with
WARN_ON(). Keeping such code small has benefits.
That being said, I certainly have no strong opinion about this.
> be a bit more verbose.
>
> I do agree that a pr_err after a WARN_ON is not needed.
--
Regards,
Sakari Ailus
next prev parent reply other threads:[~2026-04-29 8:52 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 12:41 [PATCH 0/6] media: Fix new smatch warnings Ricardo Ribalda
2026-04-28 12:41 ` [PATCH 1/6] media: v4l2-dev: Add range check for vdev->minor Ricardo Ribalda
2026-04-29 7:38 ` Hans Verkuil
2026-04-29 7:43 ` Sakari Ailus
2026-04-29 7:53 ` Hans Verkuil
2026-04-29 8:52 ` Sakari Ailus [this message]
2026-04-28 12:41 ` [PATCH 2/6] media: i2c: mt9p031: Rewrite a bitwise mask Ricardo Ribalda
2026-04-28 13:25 ` Laurent Pinchart
2026-04-28 13:37 ` Ricardo Ribalda
2026-04-28 12:41 ` [PATCH 3/6] media: i2c: adv7604: Add range checks for chip info Ricardo Ribalda
2026-04-29 7:40 ` Hans Verkuil
2026-04-28 12:41 ` [PATCH 4/6] media: chips-media: wave5: Add range checks for dec_output_info Ricardo Ribalda
2026-04-28 12:41 ` [PATCH 5/6] media: staging: ipu3-imgu: Add range check for imgu_css_cfg_acc_stripe Ricardo Ribalda
2026-04-28 13:13 ` Laurent Pinchart
2026-04-28 13:17 ` Ricardo Ribalda
2026-04-28 12:41 ` [PATCH 6/6] media: amlogic-c3: Add validations for ae and awb config Ricardo Ribalda
2026-04-28 13:10 ` Laurent Pinchart
2026-04-28 13:14 ` Ricardo Ribalda
2026-04-28 13:15 ` Ricardo Ribalda
2026-04-28 13:26 ` Laurent Pinchart
2026-04-28 13:49 ` Ricardo Ribalda
2026-04-29 6:15 ` Jacopo Mondi
2026-04-29 6:44 ` Ricardo Ribalda
2026-04-29 6:55 ` Jacopo Mondi
2026-04-29 7:15 ` Ricardo Ribalda
2026-04-29 7:30 ` Jacopo Mondi
2026-04-28 13:52 ` [PATCH 0/6] media: Fix new smatch warnings Dan Carpenter
2026-04-28 13:58 ` Ricardo Ribalda
2026-04-29 7:23 ` Laurent Pinchart
2026-04-29 10:31 ` Dan Carpenter
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=afHGxs-reZLVABTd@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=bingbu.cao@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil+cisco@kernel.org \
--cc=hverkuil@kernel.org \
--cc=jackson.lee@chipsnmedia.com \
--cc=keke.li@amlogic.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=nas.chung@chipsnmedia.com \
--cc=ribalda@chromium.org \
--cc=tian.shu.qiu@intel.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