Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] coccinelle: trivial linux code style reformatting
@ 2014-04-01 17:42 Joe Perches
  2014-04-01 18:29 ` Peter Senna Tschudin
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Joe Perches @ 2014-04-01 17:42 UTC (permalink / raw)
  To: cocci

Hello.

I tried this little cocci script to remove unnecessary
uses of return in void functions.

I tried with 2 different versions of spatch and get
different output content, neither of which is the
preferred kernel style.

The output is apparently correct and compilable.
It is just not kernel style.  I'm not sure there
is a defect really, just wanted to bring it up.

Maybe the first transform could be better written.

$ cat void_return.cocci
@@
identifier func;
expression S;
@@
void func(...) {
...
	if (...)
-		return S;
+		{ S; return; }
...
}

@@
identifier func;
expression S;
@@
void func(...) {
...
	if (...) {
...
-		return S;
+		S;
	}
...
}

@@
identifier func;
expression S;
@@
void func(...) {
...
-	return S;
+	S;
}
$

$ ~/coccinelle/spatch --version
spatch version 1.0.0-rc20 without Python support and with PCRE support

$ ~/coccinelle/spatch -sp-file void_return.cocci drivers/gpu/drm/i915/i915_irq.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: drivers/gpu/drm/i915/i915_irq.c
diff = 
--- drivers/gpu/drm/i915/i915_irq.c
+++ /tmp/cocci-output-13176-0a96c4-i915_irq.c
@@ -2818,7 +2818,10 @@ static void i915_hangcheck_elapsed(unsig
 	}
 
 	if (rings_hung)
-		return i915_handle_error(dev, true, "Ring hung");
+	{
+		i915_handle_error(dev, true, "Ring hung");
+		return;
+	}
 
 	if (busy_count)
 		/* Reset timer case chip hangs without another request


and with an older spatch version

$ spatch --version
spatch version 1.0.0-rc14 without Python support and with PCRE support

$ spatch -sp-file void_return.cocci drivers/gpu/drm/i915/i915_irq.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: drivers/gpu/drm/i915/i915_irq.c
diff = 
--- drivers/gpu/drm/i915/i915_irq.c
+++ /tmp/cocci-output-13258-bc64a5-i915_irq.c
@@ -2817,8 +2817,11 @@ static void i915_hangcheck_elapsed(unsig
 		}
 	}
 
-	if (rings_hung)
-		return i915_handle_error(dev, true, "Ring hung");
+	if (rings_hung) {
+		
+			i915_handle_error(dev, true, "Ring hung");
+			return;		
+		}
 
 	if (busy_count)
 		/* Reset timer case chip hangs without another request

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

end of thread, other threads:[~2014-04-02 10:55 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 17:42 [Cocci] coccinelle: trivial linux code style reformatting Joe Perches
2014-04-01 18:29 ` Peter Senna Tschudin
2014-04-01 23:11   ` Joe Perches
2014-04-02  5:53     ` Julia Lawall
2014-04-02  5:57       ` Joe Perches
2014-04-02  8:30       ` [Cocci] "trivial" " SF Markus Elfring
2014-04-02  8:35         ` Julia Lawall
2014-04-02  9:00           ` [Cocci] " SF Markus Elfring
2014-04-02 10:55           ` [Cocci] Restore source code from matched expressions? SF Markus Elfring
2014-04-01 20:02 ` [Cocci] "trivial" linux code style reformatting SF Markus Elfring
2014-04-01 23:26   ` Joe Perches
2014-04-02  7:19 ` [Cocci] Clarification for source " SF Markus Elfring
2014-04-02  7:43   ` Julia Lawall
2014-04-02  7:53     ` SF Markus Elfring
2014-04-02  8:33       ` Julia Lawall
2014-04-02  7:56   ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox