linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] net: use semicolons rather than commas to separate statements
@ 2020-10-11 10:34 Julia Lawall
  2020-10-11 10:34 ` [PATCH 4/5] net/ipv6: " Julia Lawall
  2020-10-14  0:15 ` [PATCH 0/5] net: " Jakub Kicinski
  0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2020-10-11 10:34 UTC (permalink / raw)
  To: linux-security-module
  Cc: Valdis Klētnieks, Joe Perches, Thomas Gleixner,
	kernel-janitors, linux-wireless, linux-kernel, netdev,
	David S. Miller, Jakub Kicinski, linux-afs

These patches replace commas by semicolons.  Commas introduce
unnecessary variability in the code structure and are hard to see.
This was done using the Coccinelle semantic patch
(http://coccinelle.lip6.fr/) shown below.

This semantic patch ensures that commas inside for loop headers will
not be transformed.  It also doesn't touch macro definitions.

Coccinelle ensures that braces are added as needed when a
single-statement branch turns into a multi-statement one.

This semantic patch has a few false positives, for variable
delcarations such as:

LIST_HEAD(x), *y;

The semantic patch could be improved to avoid these, but for the
moment they have been removed manually (2 occurrences).

// <smpl>
@initialize:ocaml@
@@

let infunction p =
  (* avoid macros *)
  (List.hd p).current_element <> "something_else"

let combined p1 p2 =
  (List.hd p1).line_end = (List.hd p2).line ||
  (((List.hd p1).line_end < (List.hd p2).line) &&
   ((List.hd p1).col < (List.hd p2).col))

@bad@
statement S;
declaration d;
position p;
@@

S@p
d

// special cases where newlines are needed (hope for no more than 5)
@@
expression e1,e2;
statement S;
position p != bad.p;
position p1;
position p2 :
    script:ocaml(p1) { infunction p1 && combined p1 p2 };
@@

- e1@p1,@S@p e2@p2;
+ e1; e2;

@@
expression e1,e2;
statement S;
position p != bad.p;
position p1;
position p2 :
    script:ocaml(p1) { infunction p1 && combined p1 p2 };
@@

- e1@p1,@S@p e2@p2;
+ e1; e2;

@@
expression e1,e2;
statement S;
position p != bad.p;
position p1;
position p2 :
    script:ocaml(p1) { infunction p1 && combined p1 p2 };
@@

- e1@p1,@S@p e2@p2;
+ e1; e2;

@@
expression e1,e2;
statement S;
position p != bad.p;
position p1;
position p2 :
    script:ocaml(p1) { infunction p1 && combined p1 p2 };
@@

- e1@p1,@S@p e2@p2;
+ e1; e2;

@@
expression e1,e2;
statement S;
position p != bad.p;
position p1;
position p2 :
    script:ocaml(p1) { infunction p1 && combined p1 p2 };
@@

- e1@p1,@S@p e2@p2;
+ e1; e2;

@r@
expression e1,e2;
statement S;
position p != bad.p;
@@

e1 ,@S@p e2;

@@
expression e1,e2;
position p1;
position p2 :
    script:ocaml(p1) { infunction p1 && not(combined p1 p2) };
statement S;
position r.p;
@@

e1@p1
-,@S@p
+;
e2@p2
... when any
// </smpl>

---

 net/ipv4/tcp_input.c       |    3 ++-
 net/ipv4/tcp_vegas.c       |    8 ++++----
 net/ipv6/calipso.c         |    2 +-
 net/mac80211/debugfs_sta.c |    2 +-
 net/rxrpc/recvmsg.c        |    2 +-
 net/tls/tls_main.c         |    2 +-
 6 files changed, 10 insertions(+), 9 deletions(-)

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

* [PATCH 4/5] net/ipv6: use semicolons rather than commas to separate statements
  2020-10-11 10:34 [PATCH 0/5] net: use semicolons rather than commas to separate statements Julia Lawall
@ 2020-10-11 10:34 ` Julia Lawall
  2020-10-11 20:05   ` Paul Moore
  2020-10-14  0:15 ` [PATCH 0/5] net: " Jakub Kicinski
  1 sibling, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2020-10-11 10:34 UTC (permalink / raw)
  To: Paul Moore
  Cc: Valdis Klētnieks, Joe Perches, Thomas Gleixner,
	kernel-janitors, David S. Miller, Alexey Kuznetsov,
	Hideaki YOSHIFUJI, Jakub Kicinski, netdev, linux-security-module,
	linux-kernel

Replace commas with semicolons.  Commas introduce unnecessary
variability in the code structure and are hard to see.  What is done
is essentially described by the following Coccinelle semantic patch
(http://coccinelle.lip6.fr/):

// <smpl>
@@ expression e1,e2; @@
e1
-,
+;
e2
... when any
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>

---
 net/ipv6/calipso.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c
index 8d3f66c310db..78f766019b7e 100644
--- a/net/ipv6/calipso.c
+++ b/net/ipv6/calipso.c
@@ -761,7 +761,7 @@ static int calipso_genopt(unsigned char *buf, u32 start, u32 buf_len,
 	calipso[1] = len - 2;
 	*(__be32 *)(calipso + 2) = htonl(doi_def->doi);
 	calipso[6] = (len - CALIPSO_HDR_LEN) / 4;
-	calipso[7] = secattr->attr.mls.lvl,
+	calipso[7] = secattr->attr.mls.lvl;
 	crc = ~crc_ccitt(0xffff, calipso, len);
 	calipso[8] = crc & 0xff;
 	calipso[9] = (crc >> 8) & 0xff;


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

* Re: [PATCH 4/5] net/ipv6: use semicolons rather than commas to separate statements
  2020-10-11 10:34 ` [PATCH 4/5] net/ipv6: " Julia Lawall
@ 2020-10-11 20:05   ` Paul Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Moore @ 2020-10-11 20:05 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Valdis Klētnieks, Joe Perches, Thomas Gleixner,
	kernel-janitors, David S. Miller, Alexey Kuznetsov,
	Hideaki YOSHIFUJI, Jakub Kicinski, netdev, linux-security-module,
	linux-kernel

On Sun, Oct 11, 2020 at 7:18 AM Julia Lawall <Julia.Lawall@inria.fr> wrote:
>
> Replace commas with semicolons.  Commas introduce unnecessary
> variability in the code structure and are hard to see.  What is done
> is essentially described by the following Coccinelle semantic patch
> (http://coccinelle.lip6.fr/):
>
> // <smpl>
> @@ expression e1,e2; @@
> e1
> -,
> +;
> e2
> ... when any
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
>
> ---
>  net/ipv6/calipso.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks Julia.

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c
> index 8d3f66c310db..78f766019b7e 100644
> --- a/net/ipv6/calipso.c
> +++ b/net/ipv6/calipso.c
> @@ -761,7 +761,7 @@ static int calipso_genopt(unsigned char *buf, u32 start, u32 buf_len,
>         calipso[1] = len - 2;
>         *(__be32 *)(calipso + 2) = htonl(doi_def->doi);
>         calipso[6] = (len - CALIPSO_HDR_LEN) / 4;
> -       calipso[7] = secattr->attr.mls.lvl,
> +       calipso[7] = secattr->attr.mls.lvl;
>         crc = ~crc_ccitt(0xffff, calipso, len);
>         calipso[8] = crc & 0xff;
>         calipso[9] = (crc >> 8) & 0xff;

-- 
paul moore
www.paul-moore.com

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

* Re: [PATCH 0/5] net: use semicolons rather than commas to separate statements
  2020-10-11 10:34 [PATCH 0/5] net: use semicolons rather than commas to separate statements Julia Lawall
  2020-10-11 10:34 ` [PATCH 4/5] net/ipv6: " Julia Lawall
@ 2020-10-14  0:15 ` Jakub Kicinski
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2020-10-14  0:15 UTC (permalink / raw)
  To: Julia Lawall
  Cc: linux-security-module, Valdis Klētnieks, Joe Perches,
	Thomas Gleixner, kernel-janitors, linux-wireless, linux-kernel,
	netdev, David S. Miller, linux-afs

On Sun, 11 Oct 2020 12:34:53 +0200 Julia Lawall wrote:
> These patches replace commas by semicolons.  Commas introduce
> unnecessary variability in the code structure and are hard to see.
> This was done using the Coccinelle semantic patch
> (http://coccinelle.lip6.fr/) shown below.

Applied 3-5 to net-next, thanks!

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

end of thread, other threads:[~2020-10-14  0:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-11 10:34 [PATCH 0/5] net: use semicolons rather than commas to separate statements Julia Lawall
2020-10-11 10:34 ` [PATCH 4/5] net/ipv6: " Julia Lawall
2020-10-11 20:05   ` Paul Moore
2020-10-14  0:15 ` [PATCH 0/5] net: " Jakub Kicinski

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