media: mtk-vcodec: Handle H264 error bitstreams
authorRui Wang <gtk_ruiwang@mediatek.com>
Wed, 31 Jul 2019 04:29:39 +0000 (01:29 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Wed, 7 Aug 2019 20:05:29 +0000 (17:05 -0300)
Error h264 bitstreams which picture info are out range of
decoder hardware specification, and no nal start code at the
beginning of the buffer, stop decoding and exit.

Signed-off-by: Rui Wang <gtk_ruiwang@mediatek.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c

index c5f8f1f..49aa85a 100644 (file)
@@ -29,6 +29,9 @@
 #define H264_MAX_FB_NUM                                17
 #define HDR_PARSING_BUF_SZ                     1024
 
+#define DEC_ERR_RET(ret)                       ((ret) >> 16)
+#define H264_ERR_NOT_VALID                     3
+
 /**
  * struct h264_fb - h264 decode frame buffer information
  * @vdec_fb_va  : virtual address of struct vdec_fb
@@ -357,8 +360,11 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
        buf = (unsigned char *)bs->va;
        buf_sz = bs->size;
        nal_start_idx = find_start_code(buf, buf_sz);
-       if (nal_start_idx < 0)
+       if (nal_start_idx < 0) {
+               mtk_vcodec_err(inst, "invalid nal start code");
+               err = -EIO;
                goto err_free_fb_out;
+       }
 
        nal_start = buf[nal_start_idx];
        nal_type = NAL_TYPE(buf[nal_start_idx]);
@@ -382,8 +388,14 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
        data[0] = buf_sz;
        data[1] = nal_start;
        err = vpu_dec_start(vpu, data, 2);
-       if (err)
+       if (err) {
+               if (err > 0 && (DEC_ERR_RET(err) == H264_ERR_NOT_VALID)) {
+                       mtk_vcodec_err(inst, "- error bitstream - err = %d -",
+                                      err);
+                       err = -EIO;
+               }
                goto err_free_fb_out;
+       }
 
        *res_chg = inst->vsi->dec.resolution_changed;
        if (*res_chg) {