All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 1/3] [media] coda: Fix error paths
@ 2013-08-20 19:29 Fabio Estevam
  2013-08-20 19:29 ` [PATCH v6 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
  2013-08-20 19:29 ` [PATCH v6 3/3] [media] coda: No need to check the return value of platform_get_resource() Fabio Estevam
  0 siblings, 2 replies; 4+ messages in thread
From: Fabio Estevam @ 2013-08-20 19:29 UTC (permalink / raw)
  To: k.debski; +Cc: p.zabel, linux-media, Fabio Estevam

Some resources were not being released in the error path and some were released
in the incorrect order.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v5:
- Rebased against latest Kamil's tree

 drivers/media/platform/coda.c | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 66db0df..b5d48b7 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -2381,15 +2381,17 @@ static int coda_open(struct file *file)
 	int ret;
 	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);
 	if (!ctx)
 		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);
 	v4l2_fh_init(&ctx->fh, video_devdata(file));
 	file->private_data = &ctx->fh;
@@ -2403,6 +2405,9 @@ static int coda_open(struct file *file)
 	default:
 		ctx->reg_idx = idx;
 	}
+
+	clk_prepare_enable(dev->clk_per);
+	clk_prepare_enable(dev->clk_ahb);
 	set_default_params(ctx);
 	ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
 					 &coda_queue_init);
@@ -2411,12 +2416,12 @@ static int coda_open(struct file *file)
 
 		v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n",
 			 __func__, ret);
-		goto err;
+		goto err_ctx_init;
 	}
 	ret = coda_ctrls_setup(ctx);
 	if (ret) {
 		v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n");
-		goto err;
+		goto err_ctrls_setup;
 	}
 
 	ctx->fh.ctrl_handler = &ctx->ctrls;
@@ -2424,7 +2429,7 @@ static int coda_open(struct file *file)
 	ret = coda_alloc_context_buf(ctx, &ctx->parabuf, CODA_PARA_BUF_SIZE);
 	if (ret < 0) {
 		v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
-		goto err;
+		goto err_dma_alloc;
 	}
 
 	ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
@@ -2433,7 +2438,7 @@ static int coda_open(struct file *file)
 	if (!ctx->bitstream.vaddr) {
 		v4l2_err(&dev->v4l2_dev, "failed to allocate bitstream ringbuffer");
 		ret = -ENOMEM;
-		goto err;
+		goto err_dma_writecombine;
 	}
 	kfifo_init(&ctx->bitstream_fifo,
 		ctx->bitstream.vaddr, ctx->bitstream.size);
@@ -2444,17 +2449,27 @@ static int coda_open(struct file *file)
 	list_add(&ctx->list, &dev->instances);
 	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",
 		 ctx->idx, ctx);
 
 	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_exit(&ctx->fh);
+	clear_bit(ctx->idx, &dev->instance_mask);
+err_coda_max:
 	kfree(ctx);
 	return ret;
 }
@@ -2496,8 +2511,8 @@ static int coda_release(struct file *file)
 
 	coda_free_aux_buf(dev, &ctx->parabuf);
 	v4l2_ctrl_handler_free(&ctx->ctrls);
-	clk_disable_unprepare(dev->clk_per);
 	clk_disable_unprepare(dev->clk_ahb);
+	clk_disable_unprepare(dev->clk_per);
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
 	clear_bit(ctx->idx, &dev->instance_mask);
-- 
1.8.1.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v6 2/3] [media] coda: Check the return value from clk_prepare_enable()
  2013-08-20 19:29 [PATCH v6 1/3] [media] coda: Fix error paths Fabio Estevam
