media: rcar_fdp1: simplify error check logic at fdp_open()
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Fri, 23 Apr 2021 14:59:34 +0000 (16:59 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 10 May 2021 09:36:33 +0000 (11:36 +0200)
Avoid some code duplication by moving the common error path
logic at fdp_open().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/rcar_fdp1.c

index 01c1fbb..d26413f 100644 (file)
@@ -2117,9 +2117,7 @@ static int fdp1_open(struct file *file)
 
        if (ctx->hdl.error) {
                ret = ctx->hdl.error;
-               v4l2_ctrl_handler_free(&ctx->hdl);
-               kfree(ctx);
-               goto done;
+               goto error_ctx;
        }
 
        ctx->fh.ctrl_handler = &ctx->hdl;
@@ -2133,10 +2131,7 @@ static int fdp1_open(struct file *file)
 
        if (IS_ERR(ctx->fh.m2m_ctx)) {
                ret = PTR_ERR(ctx->fh.m2m_ctx);
-
-               v4l2_ctrl_handler_free(&ctx->hdl);
-               kfree(ctx);
-               goto done;
+               goto error_ctx;
        }
 
        /* Perform any power management required */
@@ -2147,6 +2142,12 @@ static int fdp1_open(struct file *file)
        dprintk(fdp1, "Created instance: %p, m2m_ctx: %p\n",
                ctx, ctx->fh.m2m_ctx);
 
+       mutex_unlock(&fdp1->dev_mutex);
+       return 0;
+
+error_ctx:
+       v4l2_ctrl_handler_free(&ctx->hdl);
+       kfree(ctx);
 done:
        mutex_unlock(&fdp1->dev_mutex);
        return ret;