OSDN Git Service

media: vicodec: make life easier for static analyzers
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 22 Aug 2019 14:41:45 +0000 (11:41 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 26 Aug 2019 17:02:22 +0000 (14:02 -0300)
cppcheck incorrectly produces an error here:
[drivers/media/platform/vicodec/vicodec-core.c:1677]: (error) Pointer addition with NULL pointer.

While this is actually a false positive, it doesn't hurt to
reorder the checks to make the code simpler, handling first
the error patch, where no color or alpha components are there.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/vicodec/vicodec-core.c

index 5152f44..0ee143a 100644 (file)
@@ -1664,19 +1664,22 @@ static int vicodec_start_streaming(struct vb2_queue *q,
        kvfree(state->compressed_frame);
        state->compressed_frame = new_comp_frame;
 
-       if (info->components_num >= 3) {
-               state->ref_frame.cb = state->ref_frame.luma + size;
-               state->ref_frame.cr = state->ref_frame.cb + size / chroma_div;
-       } else {
+       if (info->components_num < 3) {
                state->ref_frame.cb = NULL;
                state->ref_frame.cr = NULL;
+               state->ref_frame.alpha = NULL;
+               return 0;
        }
 
+       state->ref_frame.cb = state->ref_frame.luma + size;
+       state->ref_frame.cr = state->ref_frame.cb + size / chroma_div;
+
        if (info->components_num == 4)
                state->ref_frame.alpha =
                        state->ref_frame.cr + size / chroma_div;
        else
                state->ref_frame.alpha = NULL;
+
        return 0;
 }