linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>,
	linux-media@vger.kernel.org, kernel@collabora.com,
	dafna3@gmail.com, sakari.ailus@linux.intel.com,
	mchehab@kernel.org
Subject: Re: [PATCH 2/2] media: videobuf2: add WARN_ON if bytesused is bigger than buffer length
Date: Wed, 10 Nov 2021 16:49:55 +0200	[thread overview]
Message-ID: <YYvcE24qkaImq5xK@pendragon.ideasonboard.com> (raw)
In-Reply-To: <5efc3d13-9d25-d0ce-98c8-fe1563dd91e9@xs4all.nl>

On Wed, Nov 10, 2021 at 09:58:02AM +0100, Hans Verkuil wrote:
> On 08/11/2021 20:39, Dafna Hirschfeld wrote:
> > In function vb2_set_plane_payload, report if the
> > given bytesused is bigger than the buffer size.
> > 
> > Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
> > ---
> >  include/media/videobuf2-core.h | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> > index 2467284e5f26..ffaa1f3361c3 100644
> > --- a/include/media/videobuf2-core.h
> > +++ b/include/media/videobuf2-core.h
> > @@ -1155,8 +1155,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
> >  static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
> >  				 unsigned int plane_no, unsigned long size)
> >  {
> > -	if (plane_no < vb->num_planes)
> > +	if (plane_no < vb->num_planes) {
> > +		WARN_ON(size > vb->planes[plane_no].length);
> 
> I would change this to:
> 
> 		/*
> 		 * size must never be larger than the buffer length, so
> 		 * warn and clamp to the buffer length if that's the case.
> 		 */
> 		if (WARN_ON(size > vb->planes[plane_no].length))
> 			size = vb->planes[plane_no].length;

Should this also be a WARN_ON_ONCE() ? If it occurs once there's a large
risk it will occur very frequently, and flood the kernel log.

> >  		vb->planes[plane_no].bytesused = size;
> > +	}
> >  }
> >  
> >  /**

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2021-11-10 14:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 19:39 [PATCH 0/2] media: videobuf2: make sure bytesused is smaller than the buffer size Dafna Hirschfeld
2021-11-08 19:39 ` [PATCH 1/2] media: replace setting of bytesused with vb2_set_plane_payload Dafna Hirschfeld
2021-11-10 14:45   ` Laurent Pinchart
2021-11-08 19:39 ` [PATCH 2/2] media: videobuf2: add WARN_ON if bytesused is bigger than buffer length Dafna Hirschfeld
2021-11-10  8:58   ` Hans Verkuil
2021-11-10 14:49     ` Laurent Pinchart [this message]
2021-11-10 15:04       ` Hans Verkuil

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=YYvcE24qkaImq5xK@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dafna.hirschfeld@collabora.com \
    --cc=dafna3@gmail.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.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;
as well as URLs for NNTP newsgroup(s).