@ 2013-08-20 19:29 ` Fabio Estevam
  2013-08-21 14:45   ` Kamil Debski
  2013-08-20 19:29 ` [PATCH v6 3/3] [media] coda: No need to check the return value of platform_get_resource() Fabio Estevam
  1 sibling, 1 reply; 4+ messages in thread
From: Fabio Estevam @ 2013-08-20 19:29 UTC (permalink / raw)
  To: k.debski; +Cc: p.zabel, linux-media, Fabio Estevam

clk_prepare_enable() may fail, so let's check its return value and propagate it
in the case of error.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v5:
- Rebased against latest Kamil's tree

 drivers/media/platform/coda.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index b5d48b7..a68379c 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -2406,8 +2406,14 @@ static int coda_open(struct file *file)
 		ctx->reg_idx = idx;
 	}
 
-	clk_prepare_enable(dev->clk_per);
-	clk_prepare_enable(dev->clk_ahb);
+	ret = clk_prepare_enable(dev->clk_per);
+	if (ret)
+		goto err_clk_per;
+
+	ret = clk_prepare_enable(dev->clk_ahb);
+	if (ret)
+		goto err_clk_ahb;
+
 	set_default_params(ctx);
 	ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
 					 &coda_queue_init);
@@ -2465,7 +2471,9 @@ err_ctrls_setup:
        v4l2_m2m_ctx_release(ctx->m2m_ctx);
 err_ctx_init:
 	clk_disable_unprepare(dev->clk_ahb);
+err_clk_ahb:
 	clk_disable_unprepare(dev->clk_per);
+err_clk_per:
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
 	clear_bit(ctx->idx, &dev->instance_mask);
@@ -2873,10 +2881,15 @@ static int coda_hw_init(struct coda_dev *dev)
 	u16 product, major, minor, release;
 	u32 data;
 	u16 *p;
-	int i;
+	int i, ret;
+
+	ret = clk_prepare_enable(dev->clk_per);
+	if (ret)
+		return ret;
 
-	clk_prepare_enable(dev->clk_per);
-	clk_prepare_enable(dev->clk_ahb);
+	ret = clk_prepare_enable(dev->clk_ahb);
+	if (ret)
+		goto err_clk_ahb;
 
 	/*
 	 * Copy the first CODA_ISRAM_SIZE in the internal SRAM.
@@ -2985,6 +2998,10 @@ static int coda_hw_init(struct coda_dev *dev)
 	}
 
 	return 0;
+
+err_clk_ahb:
+	clk_disable_unprepare(dev->clk_per);
+	return ret;
 }
 
 static void coda_fw_callback(const struct firmware *fw, void *context)
-- 
1.8.1.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v6 3/3] [media] coda: No need to check the return value of platform_get_resource()
  2013-08-20 19:29 [PATCH v6 1/3] [media] coda: Fix error paths Fabio Estevam
  2013-08-20 19:29 ` [PATCH v6 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
@ 2013-08-20 19:29 ` Fabio Estevam
  1 sibling, 0 replies; 4+ messages in thread
From: Fabio Estevam @ 2013-08-20 19:29 UTC (permalink / raw)
  To: k.debski; +Cc: p.zabel, linux-media, Fabio Estevam

When using devm_ioremap_resource(), we do not need to check the return value of
platform_get_resource(), so just remove it.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
---
Changes since v5:
- Rebased against latest Kamil's tree

 drivers/media/platform/coda.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index a68379c..7ac8f46 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -3154,11 +3154,6 @@ static int coda_probe(struct platform_device *pdev)
 
 	/* Get  memory for physical registers */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (res == NULL) {
-		dev_err(&pdev->dev, "failed to get memory region resource\n");
-		return -ENOENT;
-	}
-
 	dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(dev->regs_base))
 		return PTR_ERR(dev->regs_base);
-- 
1.8.1.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH v6 2/3] [media] coda: Check the return value from clk_prepare_enable()
  2013-08-20 19:29 ` [PATCH v6 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
@ 2013-08-21 14:45   ` Kamil Debski
  0 siblings, 0 replies; 4+ messages in thread
From: Kamil Debski @ 2013-08-21 14:45 UTC (permalink / raw)
  To: 'Fabio Estevam'; +Cc: p.zabel, linux-media

Hi Fabio,

I still cannot apply this patch. There is something wrong.
Could you rebase this patch (or even better all 3 patches) to:
http://git.linuxtv.org/media_tree.git/shortlog/refs/heads/master ?

I really want to send the pull request before the end of the week. 

Best wishes,
-- 
Kamil Debski
Linux Kernel Developer
Samsung R&D Institute Poland


> -----Original Message-----
> From: linux-media-owner@vger.kernel.org [mailto:linux-media-
> owner@vger.kernel.org] On Behalf Of Fabio Estevam
> Sent: Tuesday, August 20, 2013 9:30 PM
> To: k.debski@samsung.com
> Cc: p.zabel@pengutronix.de; linux-media@vger.kernel.org; Fabio Estevam
> Subject: [PATCH v6 2/3] [media] coda: Check the return value from
> clk_prepare_enable()
> 
> clk_prepare_enable() may fail, so let's check its return value and
> propagate it in the case of error.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
> Changes since v5:
> - Rebased against latest Kamil's tree
> 
>  drivers/media/platform/coda.c | 27 ++++++++++++++++++++++-----
>  1 file changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/platform/coda.c
> b/drivers/media/platform/coda.c index b5d48b7..a68379c 100644
> --- a/drivers/media/platform/coda.c
> +++ b/drivers/media/platform/coda.c
> @@ -2406,8 +2406,14 @@ static int coda_open(struct file *file)
>  		ctx->reg_idx = idx;
>  	}
> 
> -	clk_prepare_enable(dev->clk_per);
> -	clk_prepare_enable(dev->clk_ahb);
> +	ret = clk_prepare_enable(dev->clk_per);
> +	if (ret)
> +		goto err_clk_per;
> +
> +	ret = clk_prepare_enable(dev->clk_ahb);
> +	if (ret)
> +		goto err_clk_ahb;
> +
>  	set_default_params(ctx);
>  	ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
>  					 &coda_queue_init);
> @@ -2465,7 +2471,9 @@ err_ctrls_setup:
>         v4l2_m2m_ctx_release(ctx->m2m_ctx);
>  err_ctx_init:
>  	clk_disable_unprepare(dev->clk_ahb);
> +err_clk_ahb:
>  	clk_disable_unprepare(dev->clk_per);
> +err_clk_per:
>  	v4l2_fh_del(&ctx->fh);
>  	v4l2_fh_exit(&ctx->fh);
>  	clear_bit(ctx->idx, &dev->instance_mask); @@ -2873,10 +2881,15 @@
> static int coda_hw_init(struct coda_dev *dev)
>  	u16 product, major, minor, release;
>  	u32 data;
>  	u16 *p;
> -	int i;
> +	int i, ret;
> +
> +	ret = clk_prepare_enable(dev->clk_per);
> +	if (ret)
> +		return ret;
> 
> -	clk_prepare_enable(dev->clk_per);
> -	clk_prepare_enable(dev->clk_ahb);
> +	ret = clk_prepare_enable(dev->clk_ahb);
> +	if (ret)
> +		goto err_clk_ahb;
> 
>  	/*
>  	 * Copy the first CODA_ISRAM_SIZE in the internal SRAM.
> @@ -2985,6 +2998,10 @@ static int coda_hw_init(struct coda_dev *dev)
>  	}
> 
>  	return 0;
> +
> +err_clk_ahb:
> +	clk_disable_unprepare(dev->clk_per);
> +	return ret;
>  }
> 
>  static void coda_fw_callback(const struct firmware *fw, void *context)
> --
> 1.8.1.2
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media"
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-08-21 14:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-20 19:29 [PATCH v6 1/3] [media] coda: Fix error paths Fabio Estevam
2013-08-20 19:29 ` [PATCH v6 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
2013-08-21 14:45   ` Kamil Debski
2013-08-20 19:29 ` [PATCH v6 3/3] [media] coda: No need to check the return value of platform_get_resource() Fabio Estevam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.