Discussion:
[Cocci] [PATCH 0/2] detect identical chip data arrays
Julia Lawall
2017-10-08 19:18:39 UTC
Permalink
Rename battery.cocci as check_bq27xxx_data.cocci and adjust the warning
messages to indicate that some structures are the same, in response to
feedback from Liam Breck.

Although check_bq27xxx_data.cocci says is requires Coccinelle 1.0.7, which
is not yet released, it actually works with the version currently available
on Github, eg from Coccinelle commit 3ba77b3a0f91.

---

scripts/coccinelle/api/battery.cocci | 161 ------------------------
scripts/coccinelle/api/check_bq27xxx_data.cocci | 161 ++++++++++++++++++++++++
2 files changed, 161 insertions(+), 161 deletions(-)
Julia Lawall
2017-10-08 19:18:40 UTC
Permalink
Drop bettery.cocci as a more specific filename was preferred.

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

---
scripts/coccinelle/api/battery.cocci | 161 -----------------------------------
1 file changed, 161 deletions(-)

diff --git a/scripts/coccinelle/api/battery.cocci b/scripts/coccinelle/api/battery.cocci
deleted file mode 100644
index 77c145a..0000000
--- a/scripts/coccinelle/api/battery.cocci
+++ /dev/null
@@ -1,161 +0,0 @@
-/// Detect BQ27XXX_DATA structures with identical registers, dm registers or
-/// properties.
-//# Doesn't unfold macros used in register or property fields.
-//# Requires OCaml scripting
-///
-// Confidence: High
-// Copyright: (C) 2017 Julia Lawall, Inria/LIP6, GPLv2.
-// URL: http://coccinelle.lip6.fr/
-// Requires: 1.0.7
-// Keywords: BQ27XXX_DATA
-
-virtual report
-
-@initialize:ocaml@
-@@
-
-let print_report p msg =
- let p = List.hd p in
- Printf.printf "%s:%d:%d-%d: %s" p.file p.line p.col p.col_end msg
-
-@str depends on report@
-type t;
-identifier i,i1,i2;
-expression e1,e2;
-@@
-
-t i[] = {
- ...,
- [e1] = BQ27XXX_DATA(i1,...),
- ...,
- [e2] = BQ27XXX_DATA(i2,...),
- ...,
-};
-
-@script:ocaml tocheck@
-i1 << str.i1;
-i2 << str.i2;
-i1regs; i2regs;
-i1dmregs; i2dmregs;
-i1props; i2props;
-@@
-
-if not(i1 = i2)
-then
- begin
- i1regs := make_ident (i1 ^ "_regs");
- i2regs := make_ident (i2 ^ "_regs");
- i1dmregs := make_ident (i1 ^ "_dm_regs");
- i2dmregs := make_ident (i2 ^ "_dm_regs");
- i1props := make_ident (i1 ^ "_props");
- i2props := make_ident (i2 ^ "_props")
- end
-
-(* ---------------------------------------------------------------- *)
-
-@getregs1@
-typedef u8;
-identifier tocheck.i1regs;
-initializer list i1regs_vals;
-position p1;
-@@
-
-u8 ***@p1[...] = { i1regs_vals, };
-
-@getregs2@
-identifier tocheck.i2regs;
-initializer list i2regs_vals;
-position p2;
-@@
-
-u8 ***@p2[...] = { i2regs_vals, };
-
-@script:ocaml@
-(_,i1regs_vals) << getregs1.i1regs_vals;
-(_,i2regs_vals) << getregs2.i2regs_vals;
-i1regs << tocheck.i1regs;
-i2regs << tocheck.i2regs;
-p1 << getregs1.p1;
-p2 << getregs2.p2;
-@@
-
-if i1regs < i2regs &&
- List.sort compare i1regs_vals = List.sort compare i2regs_vals
-then
- let msg =
- Printf.sprintf
- "WARNING %s and %s (line %d) have the same registers\n"
- i1regs i2regs (List.hd p2).line in
- print_report p1 msg
-
-(* ---------------------------------------------------------------- *)
-
-@getdmregs1@
-identifier tocheck.i1dmregs;
-initializer list i1dmregs_vals;
-position p1;
-@@
-
-struct bq27xxx_dm_reg ***@p1[] = { i1dmregs_vals, };
-
-@getdmregs2@
-identifier tocheck.i2dmregs;
-initializer list i2dmregs_vals;
-position p2;
-@@
-
-struct bq27xxx_dm_reg ***@p2[] = { i2dmregs_vals, };
-
-@script:ocaml@
-(_,i1dmregs_vals) << getdmregs1.i1dmregs_vals;
-(_,i2dmregs_vals) << getdmregs2.i2dmregs_vals;
-i1dmregs << tocheck.i1dmregs;
-i2dmregs << tocheck.i2dmregs;
-p1 << getdmregs1.p1;
-p2 << getdmregs2.p2;
-@@
-
-if i1dmregs < i2dmregs &&
- List.sort compare i1dmregs_vals = List.sort compare i2dmregs_vals
-then
- let msg =
- Printf.sprintf
- "WARNING %s and %s (line %d) have the same dm registers\n"
- i1dmregs i2dmregs (List.hd p2).line in
- print_report p1 msg
-
-(* ---------------------------------------------------------------- *)
-
-@getprops1@
-identifier tocheck.i1props;
-initializer list[n1] i1props_vals;
-position p1;
-@@
-
-enum power_supply_property ***@p1[] = { i1props_vals, };
-
-@getprops2@
-identifier tocheck.i2props;
-initializer list[n2] i2props_vals;
-position p2;
-@@
-
-enum power_supply_property ***@p2[] = { i2props_vals, };
-
-@script:ocaml@
-(_,i1props_vals) << getprops1.i1props_vals;
-(_,i2props_vals) << getprops2.i2props_vals;
-i1props << tocheck.i1props;
-i2props << tocheck.i2props;
-p1 << getprops1.p1;
-p2 << getprops2.p2;
-@@
-
-if i1props < i2props &&
- List.sort compare i1props_vals = List.sort compare i2props_vals
-then
- let msg =
- Printf.sprintf
- "WARNING %s and %s (line %d) have the same properties\n"
- i1props i2props (List.hd p2).line in
- print_report p1 msg
Julia Lawall
2017-10-08 19:18:41 UTC
Permalink
This semantic patch detects duplicate arrays declared using BQ27XXX_DATA
within a single structure. It is currently specific to the file
drivers/power/supply/bq27xxx_battery.c. Nevertheless, having the script in
the kernel will allow others to check their code if the data structures
change in the future.

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

