Skip to content

Commit d43d7db

Browse files
ndufresnehverkuil
authored andcommitted
media: rkvdec: Initialize the m2m context before the controls
Setting up the control handler calls into .s_ctrl ops. While validating the controls the ops may need to access some of the context state, which could lead to a crash if not properly initialized. Signed-off-by: Nicolas Dufresne <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 45029d3 commit d43d7db

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/staging/media/rkvdec/rkvdec.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -871,24 +871,24 @@ static int rkvdec_open(struct file *filp)
871871
rkvdec_reset_decoded_fmt(ctx);
872872
v4l2_fh_init(&ctx->fh, video_devdata(filp));
873873

874-
ret = rkvdec_init_ctrls(ctx);
875-
if (ret)
876-
goto err_free_ctx;
877-
878874
ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(rkvdec->m2m_dev, ctx,
879875
rkvdec_queue_init);
880876
if (IS_ERR(ctx->fh.m2m_ctx)) {
881877
ret = PTR_ERR(ctx->fh.m2m_ctx);
882-
goto err_cleanup_ctrls;
878+
goto err_free_ctx;
883879
}
884880

881+
ret = rkvdec_init_ctrls(ctx);
882+
if (ret)
883+
goto err_cleanup_m2m_ctx;
884+
885885
filp->private_data = &ctx->fh;
886886
v4l2_fh_add(&ctx->fh);
887887

888888
return 0;
889889

890-
err_cleanup_ctrls:
891-
v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
890+
err_cleanup_m2m_ctx:
891+
v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
892892

893893
err_free_ctx:
894894
kfree(ctx);

0 commit comments

Comments
 (0)