Add the field 'dev_inst' to vicodec_ctx that points to the 'vicodec_dev_instance'. This saves many if-elses Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx> --- drivers/media/platform/vicodec/vicodec-core.c | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/drivers/media/platform/vicodec/vicodec-core.c b/drivers/media/platform/vicodec/vicodec-core.c index 3e93e86041f7..73661bc96671 100644 --- a/drivers/media/platform/vicodec/vicodec-core.c +++ b/drivers/media/platform/vicodec/vicodec-core.c @@ -121,6 +121,7 @@ struct vicodec_ctx { bool has_stopped; spinlock_t *lock; + struct vicodec_dev_instance *dev_inst; struct v4l2_ctrl_handler hdl; struct vb2_v4l2_buffer *last_src_buf; @@ -413,7 +414,6 @@ static enum vb2_buffer_state get_next_header(struct vicodec_ctx *ctx, static void device_run(void *priv) { struct vicodec_ctx *ctx = priv; - struct vicodec_dev *dev = ctx->dev; struct vb2_v4l2_buffer *src_buf, *dst_buf; struct vicodec_q_data *q_src, *q_dst; u32 state; @@ -462,13 +462,7 @@ static void device_run(void *priv) if (ctx->is_stateless && src_req) v4l2_ctrl_request_complete(src_req, &ctx->hdl); - if (ctx->is_enc) - v4l2_m2m_job_finish(dev->stateful_enc.m2m_dev, ctx->fh.m2m_ctx); - else if (ctx->is_stateless) - v4l2_m2m_job_finish(dev->stateless_dec.m2m_dev, - ctx->fh.m2m_ctx); - else - v4l2_m2m_job_finish(dev->stateful_dec.m2m_dev, ctx->fh.m2m_ctx); + v4l2_m2m_job_finish(ctx->dev_inst->m2m_dev, ctx->fh.m2m_ctx); } static void job_remove_src_buf(struct vicodec_ctx *ctx, u32 state) @@ -1787,12 +1781,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, src_vq->ops = &vicodec_qops; src_vq->mem_ops = &vb2_vmalloc_memops; src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; - if (ctx->is_enc) - src_vq->lock = &ctx->dev->stateful_enc.mutex; - else if (ctx->is_stateless) - src_vq->lock = &ctx->dev->stateless_dec.mutex; - else - src_vq->lock = &ctx->dev->stateful_dec.mutex; + src_vq->lock = &ctx->dev_inst->mutex; src_vq->supports_requests = ctx->is_stateless; src_vq->requires_requests = ctx->is_stateless; ret = vb2_queue_init(src_vq); @@ -1915,10 +1904,15 @@ static int vicodec_open(struct file *file) goto open_unlock; } - if (vfd == &dev->stateful_enc.vfd) + if (vfd == &dev->stateful_enc.vfd) { ctx->is_enc = true; - else if (vfd == &dev->stateless_dec.vfd) + ctx->dev_inst = &dev->stateful_enc; + } else if (vfd == &dev->stateless_dec.vfd) { ctx->is_stateless = true; + ctx->dev_inst = &dev->stateless_dec; + } else { + ctx->dev_inst = &dev->stateful_dec; + } v4l2_fh_init(&ctx->fh, video_devdata(file)); file->private_data = &ctx->fh; @@ -1975,19 +1969,9 @@ static int vicodec_open(struct file *file) ctx->state.colorspace = V4L2_COLORSPACE_REC709; - if (ctx->is_enc) { - ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->stateful_enc.m2m_dev, - ctx, &queue_init); - ctx->lock = &dev->stateful_enc.lock; - } else if (ctx->is_stateless) { - ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->stateless_dec.m2m_dev, - ctx, &queue_init); - ctx->lock = &dev->stateless_dec.lock; - } else { - ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->stateful_dec.m2m_dev, - ctx, &queue_init); - ctx->lock = &dev->stateful_dec.lock; - } + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(ctx->dev_inst->m2m_dev, + ctx, &queue_init); + ctx->lock = &ctx->dev_inst->lock; if (IS_ERR(ctx->fh.m2m_ctx)) { rc = PTR_ERR(ctx->fh.m2m_ctx); -- 2.17.1