Skip to content

Commit

Permalink
media: amphion: lock and check m2m_ctx in event handler
Browse files Browse the repository at this point in the history
[ Upstream commit 1ade3f3 ]

driver needs to cancel vpu before releasing the vpu instance,
so call v4l2_m2m_ctx_release() first,
to handle the redundant event triggered after m2m_ctx is released.

lock and check m2m_ctx in the event handler.

Fixes: 3cd0845 ("media: amphion: add vpu v4l2 m2m support")
Signed-off-by: Ming Qian <ming.qian@nxp.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>
  • Loading branch information
mingqian-0 authored and gregkh committed Dec 31, 2022
1 parent c0c1903 commit c9411d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions drivers/media/platform/amphion/vpu_msgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ static void vpu_session_handle_mem_request(struct vpu_inst *inst, struct vpu_rpc
req_data.ref_frame_num,
req_data.act_buf_size,
req_data.act_buf_num);
vpu_inst_lock(inst);
call_void_vop(inst, mem_request,
req_data.enc_frame_size,
req_data.enc_frame_num,
req_data.ref_frame_size,
req_data.ref_frame_num,
req_data.act_buf_size,
req_data.act_buf_num);
vpu_inst_unlock(inst);
}

static void vpu_session_handle_stop_done(struct vpu_inst *inst, struct vpu_rpc_event *pkt)
Expand Down
8 changes: 6 additions & 2 deletions drivers/media/platform/amphion/vpu_v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ int vpu_process_capture_buffer(struct vpu_inst *inst)

struct vb2_v4l2_buffer *vpu_next_src_buf(struct vpu_inst *inst)
{
struct vb2_v4l2_buffer *src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx);
struct vb2_v4l2_buffer *src_buf = NULL;

if (!inst->fh.m2m_ctx)
return NULL;

src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx);
if (!src_buf || vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_IDLE)
return NULL;

Expand All @@ -266,7 +270,7 @@ void vpu_skip_frame(struct vpu_inst *inst, int count)
enum vb2_buffer_state state;
int i = 0;

if (count <= 0)
if (count <= 0 || !inst->fh.m2m_ctx)
return;

while (i < count) {
Expand Down

0 comments on commit c9411d5

Please sign in to comment.