Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

coccinelle: tests: improve odd_ptr_err.cocci

The original version only considered the case where the then branch
contains only one call to PTR_ERR. Reimplement the whole thing to allow
multiple calls, with potentially different arguments.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>

authored by

Julia Lawall and committed by
Michal Marek
02da7b42 74a8478f

+86 -34
+86 -34
scripts/coccinelle/tests/odd_ptr_err.cocci
··· 1 1 /// PTR_ERR should access the value just tested by IS_ERR 2 - //# There can be false positives in the patch case, where it is the call 2 + //# There can be false positives in the patch case, where it is the call to 3 3 //# IS_ERR that is wrong. 4 4 /// 5 5 // Confidence: High 6 - // Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2. 7 - // Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2. 6 + // Copyright: (C) 2012, 2015 Julia Lawall, INRIA. GPLv2. 7 + // Copyright: (C) 2012, 2015 Gilles Muller, INRIA. GPLv2. 8 8 // URL: http://coccinelle.lip6.fr/ 9 - // Comments: 10 9 // Options: --no-includes --include-headers 11 10 12 11 virtual patch ··· 13 14 virtual org 14 15 virtual report 15 16 16 - @depends on patch@ 17 - expression e,e1; 17 + @ok1 exists@ 18 + expression x,e; 19 + position p; 18 20 @@ 19 21 22 + if (IS_ERR(x=e) || ...) { 23 + <... 24 + PTR_ERR@p(x) 25 + ...> 26 + } 27 + 28 + @ok2 exists@ 29 + expression x,e1,e2; 30 + position p; 31 + @@ 32 + 33 + if (IS_ERR(x) || ...) { 34 + <... 20 35 ( 21 - if (IS_ERR(e)) { ... PTR_ERR(e) ... } 36 + PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\)) 22 37 | 23 - if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } 38 + PTR_ERR@p(x) 39 + ) 40 + ...> 41 + } 42 + 43 + @r1 depends on patch && !context && !org && !report exists@ 44 + expression x,y; 45 + position p != {ok1.p,ok2.p}; 46 + @@ 47 + 48 + if (IS_ERR(x) || ...) { 49 + ... when any 50 + when != IS_ERR(...) 51 + ( 52 + PTR_ERR(x) 24 53 | 25 - if (IS_ERR(e)) 26 - { ... 27 - PTR_ERR( 28 - - e1 29 - + e 54 + PTR_ERR@p( 55 + - y 56 + + x 30 57 ) 31 - ... } 32 58 ) 59 + ... when any 60 + } 33 61 34 - @r depends on !patch@ 35 - expression e,e1; 36 - position p1,p2; 62 + // ---------------------------------------------------------------------------- 63 + 64 + @r1_context depends on !patch && (context || org || report) exists@ 65 + position p != {ok1.p,ok2.p}; 66 + expression x, y; 67 + position j0, j1; 37 68 @@ 38 69 70 + if (IS_ERR@j0(x) || ...) { 71 + ... when any 72 + when != IS_ERR(...) 39 73 ( 40 - if (IS_ERR(e)) { ... PTR_ERR(e) ... } 74 + PTR_ERR(x) 41 75 | 42 - if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } 43 - | 44 - *if (IS_ERR@p1(e)) 45 - { ... 46 - * PTR_ERR@p2(e1) 47 - ... } 76 + PTR_ERR@j1@p( 77 + y 78 + ) 48 79 ) 80 + ... when any 81 + } 49 82 50 - @script:python depends on org@ 51 - p1 << r.p1; 52 - p2 << r.p2; 83 + @r1_disj depends on !patch && (context || org || report) exists@ 84 + position p != {ok1.p,ok2.p}; 85 + expression x, y; 86 + position r1_context.j0, r1_context.j1; 53 87 @@ 54 88 55 - cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1) 56 - cocci.print_secs("PTR_ERR",p2) 89 + * if (IS_ERR@j0(x) || ...) { 90 + ... when any 91 + when != IS_ERR(...) 92 + * PTR_ERR@j1@p( 93 + y 94 + ) 95 + ... when any 96 + } 57 97 58 - @script:python depends on report@ 59 - p1 << r.p1; 60 - p2 << r.p2; 98 + // ---------------------------------------------------------------------------- 99 + 100 + @script:python r1_org depends on org@ 101 + j0 << r1_context.j0; 102 + j1 << r1_context.j1; 61 103 @@ 62 104 63 - msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line) 64 - coccilib.report.print_report(p1[0],msg) 105 + msg = "inconsistent IS_ERR and PTR_ERR" 106 + coccilib.org.print_todo(j0[0], msg) 107 + coccilib.org.print_link(j1[0], "") 108 + 109 + // ---------------------------------------------------------------------------- 110 + 111 + @script:python r1_report depends on report@ 112 + j0 << r1_context.j0; 113 + j1 << r1_context.j1; 114 + @@ 115 + 116 + msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line) 117 + coccilib.report.print_report(j0[0], msg) 118 +