linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/3] [media] coda: Fix error paths
@ 2013-07-23 18:04 Fabio Estevam
  2013-07-23 18:04 ` [PATCH v4 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Fabio Estevam @ 2013-07-23 18:04 UTC (permalink / raw)
  To: k.debski; +Cc: m.chehab, kernel, 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 v3:
- Only disable the clocks after v4l2_m2m_ctx_release()
Changes since v2:
- Newly introduced in this series

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

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index df4ada88..9384f02 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -1514,21 +1514,26 @@ static int coda_open(struct file *file)
 	int ret = 0;
 	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);
+
 	v4l2_fh_init(&ctx->fh, video_devdata(file));
 	file->private_data = &ctx->fh;
 	v4l2_fh_add(&ctx->fh);
 	ctx->dev = dev;
 	ctx->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);
@@ -1537,12 +1542,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;
@@ -1552,24 +1557,29 @@ static int coda_open(struct file *file)
 	if (!ctx->parabuf.vaddr) {
 		v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
 		ret = -ENOMEM;
-		goto err;
+		goto err_dma_alloc;
 	}
 
 	coda_lock(ctx);
 	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_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;
 }
@@ -1588,10 +1598,10 @@ static int coda_release(struct file *file)
 
 	dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE,
 		ctx->parabuf.vaddr, ctx->parabuf.paddr);
-	v4l2_m2m_ctx_release(ctx->m2m_ctx);
 	v4l2_ctrl_handler_free(&ctx->ctrls);
-	clk_disable_unprepare(dev->clk_per);
+	v4l2_m2m_ctx_release(ctx->m2m_ctx);
 	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] 5+ messages in thread

* [PATCH v4 2/3] [media] coda: Check the return value from clk_prepare_enable()
  2013-07-23 18:04 [PATCH v4 1/3] [media] coda: Fix error paths Fabio Estevam
@ 2013-07-23 18:04 ` Fabio Estevam
  2013-07-23 18:04 ` [PATCH v4 3/3] [media] coda: No need to check the return value of platform_get_resource() Fabio Estevam
  2013-07-24  9:47 ` [PATCH v4 1/3] [media] coda: Fix error paths Philipp Zabel
  2 siblings, 0 replies; 5+ messages in thread
From: Fabio Estevam @ 2013-07-23 18:04 UTC (permalink / raw)
  To: k.debski; +Cc: m.chehab, kernel, 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 v3:
- Adapt it to make error handling easier
Changes since v2:
- Release the previously acquired resources
Changes since v1:
- Add missing 'if'

 drivers/media/platform/coda.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 9384f02..2d1576b 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -1531,8 +1531,13 @@ static int coda_open(struct file *file)
 	ctx->dev = dev;
 	ctx->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,
@@ -1575,7 +1580,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);
-- 
1.8.1.2



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

