1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Detect BQ27XXX_DATA structures with identical registers, dm registers or
4 //# Doesn't unfold macros used in register or property fields.
5 //# Requires OCaml scripting
8 // Copyright: (C) 2017 Julia Lawall, Inria/LIP6,
9 // URL: http://coccinelle.lip6.fr/
11 // Keywords: BQ27XXX_DATA
18 let print_report p msg =
20 Printf.printf "%s:%d:%d-%d: %s" p.file p.line p.col p.col_end msg
22 @str depends on report@
30 [e1] = BQ27XXX_DATA(i1,...),
32 [e2] = BQ27XXX_DATA(i2,...),
36 @script:ocaml tocheck@
47 i1regs := make_ident (i1 ^ "_regs");
48 i2regs := make_ident (i2 ^ "_regs");
49 i1dmregs := make_ident (i1 ^ "_dm_regs");
50 i2dmregs := make_ident (i2 ^ "_dm_regs");
51 i1props := make_ident (i1 ^ "_props");
52 i2props := make_ident (i2 ^ "_props")
55 (* ---------------------------------------------------------------- *)
59 identifier tocheck.i1regs;
60 initializer list i1regs_vals;
64 u8 i1regs@p1[...] = { i1regs_vals, };
67 identifier tocheck.i2regs;
68 initializer list i2regs_vals;
72 u8 i2regs@p2[...] = { i2regs_vals, };
75 (_,i1regs_vals) << getregs1.i1regs_vals;
76 (_,i2regs_vals) << getregs2.i2regs_vals;
77 i1regs << tocheck.i1regs;
78 i2regs << tocheck.i2regs;
84 List.sort compare i1regs_vals = List.sort compare i2regs_vals
88 "WARNING %s and %s (line %d) are identical\n"
89 i1regs i2regs (List.hd p2).line in
92 (* ---------------------------------------------------------------- *)
95 identifier tocheck.i1dmregs;
96 initializer list i1dmregs_vals;
100 struct bq27xxx_dm_reg i1dmregs@p1[] = { i1dmregs_vals, };
103 identifier tocheck.i2dmregs;
104 initializer list i2dmregs_vals;
108 struct bq27xxx_dm_reg i2dmregs@p2[] = { i2dmregs_vals, };
111 (_,i1dmregs_vals) << getdmregs1.i1dmregs_vals;
112 (_,i2dmregs_vals) << getdmregs2.i2dmregs_vals;
113 i1dmregs << tocheck.i1dmregs;
114 i2dmregs << tocheck.i2dmregs;
119 if i1dmregs < i2dmregs &&
120 List.sort compare i1dmregs_vals = List.sort compare i2dmregs_vals
124 "WARNING %s and %s (line %d) are identical\n"
125 i1dmregs i2dmregs (List.hd p2).line in
128 (* ---------------------------------------------------------------- *)
131 identifier tocheck.i1props;
132 initializer list[n1] i1props_vals;
136 enum power_supply_property i1props@p1[] = { i1props_vals, };
139 identifier tocheck.i2props;
140 initializer list[n2] i2props_vals;
144 enum power_supply_property i2props@p2[] = { i2props_vals, };
147 (_,i1props_vals) << getprops1.i1props_vals;
148 (_,i2props_vals) << getprops2.i2props_vals;
149 i1props << tocheck.i1props;
150 i2props << tocheck.i2props;
155 if i1props < i2props &&
156 List.sort compare i1props_vals = List.sort compare i2props_vals
160 "WARNING %s and %s (line %d) are identical\n"
161 i1props i2props (List.hd p2).line in