---
scripts/coccinelle/api/check_bq27xxx_data.cocci | 161 ++++++++++++++++++++++++
1 file changed, 161 insertions(+)

diff --git a/scripts/coccinelle/api/check_bq27xxx_data.cocci b/scripts/coccinelle/api/check_bq27xxx_data.cocci
new file mode 100644
index 0000000..9212b85
--- /dev/null
+++ b/scripts/coccinelle/api/check_bq27xxx_data.cocci
@@ -0,0 +1,161 @@
+/// Detect BQ27XXX_DATA structures with identical registers, dm registers or
+/// properties.
+//# Doesn't unfold macros used in register or property fields.
+//# Requires OCaml scripting
+///
+// Confidence: High
+// Copyright: (C) 2017 Julia Lawall, Inria/LIP6, GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Requires: 1.0.7
+// Keywords: BQ27XXX_DATA
+
+virtual report
+
+@initialize:ocaml@
+@@
+
+let print_report p msg =
+ let p = List.hd p in
+ Printf.printf "%s:%d:%d-%d: %s" p.file p.line p.col p.col_end msg
+
+@str depends on report@
+type t;
+identifier i,i1,i2;
+expression e1,e2;
+@@
+
+t i[] = {
+ ...,
+ [e1] = BQ27XXX_DATA(i1,...),
+ ...,
+ [e2] = BQ27XXX_DATA(i2,...),
+ ...,
+};
+
+@script:ocaml tocheck@
+i1 << str.i1;
+i2 << str.i2;
+i1regs; i2regs;
+i1dmregs; i2dmregs;
+i1props; i2props;
+@@
+
+if not(i1 = i2)
+then
+ begin
+ i1regs := make_ident (i1 ^ "_regs");
+ i2regs := make_ident (i2 ^ "_regs");
+ i1dmregs := make_ident (i1 ^ "_dm_regs");
+ i2dmregs := make_ident (i2 ^ "_dm_regs");
+ i1props := make_ident (i1 ^ "_props");
+ i2props := make_ident (i2 ^ "_props")
+ end
+
+(* ---------------------------------------------------------------- *)
+
+@getregs1@
+typedef u8;
+identifier tocheck.i1regs;
+initializer list i1regs_vals;
+position p1;
+@@
+
+u8 ***@p1[...] = { i1regs_vals, };
+
+@getregs2@
+identifier tocheck.i2regs;
+initializer list i2regs_vals;
+position p2;
+@@
+
+u8 ***@p2[...] = { i2regs_vals, };
+
+@script:ocaml@
+(_,i1regs_vals) << getregs1.i1regs_vals;
+(_,i2regs_vals) << getregs2.i2regs_vals;
+i1regs << tocheck.i1regs;
+i2regs << tocheck.i2regs;
+p1 << getregs1.p1;
+p2 << getregs2.p2;
+@@
+
+if i1regs < i2regs &&
+ List.sort compare i1regs_vals = List.sort compare i2regs_vals
+then
+ let msg =
+ Printf.sprintf
+ "WARNING %s and %s (line %d) are identical\n"
+ i1regs i2regs (List.hd p2).line in
+ print_report p1 msg
+
+(* ---------------------------------------------------------------- *)
+
+@getdmregs1@
+identifier tocheck.i1dmregs;
+initializer list i1dmregs_vals;
+position p1;
+@@
+
+struct bq27xxx_dm_reg ***@p1[] = { i1dmregs_vals, };
+
+@getdmregs2@
+identifier tocheck.i2dmregs;
+initializer list i2dmregs_vals;
+position p2;
+@@
+
+struct bq27xxx_dm_reg ***@p2[] = { i2dmregs_vals, };
+
+@script:ocaml@
+(_,i1dmregs_vals) << getdmregs1.i1dmregs_vals;
+(_,i2dmregs_vals) << getdmregs2.i2dmregs_vals;
+i1dmregs << tocheck.i1dmregs;
+i2dmregs << tocheck.i2dmregs;
+p1 << getdmregs1.p1;
+p2 << getdmregs2.p2;
+@@
+
+if i1dmregs < i2dmregs &&
+ List.sort compare i1dmregs_vals = List.sort compare i2dmregs_vals
+then
+ let msg =
+ Printf.sprintf
+ "WARNING %s and %s (line %d) are identical\n"
+ i1dmregs i2dmregs (List.hd p2).line in
+ print_report p1 msg
+
+(* ---------------------------------------------------------------- *)
+
+@getprops1@
+identifier tocheck.i1props;
+initializer list[n1] i1props_vals;
+position p1;
+@@
+
+enum power_supply_property ***@p1[] = { i1props_vals, };
+
+@getprops2@
+identifier tocheck.i2props;
+initializer list[n2] i2props_vals;
+position p2;
+@@
+
+enum power_supply_property ***@p2[] = { i2props_vals, };
+
+@script:ocaml@
+(_,i1props_vals) << getprops1.i1props_vals;
+(_,i2props_vals) << getprops2.i2props_vals;
+i1props << tocheck.i1props;
+i2props << tocheck.i2props;
+p1 << getprops1.p1;
+p2 << getprops2.p2;
+@@
+
+if i1props < i2props &&
+ List.sort compare i1props_vals = List.sort compare i2props_vals
+then
+ let msg =
+ Printf.sprintf
+ "WARNING %s and %s (line %d) are identical\n"
+ i1props i2props (List.hd p2).line in
+ print_report p1 msg
Masahiro Yamada
2017-11-07 00:21:11 UTC
Permalink
Post by Julia Lawall
This semantic patch detects duplicate arrays declared using BQ27XXX_DATA
within a single structure. It is currently specific to the file
drivers/power/supply/bq27xxx_battery.c. Nevertheless, having the script in
the kernel will allow others to check their code if the data structures
change in the future.
Applied to linux-kbuild/misc.
--
Best Regards
Masahiro Yamada
Julia Lawall
2017-11-08 13:04:17 UTC
Permalink
Post by Masahiro Yamada
Post by Julia Lawall
This semantic patch detects duplicate arrays declared using BQ27XXX_DATA
within a single structure. It is currently specific to the file
drivers/power/supply/bq27xxx_battery.c. Nevertheless, having the script in
the kernel will allow others to check their code if the data structures
change in the future.
Applied to linux-kbuild/misc.
Thanks!

