Debian Codegraph @

demos/demo_rule9/rule9.cocci

raw
1 // the order of rules in standard.iso is important to makes this SP works.
2
3 @ rule1 @
4 typedef Scsi_Host_Template;
5 {struct SHT, Scsi_Host_Template} fops;
6 identifier proc_info_func;
7 @@
8 fops.proc_info = proc_info_func;
9
10 @ rule2 @
11 identifier rule1.proc_info_func;
12 identifier buffer, start, offset, length, inout, hostno;
13 identifier hostptr;
14 typedef off_t;
15 @@
16 proc_info_func (
17 + struct Scsi_Host *hostptr,
18 char *buffer, char **start, off_t offset, int length,
19 - int hostno,
20 int inout) {
21 ...
22 - struct Scsi_Host *hostptr;
23 ...
24 - hostptr = scsi_host_hn_get(hostno);
25 ...
26 ?- if (!hostptr) { ... return ...; }
27 ...
28 ?- scsi_host_put(hostptr);
29 ...
30 }
31
32 @ rule3 @
33 identifier rule1.proc_info_func;
34 identifier rule2.hostno;
35 identifier rule2.hostptr;
36 @@
37 proc_info_func(...) {
38 <...
39 - hostno
40 + hostptr->host_no
41 ...>
42 }
43
44 @ rule4 @
45 identifier rule1.proc_info_func;
46 identifier func;
47 expression buffer, start, offset, length, inout, hostno;
48 identifier hostptr;
49 @@
50
51 func(..., struct Scsi_Host *hostptr, ...) {
52 <...
53 proc_info_func(
54 + hostptr,
55 buffer, start, offset, length,
56 - hostno,
57 inout)
58 ...>
59 }