Commit 92dc64d4 authored by Dafna Hirschfeld's avatar Dafna Hirschfeld Committed by Mauro Carvalho Chehab

media: vicodec: Validate version dependent header values in a separate function

Move the code that validates version dependent header
values to a separate function 'validate_by_version'
Signed-off-by: default avatarDafna Hirschfeld <dafna3@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 86764b88
......@@ -190,6 +190,23 @@ static void copy_cap_to_ref(const u8 *cap, const struct v4l2_fwht_pixfmt_info *i
}
}
static bool validate_by_version(unsigned int flags, unsigned int version)
{
if (!version || version > FWHT_VERSION)
return false;
if (version >= 2) {
unsigned int components_num = 1 +
((flags & FWHT_FL_COMPONENTS_NUM_MSK) >>
FWHT_FL_COMPONENTS_NUM_OFFSET);
unsigned int pixenc = flags & FWHT_FL_PIXENC_MSK;
if (components_num == 0 || components_num > 4 || !pixenc)
return false;
}
return true;
}
static int device_process(struct vicodec_ctx *ctx,
struct vb2_v4l2_buffer *src_vb,
struct vb2_v4l2_buffer *dst_vb)
......@@ -396,21 +413,11 @@ static bool is_header_valid(const struct fwht_cframe_hdr *p_hdr)
unsigned int version = ntohl(p_hdr->version);
unsigned int flags = ntohl(p_hdr->flags);
if (!version || version > FWHT_VERSION)
return false;
if (w < MIN_WIDTH || w > MAX_WIDTH || h < MIN_HEIGHT || h > MAX_HEIGHT)
return false;
if (version >= 2) {
unsigned int components_num = 1 +
((flags & FWHT_FL_COMPONENTS_NUM_MSK) >>
FWHT_FL_COMPONENTS_NUM_OFFSET);
unsigned int pixenc = flags & FWHT_FL_PIXENC_MSK;
if (components_num == 0 || components_num > 4 || !pixenc)
return false;
}
if (!validate_by_version(flags, version))
return false;
info = info_from_header(p_hdr);
if (!info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment