public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Coccinelle: Script to drop parenthesis in the return statements
@ 2014-06-19 16:29 Himangi Saraogi
  2014-06-19 16:34 ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Himangi Saraogi @ 2014-06-19 16:29 UTC (permalink / raw)
  To: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek, cocci,
	linux-kernel
  Cc: benoit.taine

This script detects the use of a parenthesis around return value ot the
return statements and removes them as they are unnecessary and against
the CodingStyle. A new directory called checkpatch is added for semantic
patches that just make patches for what checkpatch does. This will help
developers having checkpatch problems, to run the semantic patches in this
directory on their code and fix some of them automatically.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 .../coccinelle/checkpatch/drop_parenthesis.cocci   | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 scripts/coccinelle/checkpatch/drop_parenthesis.cocci

diff --git a/scripts/coccinelle/checkpatch/drop_parenthesis.cocci b/scripts/coccinelle/checkpatch/drop_parenthesis.cocci
new file mode 100644
index 0000000..49c0538
--- /dev/null
+++ b/scripts/coccinelle/checkpatch/drop_parenthesis.cocci
@@ -0,0 +1,33 @@
+/// Remove parenthesis around return value in return statements
+///
+//# This makes an effort to find cases of parenthesis in the return
+//# statements when returning an identifier or a constant and removes
+//# the parenthesis as they are not required.
+//
+// Confidence: High
+// Copyright: 2014, Himangi Saraogi  GPLv2.
+// Comments:
+// Options: --no-includes --include-headers
+//
+
+virtual patch
+
+//----------------------------------------------------------
+//  For patch mode
+//----------------------------------------------------------
+
+@depends on patch disable paren@
+identifier a;
+constant C;
+@@
+ return
+-(
+(
+C
+|
+a
+)
+-)
+ ;
+
-- 
1.9.1


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

* Re: [PATCH] Coccinelle: Script to drop parenthesis in the return statements
  2014-06-19 16:29 [PATCH] Coccinelle: Script to drop parenthesis in the return statements Himangi Saraogi
@ 2014-06-19 16:34 ` Joe Perches
  2014-06-19 16:49   ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2014-06-19 16:34 UTC (permalink / raw)
  To: Himangi Saraogi
  Cc: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek, cocci,
	linux-kernel, benoit.taine

On Thu, 2014-06-19 at 21:59 +0530, Himangi Saraogi wrote:
> This script detects the use of a parenthesis around return value ot the
> return statements and removes them as they are unnecessary and against
> the CodingStyle. A new directory called checkpatch is added for semantic
> patches that just make patches for what checkpatch does. This will help
> developers having checkpatch problems, to run the semantic patches in this
> directory on their code and fix some of them automatically.

checkpatch already has --fix and --fix-inplace options that
do something similar.



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

* Re: [PATCH] Coccinelle: Script to drop parenthesis in the return statements
  2014-06-19 16:34 ` Joe Perches
@ 2014-06-19 16:49   ` Julia Lawall
  2014-06-19 16:59     ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2014-06-19 16:49 UTC (permalink / raw)
  To: Joe Perches
  Cc: Himangi Saraogi, Julia Lawall, Gilles Muller, Nicolas Palix,
	Michal Marek, cocci, linux-kernel, benoit.taine

On Thu, 19 Jun 2014, Joe Perches wrote:

> On Thu, 2014-06-19 at 21:59 +0530, Himangi Saraogi wrote:
> > This script detects the use of a parenthesis around return value ot the
> > return statements and removes them as they are unnecessary and against
> > the CodingStyle. A new directory called checkpatch is added for semantic
> > patches that just make patches for what checkpatch does. This will help
> > developers having checkpatch problems, to run the semantic patches in this
> > directory on their code and fix some of them automatically.
>
> checkpatch already has --fix and --fix-inplace options that
> do something similar.

OK.  Then it is not worth adding coccinelle scripts for simple changes
like this one.

I guess that some of the more complex changes, like choosing an
appropriate error message function, checkpatch does not do?

julia

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

* Re: [PATCH] Coccinelle: Script to drop parenthesis in the return statements
  2014-06-19 16:49   ` Julia Lawall
@ 2014-06-19 16:59     ` Joe Perches
  2014-06-20  5:22       ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2014-06-19 16:59 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Himangi Saraogi, Gilles Muller, Nicolas Palix, Michal Marek,
	cocci, linux-kernel, benoit.taine

On Thu, 2014-06-19 at 18:49 +0200, Julia Lawall wrote:
> On Thu, 19 Jun 2014, Joe Perches wrote:
> > On Thu, 2014-06-19 at 21:59 +0530, Himangi Saraogi wrote:
> > > This script detects the use of a parenthesis around return value ot the
> > > return statements and removes them as they are unnecessary and against
> > > the CodingStyle. A new directory called checkpatch is added for semantic
> > > patches that just make patches for what checkpatch does. This will help
> > > developers having checkpatch problems, to run the semantic patches in this
> > > directory on their code and fix some of them automatically.
> >
> > checkpatch already has --fix and --fix-inplace options that
> > do something similar.
> 
> OK.  Then it is not worth adding coccinelle scripts for simple changes
> like this one.
> 
> I guess that some of the more complex changes, like choosing an
> appropriate error message function, checkpatch does not do?

I'm not quite sure what you're suggesting.

You mean choosing pr_err vs pr_notice or something
like finding an active struct <foo> and converting
printks to <foo>_<level>(&foo, fmt, ...)

from:
{
	struct device *dev;
	...
	printk(KERN_ERR "msg", ...)
to:
	dev_err(dev, "msg", ...)

checkpatch definitely can not do that.

Is it something else?


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

* Re: [PATCH] Coccinelle: Script to drop parenthesis in the return statements
  2014-06-19 16:59     ` Joe Perches
@ 2014-06-20  5:22       ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2014-06-20  5:22 UTC (permalink / raw)
  To: Joe Perches
  Cc: Himangi Saraogi, Gilles Muller, Nicolas Palix, Michal Marek,
	cocci, linux-kernel, benoit.taine



On Thu, 19 Jun 2014, Joe Perches wrote:

> On Thu, 2014-06-19 at 18:49 +0200, Julia Lawall wrote:
> > On Thu, 19 Jun 2014, Joe Perches wrote:
> > > On Thu, 2014-06-19 at 21:59 +0530, Himangi Saraogi wrote:
> > > > This script detects the use of a parenthesis around return value ot the
> > > > return statements and removes them as they are unnecessary and against
> > > > the CodingStyle. A new directory called checkpatch is added for semantic
> > > > patches that just make patches for what checkpatch does. This will help
> > > > developers having checkpatch problems, to run the semantic patches in this
> > > > directory on their code and fix some of them automatically.
> > >
> > > checkpatch already has --fix and --fix-inplace options that
> > > do something similar.
> > 
> > OK.  Then it is not worth adding coccinelle scripts for simple changes
> > like this one.
> > 
> > I guess that some of the more complex changes, like choosing an
> > appropriate error message function, checkpatch does not do?
> 
> I'm not quite sure what you're suggesting.
> 
> You mean choosing pr_err vs pr_notice or something
> like finding an active struct <foo> and converting
> printks to <foo>_<level>(&foo, fmt, ...)
> 
> from:
> {
> 	struct device *dev;
> 	...
> 	printk(KERN_ERR "msg", ...)
> to:
> 	dev_err(dev, "msg", ...)
> 
> checkpatch definitely can not do that.
> 
> Is it something else?

Yes, that is what I was thinking of.  Anyway, we can just test whether 
checkpatch --fix can d the change before proposing a semantic patch for 
it.

julia

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

end of thread, other threads:[~2014-06-20  5:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-19 16:29 [PATCH] Coccinelle: Script to drop parenthesis in the return statements Himangi Saraogi
2014-06-19 16:34 ` Joe Perches
2014-06-19 16:49   ` Julia Lawall
2014-06-19 16:59     ` Joe Perches
2014-06-20  5:22       ` Julia Lawall

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