julia

Sebastian Reichel
2017-10-08 20:32:58 UTC
Permalink
Hi,
Post by Julia Lawall
Rename battery.cocci as check_bq27xxx_data.cocci and adjust the warning
messages to indicate that some structures are the same, in response to
feedback from Liam Breck.
Although check_bq27xxx_data.cocci says is requires Coccinelle 1.0.7, which
is not yet released, it actually works with the version currently available
on Github, eg from Coccinelle commit 3ba77b3a0f91.
I think the rename makes sense, but I would expect the move to
happen in one go with "git send-email -M", so that it detects the
rename.

-- Sebastian
Julia Lawall
2017-10-08 20:44:50 UTC
Permalink
Post by Sebastian Reichel
Hi,
Post by Julia Lawall
Rename battery.cocci as check_bq27xxx_data.cocci and adjust the warning
messages to indicate that some structures are the same, in response to
feedback from Liam Breck.
Although check_bq27xxx_data.cocci says is requires Coccinelle 1.0.7, which
is not yet released, it actually works with the version currently available
on Github, eg from Coccinelle commit 3ba77b3a0f91.
I think the rename makes sense, but I would expect the move to
happen in one go with "git send-email -M", so that it detects the
rename.
I'm not actually sure what is the status of the previous version.
Masahiro said applied, but I downloaded his tree and it was not there. So
I thought this way would be easier.

julia
Sebastian Reichel
2017-10-08 21:26:10 UTC
Permalink
Hi,
Post by Julia Lawall
Post by Sebastian Reichel
Hi,
Post by Julia Lawall
Rename battery.cocci as check_bq27xxx_data.cocci and adjust the warning
messages to indicate that some structures are the same, in response to
feedback from Liam Breck.
Although check_bq27xxx_data.cocci says is requires Coccinelle 1.0.7, which
is not yet released, it actually works with the version currently available
on Github, eg from Coccinelle commit 3ba77b3a0f91.
I think the rename makes sense, but I would expect the move to
happen in one go with "git send-email -M", so that it detects the
rename.
I'm not actually sure what is the status of the previous version.
Masahiro said applied, but I downloaded his tree and it was not there. So
I thought this way would be easier.
julia
Ok. In that case it makes sense to just apply the one with better
name of course :) Thanks for the script!

-- Sebastian
Julia Lawall
2017-10-09 08:40:14 UTC
Permalink
Post by Julia Lawall
Post by Sebastian Reichel
Hi,
Post by Julia Lawall
Rename battery.cocci as check_bq27xxx_data.cocci and adjust the warning
messages to indicate that some structures are the same, in response to
feedback from Liam Breck.
Although check_bq27xxx_data.cocci says is requires Coccinelle 1.0.7, which
is not yet released, it actually works with the version currently available
on Github, eg from Coccinelle commit 3ba77b3a0f91.
I think the rename makes sense, but I would expect the move to
happen in one go with "git send-email -M", so that it detects the
rename.
I'm not actually sure what is the status of the previous version.
Masahiro said applied, but I downloaded his tree and it was not there. So
I thought this way would be easier.
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git
I had applied your patch a few days before.
OK, I got that tree, but it seemed to go only up to October 1. But maybe
I did not pick the right branch.
BTW, how should I handle this series?
1/2 is reverting it.
So, I can drop the previous one entirely,
then pick up 2/2 only.
Is this a good thing to do?
That would be perfectly fine with me. You can drop 1/2 already. For 2/2,
it would be nice to have an Ack from Liam first.

thanks,
julia
--
Best Regards
Masahiro Yamada
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
More majordomo info at http://vger.kernel.org/majordomo-info.html
Masahiro Yamada
2017-10-09 09:11:49 UTC
Permalink
Post by Julia Lawall
Post by Julia Lawall
Post by Sebastian Reichel
Hi,
Post by Julia Lawall
Rename battery.cocci as check_bq27xxx_data.cocci and adjust the warning
messages to indicate that some structures are the same, in response to
feedback from Liam Breck.
Although check_bq27xxx_data.cocci says is requires Coccinelle 1.0.7, which
is not yet released, it actually works with the version currently available
on Github, eg from Coccinelle commit 3ba77b3a0f91.
I think the rename makes sense, but I would expect the move to
happen in one go with "git send-email -M", so that it detects the
rename.
I'm not actually sure what is the status of the previous version.
Masahiro said applied, but I downloaded his tree and it was not there. So
I thought this way would be easier.
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git
I had applied your patch a few days before.
OK, I got that tree, but it seemed to go only up to October 1. But maybe
I did not pick the right branch.
Oct 1 is the date you submitted it.
According to "git log --pretty=fuller", I applied it Oct 5.
I do not not remember when I pushed it, though.

commit ffb11fd663a2b9cefbe24e8e3dd2ebcacd338d69
Author: Julia Lawall <***@lip6.fr>
AuthorDate: Sun Oct 1 14:42:48 2017 +0200
Commit: Masahiro Yamada <***@socionext.com>
CommitDate: Thu Oct 5 08:37:12 2017 +0900

coccinelle: api: detect duplicate chip data arrays
Post by Julia Lawall
BTW, how should I handle this series?
1/2 is reverting it.
So, I can drop the previous one entirely,
then pick up 2/2 only.
Is this a good thing to do?
That would be perfectly fine with me. You can drop 1/2 already. For 2/2,
it would be nice to have an Ack from Liam first.
thanks,
julia
OK. I will drop the previous one.

I will hold back 2/2 until it gets Ack from Liam.
--
Best Regards
Masahiro Yamada
Loading...