media: vicodec: Validate version dependent header values in a separate function
authorDafna Hirschfeld <dafna3@gmail.com>
Wed, 6 Mar 2019 21:13:33 +0000 (16:13 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 25 Mar 2019 17:47:30 +0000 (13:47 -0400)
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>
drivers/media/platform/vicodec/vicodec-core.c

index 970b307b6ffa42c6cf87a86e72652f6faf4baec4..ab837d5cb2d83999e96302d76bd99fe0c30a1a88 100644 (file)
@@ -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)