* [PATCH v4 3/3] [media] coda: No need to check the return value of platform_get_resource()
  2013-07-23 18:04 [PATCH v4 1/3] [media] coda: Fix error paths Fabio Estevam
  2013-07-23 18:04 ` [PATCH v4 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
@ 2013-07-23 18:04 ` Fabio Estevam
  2013-07-24  9:47 ` [PATCH v4 1/3] [media] coda: Fix error paths Philipp Zabel
  2 siblings, 0 replies; 5+ messages in thread
From: Fabio Estevam @ 2013-07-23 18:04 UTC (permalink / raw)
  To: k.debski; +Cc: m.chehab, kernel, 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 v3:
- None
Changes since v2:
- None
Changes since v1:
- None

 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 2d1576b..4a0a421 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -2049,11 +2049,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] 5+ messages in thread

* Re: [PATCH v4 1/3] [media] coda: Fix error paths
  2013-07-23 18:04 [PATCH v4 1/3] [media] coda: Fix error paths Fabio Estevam
  2013-07-23 18:04 ` [PATCH v4 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
  2013-07-23 18:04 ` [PATCH v4 3/3] [media] coda: No need to check the return value of platform_get_resource() Fabio Estevam
@ 2013-07-24  9:47 ` Philipp Zabel
  2013-08-01 15:27   ` Kamil Debski
  2 siblings, 1 reply; 5+ messages in thread
From: Philipp Zabel @ 2013-07-24  9:47 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: k.debski, m.chehab, kernel, linux-media

Hi Fabio,

Am Dienstag, den 23.07.2013, 15:04 -0300 schrieb 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 v3:
> - Only disable the clocks after v4l2_m2m_ctx_release()
> Changes since v2:
> - Newly introduced in this series
> 
>  drivers/media/platform/coda.c | 38 ++++++++++++++++++++++++--------------
>  1 file changed, 24 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
> index df4ada88..9384f02 100644
> --- a/drivers/media/platform/coda.c
> +++ b/drivers/media/platform/coda.c
> @@ -1514,21 +1514,26 @@ static int coda_open(struct file *file)
>  	int ret = 0;
>  	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);
> +
>  	v4l2_fh_init(&ctx->fh, video_devdata(file));
>  	file->private_data = &ctx->fh;
>  	v4l2_fh_add(&ctx->fh);
>  	ctx->dev = dev;
>  	ctx->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);
> @@ -1537,12 +1542,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;
> @@ -1552,24 +1557,29 @@ static int coda_open(struct file *file)
>  	if (!ctx->parabuf.vaddr) {
>  		v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
>  		ret = -ENOMEM;
> -		goto err;
> +		goto err_dma_alloc;
>  	}
>  
>  	coda_lock(ctx);
>  	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_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;
>  }
> @@ -1588,10 +1598,10 @@ static int coda_release(struct file *file)
>  
>  	dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE,
>  		ctx->parabuf.vaddr, ctx->parabuf.paddr);
> -	v4l2_m2m_ctx_release(ctx->m2m_ctx);
>  	v4l2_ctrl_handler_free(&ctx->ctrls);
> -	clk_disable_unprepare(dev->clk_per);
> +	v4l2_m2m_ctx_release(ctx->m2m_ctx);
>  	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);

this looks better, thanks. Could you rebase the patches onto Kamil's
http://git.linuxtv.org/kdebski/media.git/shortlog/refs/heads/new-for-3.12
branch?

regards
Philipp


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

* RE: [PATCH v4 1/3] [media] coda: Fix error paths
  2013-07-24  9:47 ` [PATCH v4 1/3] [media] coda: Fix error paths Philipp Zabel
@ 2013-08-01 15:27   ` Kamil Debski
  0 siblings, 0 replies; 5+ messages in thread
From: Kamil Debski @ 2013-08-01 15:27 UTC (permalink / raw)
  To: 'Philipp Zabel', 'Fabio Estevam'
  Cc: m.chehab, kernel, linux-media

Hi Fabio,

> From: Philipp Zabel [mailto:p.zabel@pengutronix.de]
> Sent: Wednesday, July 24, 2013 11:47 AM
> To: Fabio Estevam
> Cc: k.debski@samsung.com; m.chehab@samsung.com; kernel@pengutronix.de;
> linux-media@vger.kernel.org
> Subject: Re: [PATCH v4 1/3] [media] coda: Fix error paths
> 
> Hi Fabio,
> 
> Am Dienstag, den 23.07.2013, 15:04 -0300 schrieb 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 v3:
> > - Only disable the clocks after v4l2_m2m_ctx_release() Changes since
> > v2:
> > - Newly introduced in this series
> >
> >  drivers/media/platform/coda.c | 38
> > ++++++++++++++++++++++++--------------
> >  1 file changed, 24 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/media/platform/coda.c
> > b/drivers/media/platform/coda.c index df4ada88..9384f02 100644
> > --- a/drivers/media/platform/coda.c
> > +++ b/drivers/media/platform/coda.c
> > @@ -1514,21 +1514,26 @@ static int coda_open(struct file *file)
> >  	int ret = 0;
> >  	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);
> > +
> >  	v4l2_fh_init(&ctx->fh, video_devdata(file));
> >  	file->private_data = &ctx->fh;
> >  	v4l2_fh_add(&ctx->fh);
> >  	ctx->dev = dev;
> >  	ctx->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);
> > @@ -1537,12 +1542,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;
> > @@ -1552,24 +1557,29 @@ static int coda_open(struct file *file)
> >  	if (!ctx->parabuf.vaddr) {
> >  		v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
> >  		ret = -ENOMEM;
> > -		goto err;
> > +		goto err_dma_alloc;
> >  	}
> >
> >  	coda_lock(ctx);
> >  	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_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;
> >  }
> > @@ -1588,10 +1598,10 @@ static int coda_release(struct file *file)
> >
> >  	dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE,
> >  		ctx->parabuf.vaddr, ctx->parabuf.paddr);
> > -	v4l2_m2m_ctx_release(ctx->m2m_ctx);
> >  	v4l2_ctrl_handler_free(&ctx->ctrls);
> > -	clk_disable_unprepare(dev->clk_per);
> > +	v4l2_m2m_ctx_release(ctx->m2m_ctx);
> >  	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);
> 
> this looks better, thanks. Could you rebase the patches onto Kamil's
> http://git.linuxtv.org/kdebski/media.git/shortlog/refs/heads/new-for-
> 3.12
> branch?

Could you rebase these patches onto 
http://git.linuxtv.org/kdebski/media.git/shortlog/refs/heads/new-for-3.12-2nd
?

I get some conflicts and I am not sure how to resolve them.

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


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

end of thread, other threads:[~2013-08-01 15:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-23 18:04 [PATCH v4 1/3] [media] coda: Fix error paths Fabio Estevam
2013-07-23 18:04 ` [PATCH v4 2/3] [media] coda: Check the return value from clk_prepare_enable() Fabio Estevam
2013-07-23 18:04 ` [PATCH v4 3/3] [media] coda: No need to check the return value of platform_get_resource() Fabio Estevam
2013-07-24  9:47 ` [PATCH v4 1/3] [media] coda: Fix error paths Philipp Zabel
2013-08-01 15:27   ` Kamil Debski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).