linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5/5] drivers/video/msm/mdp.c: adjust error handling code
@ 2011-07-04 14:11 Julia Lawall
  2011-07-13  8:13 ` Paul Mundt
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2011-07-04 14:11 UTC (permalink / raw)
  To: David Brown
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman, Paul Mundt,
	linux-arm-msm, linux-fbdev, linux-kernel

From: Julia Lawall <julia@diku.dk>

Use the error handling code at the end of the function, rather than
returning directly.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier x;
@@

kfree(x)

@@
identifier r.x;
expression E1!=0,E2,E3,E4;
statement S;
@@

(
if (<+...x...+>) S
|
if (...) { ... when != kfree(x)
               when != if (...) { ... kfree(x); ... }
               when != x = E3
* return E1;
}
... when != x = E2
if (...) { ... when != x = E4
 kfree(x); ... return ...; }
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
I wonder if the error handling code at the end of the function should be
calling clk_put as well?  In that case, having a separate label for this
case would be useful.  Otherwise, one of error_request_irq and error_get_clk
can be deleted

 drivers/video/msm/mdp.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/video/msm/mdp.c b/drivers/video/msm/mdp.c
index 243d16f..01fa660 100644
--- a/drivers/video/msm/mdp.c
+++ b/drivers/video/msm/mdp.c
@@ -421,7 +421,8 @@ int mdp_probe(struct platform_device *pdev)
 	clk = clk_get(&pdev->dev, "mdp_clk");
 	if (IS_ERR(clk)) {
 		printk(KERN_INFO "mdp: failed to get mdp clk");
-		return PTR_ERR(clk);
+		ret = PTR_ERR(clk);
+		goto error_get_clk;
 	}
 
 	ret = request_irq(mdp->irq, mdp_isr, IRQF_DISABLED, "msm_mdp", mdp);
@@ -495,6 +496,7 @@ int mdp_probe(struct platform_device *pdev)
 error_device_register:
 	free_irq(mdp->irq, mdp);
 error_request_irq:
+error_get_clk:
 	iounmap(mdp->base);
 error_get_irq:
 error_ioremap:


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

* Re: [PATCH 5/5] drivers/video/msm/mdp.c: adjust error handling code
  2011-07-04 14:11 [PATCH 5/5] drivers/video/msm/mdp.c: adjust error handling code Julia Lawall
@ 2011-07-13  8:13 ` Paul Mundt
  2011-07-13 17:49   ` David Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Mundt @ 2011-07-13  8:13 UTC (permalink / raw)
  To: Julia Lawall
  Cc: David Brown, kernel-janitors, Daniel Walker, Bryan Huntsman,
	linux-arm-msm, linux-fbdev, linux-kernel

On Mon, Jul 04, 2011 at 04:11:45PM +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Use the error handling code at the end of the function, rather than
> returning directly.
> 
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @r@
> identifier x;
> @@
> 
> kfree(x)
> 
> @@
> identifier r.x;
> expression E1!=0,E2,E3,E4;
> statement S;
> @@
> 
> (
> if (<+...x...+>) S
> |
> if (...) { ... when != kfree(x)
>                when != if (...) { ... kfree(x); ... }
>                when != x = E3
> * return E1;
> }
> ... when != x = E2
> if (...) { ... when != x = E4
>  kfree(x); ... return ...; }
> )
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
Applied, thanks.

> I wonder if the error handling code at the end of the function should be
> calling clk_put as well?  In that case, having a separate label for this
> case would be useful.  Otherwise, one of error_request_irq and error_get_clk
> can be deleted
> 
The MSM implementation for it is simply a nop, so it's not going to
really matter one way or the other. In terms of general consistency it
might be worth implementing.

I expect that there are probably quite a few drivers that don't balance
out their clk_get()'s with clk_put()'s however, perhaps this is another
semantic patch candidate? At the very least it would be interesting to
see the statistics.

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

* Re: [PATCH 5/5] drivers/video/msm/mdp.c: adjust error handling code
  2011-07-13  8:13 ` Paul Mundt
@ 2011-07-13 17:49   ` David Brown
  0 siblings, 0 replies; 3+ messages in thread
From: David Brown @ 2011-07-13 17:49 UTC (permalink / raw)
  To: Paul Mundt
  Cc: Julia Lawall, kernel-janitors, Daniel Walker, Bryan Huntsman,
	linux-arm-msm, linux-fbdev, linux-kernel

On Wed, Jul 13 2011, Paul Mundt wrote:

>> I wonder if the error handling code at the end of the function should be
>> calling clk_put as well?  In that case, having a separate label for this
>> case would be useful.  Otherwise, one of error_request_irq and error_get_clk
>> can be deleted
>> 
> The MSM implementation for it is simply a nop, so it's not going to
> really matter one way or the other. In terms of general consistency it
> might be worth implementing.

Today, at least.  Hopefully this will get better, since we can turn off
our clocks.

David

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

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

end of thread, other threads:[~2011-07-13 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-04 14:11 [PATCH 5/5] drivers/video/msm/mdp.c: adjust error handling code Julia Lawall
2011-07-13  8:13 ` Paul Mundt
2011-07-13 17:49   ` David Brown

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).