Release coccinelle-0.1
[bpt/coccinelle.git] / demos / janitorings / netdev_priv.cocci
CommitLineData
34e49164
C
1// TODO: now that have the assign/affect iso, can perhaps
2// deal with the cast pb
3// rewriting
4// - (T*) dev->priv
5// + netdev_priv(dev)
6// into
7// x =
8// - (T*) dev-> priv
9// + netdev_priv(dev)
10
11// and then make another rule for the remaining case
12
13
14@ alloc disable plus_comm @
15type T;
16expression E;
17@@
18
19(
20(
21 alloc_netdev
22|
23 alloc_etherdev
24|
25 alloc_fcdev
26|
27 alloc_fddidev
28|
29 alloc_hippi_dev
30|
31 alloc_trdev
32|
33 alloc_ltalkdev
34|
35 alloc_irdadev
36|
37 alloc_etherdev_mq
38)
39 (sizeof(T), ...)
40|
41(
42 alloc_netdev
43|
44 alloc_etherdev
45|
46 alloc_fcdev
47|
48 alloc_fddidev
49|
50 alloc_hippi_dev
51|
52 alloc_trdev
53|
54 alloc_ltalkdev
55|
56 alloc_irdadev
57|
58 alloc_etherdev_mq
59)
60 (sizeof(T) + E, ...)
61)
62
63
64// if don't have the iso sizeof(T) => sizeof(E)
65// dev = alloc_netdev(sizeof(*x), ...)
66
67//>>> - alloc_irlandev
68// but dont pass the sizeof, so cant get the type T.
69
70//> alloc_orinocodev
71
72
73@ danger @
74struct net_device *dev;
75expression E;
76@@
77 dev->priv = E
78//+ DANGER
79
80
81//@ danger @
82//struct net_device dev;
83//expression E;
84//@@
85// dev.priv = E
86
87
88
89// TODO wrong !!! can have ((T) a)->field, on peut pas remover le cast!
90@ rule1 depends on alloc && !danger @
91struct net_device *dev;
92type alloc.T;
93@@
94
95- (T*) dev->priv
96+ netdev_priv(dev)
97
98
99// the iso drop_cast is not enough because T* in the previous rule
100// can not be dropped. It's not a pure T.
101@ rule2 depends on alloc && !danger @
102struct net_device *dev;
103@@
104
105- dev->priv
106+ netdev_priv(dev)