diff options
| -rw-r--r-- | scripts/coccinelle/resource_size.cocci | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/scripts/coccinelle/resource_size.cocci b/scripts/coccinelle/resource_size.cocci new file mode 100644 index 000000000000..1935a58b39d9 --- /dev/null +++ b/scripts/coccinelle/resource_size.cocci | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | /// | ||
| 2 | /// Use resource_size function on resource object | ||
| 3 | /// instead of explicit computation. | ||
| 4 | /// | ||
| 5 | // Confidence: High | ||
| 6 | // Copyright: (C) 2009, 2010 Nicolas Palix, DIKU. GPLv2. | ||
| 7 | // Copyright: (C) 2009, 2010 Julia Lawall, DIKU. GPLv2. | ||
| 8 | // Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6. GPLv2. | ||
| 9 | // URL: http://coccinelle.lip6.fr/ | ||
| 10 | // Options: | ||
| 11 | // | ||
| 12 | // Keywords: resource_size | ||
| 13 | // Version min: 2.6.27 resource_size | ||
| 14 | // | ||
| 15 | |||
| 16 | virtual context | ||
| 17 | virtual patch | ||
| 18 | virtual org | ||
| 19 | virtual report | ||
| 20 | |||
| 21 | //---------------------------------------------------------- | ||
| 22 | // For context mode | ||
| 23 | //---------------------------------------------------------- | ||
| 24 | |||
| 25 | @r_context depends on context && !patch && !org@ | ||
| 26 | struct resource *res; | ||
| 27 | @@ | ||
| 28 | |||
| 29 | * (res->end - res->start) + 1 | ||
| 30 | |||
| 31 | //---------------------------------------------------------- | ||
| 32 | // For patch mode | ||
| 33 | //---------------------------------------------------------- | ||
| 34 | |||
| 35 | @r_patch depends on !context && patch && !org@ | ||
| 36 | struct resource *res; | ||
| 37 | @@ | ||
| 38 | |||
| 39 | - (res->end - res->start) + 1 | ||
| 40 | + resource_size(res) | ||
| 41 | |||
| 42 | //---------------------------------------------------------- | ||
| 43 | // For org mode | ||
| 44 | //---------------------------------------------------------- | ||
| 45 | |||
| 46 | |||
| 47 | @r_org depends on !context && !patch && (org || report)@ | ||
| 48 | struct resource *res; | ||
| 49 | position p; | ||
| 50 | @@ | ||
| 51 | |||
| 52 | (res->end@p - res->start) + 1 | ||
| 53 | |||
| 54 | @rbad_org depends on !context && !patch && (org || report)@ | ||
| 55 | struct resource *res; | ||
| 56 | position p != r_org.p; | ||
| 57 | @@ | ||
| 58 | |||
| 59 | res->end@p - res->start | ||
| 60 | |||
| 61 | @script:python depends on org@ | ||
| 62 | p << r_org.p; | ||
| 63 | x << r_org.res; | ||
| 64 | @@ | ||
| 65 | |||
| 66 | msg="ERROR with %s" % (x) | ||
| 67 | msg_safe=msg.replace("[","@(").replace("]",")") | ||
| 68 | coccilib.org.print_todo(p[0], msg_safe) | ||
| 69 | |||
| 70 | @script:python depends on report@ | ||
| 71 | p << r_org.p; | ||
| 72 | x << r_org.res; | ||
| 73 | @@ | ||
| 74 | |||
| 75 | msg="ERROR: Missing resource_size with %s" % (x) | ||
| 76 | coccilib.report.print_report(p[0], msg) | ||
| 77 | |||
| 78 | @script:python depends on org@ | ||
| 79 | p << rbad_org.p; | ||
| 80 | x << rbad_org.res; | ||
| 81 | @@ | ||
| 82 | |||
| 83 | msg="WARNING with %s" % (x) | ||
| 84 | msg_safe=msg.replace("[","@(").replace("]",")") | ||
| 85 | coccilib.org.print_todo(p[0], msg_safe) | ||
| 86 | |||
| 87 | @script:python depends on report@ | ||
| 88 | p << rbad_org.p; | ||
| 89 | x << rbad_org.res; | ||
| 90 | @@ | ||
| 91 | |||
| 92 | msg="WARNING: Suspicious code. resource_size is maybe missing with %s" % (x) | ||
| 93 | coccilib.report.print_report(p[0], msg) | ||
