mirror of https://gitee.com/openkylin/linux.git
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: Dafna Hirschfeld <dafna3@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
parent
86764b88c4
commit
92dc64d412
|
@ -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,
|
static int device_process(struct vicodec_ctx *ctx,
|
||||||
struct vb2_v4l2_buffer *src_vb,
|
struct vb2_v4l2_buffer *src_vb,
|
||||||
struct vb2_v4l2_buffer *dst_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 version = ntohl(p_hdr->version);
|
||||||
unsigned int flags = ntohl(p_hdr->flags);
|
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)
|
if (w < MIN_WIDTH || w > MAX_WIDTH || h < MIN_HEIGHT || h > MAX_HEIGHT)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (version >= 2) {
|
if (!validate_by_version(flags, version))
|
||||||
unsigned int components_num = 1 +
|
return false;
|
||||||
((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;
|
|
||||||
}
|
|
||||||
|
|
||||||
info = info_from_header(p_hdr);
|
info = info_from_header(p_hdr);
|
||||||
if (!info)
|
if (!info)
|
||||||
|
|
Loading…
Reference in New Issue