Commit f82bc203 authored by Fabio Estevam's avatar Fabio Estevam Committed by Mauro Carvalho Chehab

[media] coda: Fix error paths

Some resources were not being released in the error path and some were released
in the incorrect order.
Signed-off-by: default avatarFabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: default avatarKamil Debski <k.debski@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent fea564a5
...@@ -2381,15 +2381,17 @@ static int coda_open(struct file *file) ...@@ -2381,15 +2381,17 @@ static int coda_open(struct file *file)
int ret; int ret;
int idx; int idx;
idx = coda_next_free_instance(dev);
if (idx >= CODA_MAX_INSTANCES)
return -EBUSY;
set_bit(idx, &dev->instance_mask);
ctx = kzalloc(sizeof *ctx, GFP_KERNEL); ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
idx = coda_next_free_instance(dev);
if (idx >= CODA_MAX_INSTANCES) {
ret = -EBUSY;
goto err_coda_max;
}
set_bit(idx, &dev->instance_mask);
INIT_WORK(&ctx->skip_run, coda_skip_run); INIT_WORK(&ctx->skip_run, coda_skip_run);
v4l2_fh_init(&ctx->fh, video_devdata(file)); v4l2_fh_init(&ctx->fh, video_devdata(file));
file->private_data = &ctx->fh; file->private_data = &ctx->fh;
...@@ -2403,6 +2405,9 @@ static int coda_open(struct file *file) ...@@ -2403,6 +2405,9 @@ static int coda_open(struct file *file)
default: default:
ctx->reg_idx = idx; ctx->reg_idx = idx;
} }
clk_prepare_enable(dev->clk_per);
clk_prepare_enable(dev->clk_ahb);
set_default_params(ctx); set_default_params(ctx);
ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
&coda_queue_init); &coda_queue_init);
...@@ -2411,12 +2416,12 @@ static int coda_open(struct file *file) ...@@ -2411,12 +2416,12 @@ static int coda_open(struct file *file)
v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n", v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n",
__func__, ret); __func__, ret);
goto err; goto err_ctx_init;
} }
ret = coda_ctrls_setup(ctx); ret = coda_ctrls_setup(ctx);
if (ret) { if (ret) {
v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n"); v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n");
goto err; goto err_ctrls_setup;
} }
ctx->fh.ctrl_handler = &ctx->ctrls; ctx->fh.ctrl_handler = &ctx->ctrls;
...@@ -2424,7 +2429,7 @@ static int coda_open(struct file *file) ...@@ -2424,7 +2429,7 @@ static int coda_open(struct file *file)
ret = coda_alloc_context_buf(ctx, &ctx->parabuf, CODA_PARA_BUF_SIZE); ret = coda_alloc_context_buf(ctx, &ctx->parabuf, CODA_PARA_BUF_SIZE);
if (ret < 0) { if (ret < 0) {
v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf"); v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
goto err; goto err_dma_alloc;
} }
ctx->bitstream.size = CODA_MAX_FRAME_SIZE; ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
...@@ -2433,7 +2438,7 @@ static int coda_open(struct file *file) ...@@ -2433,7 +2438,7 @@ static int coda_open(struct file *file)
if (!ctx->bitstream.vaddr) { if (!ctx->bitstream.vaddr) {
v4l2_err(&dev->v4l2_dev, "failed to allocate bitstream ringbuffer"); v4l2_err(&dev->v4l2_dev, "failed to allocate bitstream ringbuffer");
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err_dma_writecombine;
} }
kfifo_init(&ctx->bitstream_fifo, kfifo_init(&ctx->bitstream_fifo,
ctx->bitstream.vaddr, ctx->bitstream.size); ctx->bitstream.vaddr, ctx->bitstream.size);
...@@ -2444,17 +2449,27 @@ static int coda_open(struct file *file) ...@@ -2444,17 +2449,27 @@ static int coda_open(struct file *file)
list_add(&ctx->list, &dev->instances); list_add(&ctx->list, &dev->instances);
coda_unlock(ctx); coda_unlock(ctx);
clk_prepare_enable(dev->clk_per);
clk_prepare_enable(dev->clk_ahb);
v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n", v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n",
ctx->idx, ctx); ctx->idx, ctx);
return 0; return 0;
err: err_dma_writecombine:
coda_free_context_buffers(ctx);
if (ctx->dev->devtype->product == CODA_DX6)
coda_free_aux_buf(dev, &ctx->workbuf);
coda_free_aux_buf(dev, &ctx->parabuf);
err_dma_alloc:
v4l2_ctrl_handler_free(&ctx->ctrls);
err_ctrls_setup:
v4l2_m2m_ctx_release(ctx->m2m_ctx);
err_ctx_init:
clk_disable_unprepare(dev->clk_ahb);
clk_disable_unprepare(dev->clk_per);
v4l2_fh_del(&ctx->fh); v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh); v4l2_fh_exit(&ctx->fh);
clear_bit(ctx->idx, &dev->instance_mask);
err_coda_max:
kfree(ctx); kfree(ctx);
return ret; return ret;
} }
...@@ -2496,8 +2511,8 @@ static int coda_release(struct file *file) ...@@ -2496,8 +2511,8 @@ static int coda_release(struct file *file)
coda_free_aux_buf(dev, &ctx->parabuf); coda_free_aux_buf(dev, &ctx->parabuf);
v4l2_ctrl_handler_free(&ctx->ctrls); v4l2_ctrl_handler_free(&ctx->ctrls);
clk_disable_unprepare(dev->clk_per);
clk_disable_unprepare(dev->clk_ahb); clk_disable_unprepare(dev->clk_ahb);
clk_disable_unprepare(dev->clk_per);
v4l2_fh_del(&ctx->fh); v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh); v4l2_fh_exit(&ctx->fh);
clear_bit(ctx->idx, &dev->instance_mask); clear_bit(ctx->idx, &dev->instance_mask);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment