From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@inria.fr>,
kernel-janitors <kernel-janitors@vger.kernel.org>,
kernelnewbies <kernelnewbies@kernelnewbies.org>,
linux-kernel-mentees@lists.linuxfoundation.org
Cc: Giuseppe Scrivano <gscrivan@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Whitcroft <apw@shadowen.org>, cocci <cocci@systeme.lip6.fr>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [Cocci] coccinelle: Convert comma to semicolons (was Re: [PATCH] checkpatch: Add test for comma use that should be semicolon)
Date: Fri, 21 Aug 2020 18:08:08 -0700 [thread overview]
Message-ID: <744af177c09f8ce22c99d6e1df458bced558518b.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2008201856110.2524@hadrien>
(forwarding on to kernel-janitors/mentees and kernelnewbies)
Just fyi for anyone that cares:
A janitorial task for someone might be to use Julia's coccinelle
script below to convert the existing instances of commas that
separate statements into semicolons.
https://lore.kernel.org/lkml/alpine.DEB.2.22.394.2008201856110.2524@hadrien/
On Thu, 2020-08-20 at 19:03 +0200, Julia Lawall wrote:
> > > I have a bunch of variations of this that are more complicated than I
> > > would have expected. One shorter variant that I have is:
> > >
> > > @@
> > > expression e1,e2;
> > > statement S;
> > > @@
> > >
> > > S
> > > e1
> > > -,
> > > +;
> > > (<+... e2 ...+>);
> > >
> > > This will miss cases where the first statement is the comma thing. But I
> > > think it is possible to improve this now. I will check.
> >
> > Hi Julia.
> >
> > Right, thanks, this adds a dependency on a statement
> > before the expression. Any stragglers would be easily
> > found using slightly different form.
> > There are not very many of these in linux kernel.
> >
> > Another nicety would be to allow the s/,/;/ conversion to
> > find both b and c in this sequence:
> > a = 1;
> > b = 2,
> > c = 3,
> > d = 4;
> > without running the script multiple times.
> > There are many dozen uses of this style in linux kernel.
> >
> > I tried variants of adding a comma after the e2 expression,
> > but cocci seems to have parsing problems with:
> >
> > @@
> > expression e1;
> > expression e2;
> > @@
> > e1
> > - ,
> > + ;
> > e2,
>
> This doesn't work because it's not a valid expression.
>
> The problem is solved by doing:
>
> e1
> - ,
> + ;
> e2
> ... when any
>
> But that doesn't work in the current version of Coccinelle. I have fixed
> the problem, though and it will work shortly.
>
> > I do appreciate that coccinelle adds braces for multiple
> > expression comma use after an if.
> >
> > i.e.:
> > if (foo)
> > a = 1, b = 2;
> > becomes
> > if (foo) {
> > a = 1; b = 2;
> > }
>
> I wasn't sure what was wanted for such things. Should b = 2 now be on a
> separate line?
>
> I took the strategy of avoiding the problem and leaving those cases as is.
> That also solves the LIST_HEAD problem. But if it is wanted to change
> these commas under ifs, then that is probably possible too.
>
> My current complete solution is as follows. The first rule avoids changing
> commas in macros, where thebody of the macro is just an expression. The
> second rule uses position variables to ensure that the two expression are
> on different lines.
>
> @r@
> expression e1,e2;
> statement S;
> position p;
> @@
>
> e1 ,@S@p e2;
>
> @@
> expression e1,e2;
> position p1;
> position p2 :
> script:ocaml(p1) { not((List.hd p1).line_end = (List.hd p2).line) };
> statement S;
> position r.p;
> @@
>
> e1@p1
> -,@S@p
> +;
> e2@p2
> ... when any
>
> The generated patch is below.
>
> julia
>
> diff -u -p a/drivers/reset/hisilicon/reset-hi3660.c b/drivers/reset/hisilicon/reset-hi3660.c
> --- a/drivers/reset/hisilicon/reset-hi3660.c
> +++ b/drivers/reset/hisilicon/reset-hi3660.c
> @@ -89,7 +89,7 @@ static int hi3660_reset_probe(struct pla
> return PTR_ERR(rc->map);
> }
>
> - rc->rst.ops = &hi3660_reset_ops,
> + rc->rst.ops = &hi3660_reset_ops;
> rc->rst.of_node = np;
> rc->rst.of_reset_n_cells = 2;
> rc->rst.of_xlate = hi3660_reset_xlate;
The rest of the changes are in the link above...
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next parent reply other threads:[~2020-08-22 1:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200818184107.f8af232fb58b17160c570874@linux-foundation.org>
[not found] ` <3bf27caf462007dfa75647b040ab3191374a59de.camel@perches.com>
[not found] ` <b0fd63e4b379eda69ee85ab098353582b8c054bb.camel@perches.com>
[not found] ` <alpine.DEB.2.22.394.2008201021400.2524@hadrien>
[not found] ` <a5713d8597065ef986f780499428fcc4cd31c003.camel@perches.com>
[not found] ` <alpine.DEB.2.22.394.2008201856110.2524@hadrien>
2020-08-22 1:08 ` Joe Perches [this message]
2020-08-22 3:35 ` [Cocci] coccinelle: Convert comma to semicolons (was Re: [PATCH] checkpatch: Add test for comma use that should be semicolon) Valdis Klētnieks
2020-08-22 5:30 ` Joe Perches
2020-08-22 7:07 ` Julia Lawall
2020-09-24 20:19 ` Thomas Gleixner
2020-09-24 20:21 ` Julia Lawall
2020-09-24 20:33 ` Joe Perches
2020-09-24 21:53 ` Thomas Gleixner
2020-09-24 22:23 ` Joe Perches
2020-09-25 17:06 ` Julia Lawall
2020-09-25 17:26 ` Joe Perches
2020-09-26 19:11 ` Valdis Klētnieks
2020-09-27 17:08 ` Julia Lawall
2020-09-27 17:45 ` Joe Perches
2020-09-27 19:35 ` Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=744af177c09f8ce22c99d6e1df458bced558518b.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=apw@shadowen.org \
--cc=cocci@systeme.lip6.fr \
--cc=gscrivan@redhat.com \
--cc=julia.lawall@inria.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=kernelnewbies@kernelnewbies.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).