media: meson: vdec: potential dereference of null pointer
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Thu, 13 Jan 2022 06:59:28 +0000 (07:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:23:14 +0000 (14:23 +0200)
[ Upstream commit c8c80c996182239ff9b05eda4db50184cf3b2e99 ]

As the possible failure of the kzalloc(), the 'new_ts' could be NULL
pointer.
Therefore, it should be better to check it in order to avoid the
dereference of the NULL pointer.
Also, the caller esparser_queue() needs to deal with the return value of
the amvdec_add_ts().

Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Suggested-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/staging/media/meson/vdec/esparser.c
drivers/staging/media/meson/vdec/vdec_helpers.c
drivers/staging/media/meson/vdec/vdec_helpers.h

index db7022707ff8dd4ce5cfd9f89203c2e46885da3b..86ccc8937afcaf0a89c96cfc92d3a13de3ee2121 100644 (file)
@@ -328,7 +328,12 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf)
 
        offset = esparser_get_offset(sess);
 
-       amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags);
+       ret = amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags);
+       if (ret) {
+               v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
+               return ret;
+       }
+
        dev_dbg(core->dev, "esparser: ts = %llu pld_size = %u offset = %08X flags = %08X\n",
                vb->timestamp, payload_size, offset, vbuf->flags);
 
index b9125c295d1d31ee3844f6421ae3c991bbabe674..06fd66539797a3579cc0b7e06b7dc1361cd5a5a9 100644 (file)
@@ -227,13 +227,16 @@ int amvdec_set_canvases(struct amvdec_session *sess,
 }
 EXPORT_SYMBOL_GPL(amvdec_set_canvases);
 
-void amvdec_add_ts(struct amvdec_session *sess, u64 ts,
-                  struct v4l2_timecode tc, u32 offset, u32 vbuf_flags)
+int amvdec_add_ts(struct amvdec_session *sess, u64 ts,
+                 struct v4l2_timecode tc, u32 offset, u32 vbuf_flags)
 {
        struct amvdec_timestamp *new_ts;
        unsigned long flags;
 
        new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL);
+       if (!new_ts)
+               return -ENOMEM;
+
        new_ts->ts = ts;
        new_ts->tc = tc;
        new_ts->offset = offset;
@@ -242,6 +245,7 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts,
        spin_lock_irqsave(&sess->ts_spinlock, flags);
        list_add_tail(&new_ts->list, &sess->timestamps);
        spin_unlock_irqrestore(&sess->ts_spinlock, flags);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(amvdec_add_ts);
 
index cfaed52ab526577e17d2d50659a9761a498a9235..798e5a8a9b3f19b83f4d56779bbb3e2b358b0d40 100644 (file)
@@ -55,8 +55,8 @@ void amvdec_dst_buf_done_offset(struct amvdec_session *sess,
  * @offset: offset in the VIFIFO where the associated packet was written
  * @flags the vb2_v4l2_buffer flags
  */
-void amvdec_add_ts(struct amvdec_session *sess, u64 ts,
-                  struct v4l2_timecode tc, u32 offset, u32 flags);
+int amvdec_add_ts(struct amvdec_session *sess, u64 ts,
+                 struct v4l2_timecode tc, u32 offset, u32 flags);
 void amvdec_remove_ts(struct amvdec_session *sess, u64 ts);
 
 /**