media: hantro: streamline open, reuse error path
authorPhilipp Zabel <p.zabel@pengutronix.de>
Thu, 5 Sep 2019 10:25:54 +0000 (07:25 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Tue, 1 Oct 2019 19:42:37 +0000 (16:42 -0300)
This adds a label to the error path to avoid calling
v4l2_m2m_ctx_init() and kfree(ctx) in two places each.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/staging/media/hantro/hantro_drv.c

index 6d9d41170832ff1f12cf5f1b8968a777dc67c8e0..23569299977b40e8cf20b3d898e38c09378ee21e 100644 (file)
@@ -413,20 +413,18 @@ static int hantro_open(struct file *filp)
        if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
                allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS;
                ctx->buf_finish = hantro_enc_buf_finish;
-               ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(vpu->m2m_dev, ctx,
-                                                   queue_init);
        } else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) {
                allowed_codecs = vpu->variant->codec & HANTRO_DECODERS;
                ctx->buf_finish = hantro_dec_buf_finish;
-               ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(vpu->m2m_dev, ctx,
-                                                   queue_init);
        } else {
-               ctx->fh.m2m_ctx = ERR_PTR(-ENODEV);
+               ret = -ENODEV;
+               goto err_ctx_free;
        }
+
+       ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(vpu->m2m_dev, ctx, queue_init);
        if (IS_ERR(ctx->fh.m2m_ctx)) {
                ret = PTR_ERR(ctx->fh.m2m_ctx);
-               kfree(ctx);
-               return ret;
+               goto err_ctx_free;
        }
 
        v4l2_fh_init(&ctx->fh, vdev);
@@ -447,6 +445,7 @@ static int hantro_open(struct file *filp)
 err_fh_free:
        v4l2_fh_del(&ctx->fh);
        v4l2_fh_exit(&ctx->fh);
+err_ctx_free:
        kfree(ctx);
        return ret;
 }