diff options
author | Dafna Hirschfeld <dafna.hirschfeld@collabora.com> | 2021-12-02 00:56:51 +0200 |
---|---|---|
committer | Hans Verkuil <hverkuil-cisco@xs4all.nl> | 2021-12-02 14:44:10 +0100 |
commit | d1888b0bfd2ddef2e8a81505ffa200b92cc32e0c (patch) | |
tree | 8c60ffee8b795e1fbb1ed9039fc8cd91c85ff1f9 | |
parent | 6ab84456d24d05be1334ea3b71c25dfff22deb85 (diff) |
media: videobuf2: add WARN_ON_ONCE if bytesused is bigger than buffer lengthbr-v5.17e
In function vb2_set_plane_payload, report if the
given bytesused is bigger than the buffer size,
and clamp it to the buffer size.
Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r-- | include/media/videobuf2-core.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 2467284e5f26..5468b633b9d2 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -1155,8 +1155,15 @@ 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) + /* + * size must never be larger than the buffer length, so + * warn and clamp to the buffer length if that's the case. + */ + if (plane_no < vb->num_planes) { + if (WARN_ON_ONCE(size > vb->planes[plane_no].length)) + size = vb->planes[plane_no].length; vb->planes[plane_no].bytesused = size; + } } /** |