~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/coccinelle/api/check_bq27xxx_data.cocci

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /// Detect BQ27XXX_DATA structures with identical registers, dm registers or
  3 /// properties.
  4 //# Doesn't unfold macros used in register or property fields.
  5 //# Requires OCaml scripting
  6 ///
  7 // Confidence: High
  8 // Copyright: (C) 2017 Julia Lawall, Inria/LIP6,
  9 // URL: https://coccinelle.gitlabpages.inria.fr/website
 10 // Requires: 1.0.7
 11 // Keywords: BQ27XXX_DATA
 12 
 13 virtual report
 14 
 15 @initialize:ocaml@
 16 @@
 17 
 18 let print_report p msg =
 19   let p = List.hd p in
 20   Printf.printf "%s:%d:%d-%d: %s" p.file p.line p.col p.col_end msg
 21 
 22 @str depends on report@
 23 type t;
 24 identifier i,i1,i2;
 25 expression e1,e2;
 26 @@
 27 
 28 t i[] = {
 29   ...,
 30   [e1] = BQ27XXX_DATA(i1,...),
 31   ...,
 32   [e2] = BQ27XXX_DATA(i2,...),
 33   ...,
 34 };
 35 
 36 @script:ocaml tocheck@
 37 i1 << str.i1;
 38 i2 << str.i2;
 39 i1regs; i2regs;
 40 i1dmregs; i2dmregs;
 41 i1props; i2props;
 42 @@
 43 
 44 if not(i1 = i2)
 45 then
 46   begin
 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")
 53   end
 54 
 55 (* ---------------------------------------------------------------- *)
 56 
 57 @getregs1@
 58 typedef u8;
 59 identifier tocheck.i1regs;
 60 initializer list i1regs_vals;
 61 position p1;
 62 @@
 63 
 64 u8 i1regs@p1[...] = { i1regs_vals, };
 65 
 66 @getregs2@
 67 identifier tocheck.i2regs;
 68 initializer list i2regs_vals;
 69 position p2;
 70 @@
 71 
 72 u8 i2regs@p2[...] = { i2regs_vals, };
 73 
 74 @script:ocaml@
 75 (_,i1regs_vals) << getregs1.i1regs_vals;
 76 (_,i2regs_vals) << getregs2.i2regs_vals;
 77 i1regs << tocheck.i1regs;
 78 i2regs << tocheck.i2regs;
 79 p1 << getregs1.p1;
 80 p2 << getregs2.p2;
 81 @@
 82 
 83 if i1regs < i2regs &&
 84    List.sort compare i1regs_vals = List.sort compare i2regs_vals
 85 then
 86   let msg =
 87     Printf.sprintf
 88       "WARNING %s and %s (line %d) are identical\n"
 89       i1regs i2regs (List.hd p2).line in
 90   print_report p1 msg
 91 
 92 (* ---------------------------------------------------------------- *)
 93 
 94 @getdmregs1@
 95 identifier tocheck.i1dmregs;
 96 initializer list i1dmregs_vals;
 97 position p1;
 98 @@
 99 
100 struct bq27xxx_dm_reg i1dmregs@p1[] = { i1dmregs_vals, };
101 
102 @getdmregs2@
103 identifier tocheck.i2dmregs;
104 initializer list i2dmregs_vals;
105 position p2;
106 @@
107 
108 struct bq27xxx_dm_reg i2dmregs@p2[] = { i2dmregs_vals, };
109 
110 @script:ocaml@
111 (_,i1dmregs_vals) << getdmregs1.i1dmregs_vals;
112 (_,i2dmregs_vals) << getdmregs2.i2dmregs_vals;
113 i1dmregs << tocheck.i1dmregs;
114 i2dmregs << tocheck.i2dmregs;
115 p1 << getdmregs1.p1;
116 p2 << getdmregs2.p2;
117 @@
118 
119 if i1dmregs < i2dmregs &&
120    List.sort compare i1dmregs_vals = List.sort compare i2dmregs_vals
121 then
122   let msg =
123     Printf.sprintf
124       "WARNING %s and %s (line %d) are identical\n"
125       i1dmregs i2dmregs (List.hd p2).line in
126   print_report p1 msg
127 
128 (* ---------------------------------------------------------------- *)
129 
130 @getprops1@
131 identifier tocheck.i1props;
132 initializer list[n1] i1props_vals;
133 position p1;
134 @@
135 
136 enum power_supply_property i1props@p1[] = { i1props_vals, };
137 
138 @getprops2@
139 identifier tocheck.i2props;
140 initializer list[n2] i2props_vals;
141 position p2;
142 @@
143 
144 enum power_supply_property i2props@p2[] = { i2props_vals, };
145 
146 @script:ocaml@
147 (_,i1props_vals) << getprops1.i1props_vals;
148 (_,i2props_vals) << getprops2.i2props_vals;
149 i1props << tocheck.i1props;
150 i2props << tocheck.i2props;
151 p1 << getprops1.p1;
152 p2 << getprops2.p2;
153 @@
154 
155 if i1props < i2props &&
156    List.sort compare i1props_vals = List.sort compare i2props_vals
157 then
158   let msg =
159     Printf.sprintf
160       "WARNING %s and %s (line %d) are identical\n"
161       i1props i2props (List.hd p2).line in
162   print_report p1 msg

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php